Skip to content

Instantly share code, notes, and snippets.

@monsterxcn
Last active October 6, 2021 01:36
Show Gist options
  • Save monsterxcn/ee6ae03ac54e341602a6de102bb894ae to your computer and use it in GitHub Desktop.
Save monsterxcn/ee6ae03ac54e341602a6de102bb894ae to your computer and use it in GitHub Desktop.
Systemctl 守护 Nonebot2 QQ 机器人

准备

mkdir /data/bot
cd /data/bot
git clone http://github.com/monsterxcn/Genshin_QBot.git .
mkdir go-cqhttp
cd go-cqhttp
wget https://github.com/Mrs4s/go-cqhttp/releases/download/v1.0.0-beta7-fix2/go-cqhttp_linux_amd64.tar.gz
tar xvzf go-cqhttp_linux_amd64.tar.gz

 

配置

cd /data/bot

# 配置 Nonebot2
cp .env.example .env
nano .env

# 配置 go-cqhttp
nano go-cqhttp/config.yml

# 安装虚拟环境
python3 -m venv venv
source venv/bin/activate
pip install nb-cli
pip install nonebot-adapter-cqhttp
pip install nonebot-plugin-apscheduler
pip install Pillow
pip install playwright
playwright install
playwright install-deps
deactivate

 

守护

nano /etc/systemd/system/gocq.service
nano /etc/systemd/system/qqbot.service

systemctl start qqbot
systemctl status qqbot
systemctl stop qqbot

# 测试无误后添加开机启动任务
systemctl enable --now qqbot
[Unit]
Description=go-cqhttp 310xxxx665
Documentation=https://docs.go-cqhttp.org
After=network-online.target
[Service]
Type=simple
ExecStart=/data/bot/go-cqhttp/go-cqhttp -w /data/bot/go-cqhttp
Restart=on-abort
User=root
[Install]
WantedBy=default.target
[Unit]
Description=QBot 310xxxx665
Documentation=http://github.com/monsterxcn/Genshin_QBot
After=network-online.target
Requires=gocq.service
[Service]
Type=simple
WorkingDirectory=/data/bot
Environment=PATH=/data/bot/venv/bin
ExecStart=/bin/bash -c 'cd /data/bot && source venv/bin/activate && nb run'
ExecStopPost=/bin/bash -c 'deactivate'
Restart=on-abort
User=root
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment