Browse Source

add binary starter and systemd user units

systemd: add puppeteer launcher and service unit
Mike L 4 years ago
parent
commit
47bba5ba89
6 changed files with 77 additions and 0 deletions
  1. 18 0
      README.md
  2. 17 0
      bin/chromium
  3. 2 0
      bin/twitterbot
  4. 14 0
      systemd/user/mirai.service
  5. 11 0
      systemd/user/puppeteer.service
  6. 15 0
      systemd/user/twitterbot.service

+ 18 - 0
README.md

@@ -38,6 +38,24 @@
 
 示例文件在 [`config.example.json`](./config.example.json)
 
+## 系统服务
+
+可以使用 [`systemd`](./systemd) 目录里的服务文件设置成自动启动服务
+```
+$ cd
+$ git clone https://github.com/CL-Jeremy/mirai-twitter-bot
+$ cd mirai-twitter-bot
+$ npm i
+$ wget -S http://t.imlxy.net:64724/mirai/MiraiOK/miraiOK_linux_amd64
+$ chmod +x miraiOK_linux_amd64
+$ wget -qO- https://api.github.com/repos/project-mirai/mirai-api-http/releases/latest | grep "browser" | cut -d'"' -f4 | wget -Sqi- -Pplugins
+$ rsync -a systemd ~/.config/
+$ systemctl --user daemon-reload
+$ systemctl --user enable twitterbot.service
+$ loginctl enable-linger
+```
+注:如果想在本地文件夹保存日志,请取消注释两个服务定义中相应的行,阅读时可以使用 `tail -f`
+
 ## Bug
 
 - 好友消息的图片有可能会失效或直接无法接收(后者会被转换为 `[失败的图片:<地址>]` 格式,然后整条消息会以纯文本模式重发)

+ 17 - 0
bin/chromium

@@ -0,0 +1,17 @@
+#!/bin/bash
+cd "$( dirname "${BASH_SOURCE[0]}" )"
+node -e "\
+    const p = require('puppeteer');\
+    p.connect({browserURL: 'http://127.0.0.1:9222'})
+    .catch(() => p.launch({\
+        args: [\
+            '--remote-debugging-port=9222',\
+            '--no-sandbox',\
+            '--disable-setuid-sandbox',\
+            '--disable-dev-shm-usage',\
+            '--disable-accelerated-2d-canvas',\
+            '--no-first-run',\
+            '--no-zygote',\
+            '--single-process',\
+        ...process.argv.slice(1)],\
+    }))" -- "$@"

+ 2 - 0
bin/twitterbot

@@ -0,0 +1,2 @@
+#!/bin/bash
+node "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../dist/main.js" $@

+ 14 - 0
systemd/user/mirai.service

@@ -0,0 +1,14 @@
+[Unit]
+Description=Mirai QQ bot kickstarter
+
+[Service]
+WorkingDirectory=%h/mirai-twitter-bot
+ExecStart=%h/mirai-twitter-bot/miraiOK_linux_amd64
+ExecStartPost=/bin/sleep 15
+#StandardOutput=append:%h/mirai-twitter-bot/miraiOK.log
+#StandardError=append:%h/mirai-twitter-bot/miraiOK.log
+Restart=always
+RestartSec=2s
+
+[Install]
+WantedBy=multi-user.target

+ 11 - 0
systemd/user/puppeteer.service

@@ -0,0 +1,11 @@
+[Unit]
+Description=Mirai QQ Puppeteer on-demand launcher
+
+[Service]
+WorkingDirectory=%h/mirai-twitter-bot
+ExecStart=%h/mirai-twitter-bot/bin/chromium
+Restart=always
+RestartSec=2s
+
+[Install]
+WantedBy=multi-user.target

+ 15 - 0
systemd/user/twitterbot.service

@@ -0,0 +1,15 @@
+[Unit]
+Description=Mirai Twitter bot
+Requires=mirai.service
+Requires=puppeteer.service
+
+[Service]
+WorkingDirectory=%h/mirai-twitter-bot
+ExecStart=%h/mirai-twitter-bot/bin/twitterbot config.json
+#StandardOutput=append:%h/mirai-twitter-bot/twitterbot.log
+#StandardError=append:%h/mirai-twitter-bot/twitterbot.log
+Restart=always
+RestartSec=2s
+
+[Install]
+WantedBy=default.target