From 87c9b2581413b83dfeb9290f1b194ba84f1f42a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20H=C3=BCbenthal?= Date: Sat, 14 Jan 2017 15:43:03 +0100 Subject: [PATCH 01/15] new systemd service file --- sinusbot | 188 ----------------------------------------------- sinusbot.service | 11 +++ 2 files changed, 11 insertions(+), 188 deletions(-) delete mode 100644 sinusbot create mode 100644 sinusbot.service diff --git a/sinusbot b/sinusbot deleted file mode 100644 index fea6a72..0000000 --- a/sinusbot +++ /dev/null @@ -1,188 +0,0 @@ -#! /bin/bash -### BEGIN INIT INFO -# Provides: sinusbot -# Required-Start: $local_fs $network -# Required-Stop: $local_fs $network -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Description: Sinusbot -### END INIT INFO - -################################################################################## -# # -# Usage: {start|stop|status|restart|console|update|backup} # -# - start: start the bot # -# - stop: stop the bot # -# - status: display the status of the bot (down or up) # -# - restart: restart the bot # -# - console: display the bot console # -# - update: runs the bot updater (with start & stop) -# - backup: archives your bot root directory -# To exit the console without stopping the server, press CTRL + A then D. # -# # -################################################################################## - -SCREEN_NAME="sinusbot" -USER="mybotuser" -DIR_ROOT="/opt/ts3soundboard/" -DIR_BACKUP="" -BOT_RUNCMD="./sinusbot" -BOT_UPDATE_ARG=" -update" -SCREEN_IGNORE_TTY="N" # Y = Ignore the tty, you can access the bot screen as root (i not recommend it) root should be disabled :) | N = disabled - -# No edits necessary beyond this line -PATH=/bin:/usr/bin:/sbin:/usr/sbin -if [ ! -x `which screen` ]; then echo "ERROR: You need screen for this script (try apt-get install screen)"; exit 1; fi -if [ ! -x `which tar` ]; then echo "WARNING: You need tar for the Backup Function (try apt-get install tar)"; fi - -function start { - if [ ! -d $DIR_ROOT ]; then echo "ERROR: $DIR_ROOT is not a directory"; exit 1; fi - if status; then echo "$SCREEN_NAME is already running"; exit 1; fi - - # Start bot - if [ `whoami` = root ] - then - su - $USER -c "cd $DIR_ROOT ; screen -AmdS $SCREEN_NAME $BOT_RUNCMD" - else - cd $DIR_ROOT - screen -AmdS $SCREEN_NAME $BOT_RUNCMD - fi -} - -function backup { - - DATE=$(date +%Y-%m-%d) - - if [ `whoami` = root ] - then - su - $USER -c "cd $DIR_ROOT ; tar -cjpf $DIR_BACKUP/sinusbot-$DATE.tar.bz2 $DIR_ROOT" - else - cd $DIR_ROOT - tar -cjpf $DIR_BACKUP/sinusbot-$DATE.tar.bz2 $DIR_ROOT - fi -} -function update { - if [ `whoami` = root ] - then - su - $USER -c "cd $DIR_ROOT ; $BOT_RUNCMD$BOT_UPDATE_ARG" - else - cd $DIR_ROOT - $BOT_RUNCMD$BOT_UPDATE_ARG - fi -} - -function stop { - if ! status; then echo "$SCREEN_NAME could not be found. Probably not running."; exit 1; fi - - if [ `whoami` = root ] - then - su - $USER -c "screen -S $SCREEN_NAME -X stuff '\003'" - else - screen -S $SCREEN_NAME -X stuff '\003' - fi -} - -function status { - if [ `whoami` = root ] - then - su - $USER -c "screen -ls" | grep [.]$SCREEN_NAME[[:space:]] > /dev/null - else - screen -ls | grep [.]$SCREEN_NAME[[:space:]] > /dev/null - fi -} - -function console { - if ! status; then echo "$SCREEN_NAME could not be found. Probably not running."; exit 1; fi - - if [ `whoami` = root ] - then - - if [ $SCREEN_IGNORE_TTY == 'Y' ] - then - su - $USER -c "script -q -c 'screen -x $SCREEN_NAME' /dev/null" - else - su - $USER -c "screen -x $SCREEN_NAME" - fi - else - screen -x $SCREEN_NAME - fi -} - -function usage { - echo "Usage: $0 {start|stop|status|restart|console}" - echo "On console, press CTRL+A then D to stop the screen without stopping the server." -} - -case "$1" in - -start) - echo "Using following data:" - echo "USER: $USER" - echo "DIR ROOT: $DIR_ROOT" - echo "BOT RUN CMD: $BOT_RUNCMD" - echo "" - sleep 2 - echo "Starting $SCREEN_NAME..." - start - sleep 2 - echo "$SCREEN_NAME started successfully" -;; - -stop) - echo "Stopping $SCREEN_NAME..." - stop - sleep 2 - echo "$SCREEN_NAME stopped successfully" -;; - -restart) - echo "Restarting $SCREEN_NAME..." - status && stop - sleep 5 - start - sleep 2 - echo "$SCREEN_NAME restarted successfully" -;; - -status) - if status - then echo "$SCREEN_NAME is UP" - else echo "$SCREEN_NAME is DOWN" - fi -;; - -console) - echo "Open console on $SCREEN_NAME..." - console -;; - -update) - if status - then stop && sleep 5 && update - else update - fi - -;; - -backup) - - if [ -d "$DIR_BACKUP" ] - then - if status - then stop && sleep 5 && backup - else backup - fi - else echo "BACKUP DIRECTORY NOT EXISTS. EXIT!"; exit 1; - fi - -;; - -*) - usage - exit 1 -;; - -esac - -exit 0 - diff --git a/sinusbot.service b/sinusbot.service new file mode 100644 index 0000000..2f8fb57 --- /dev/null +++ b/sinusbot.service @@ -0,0 +1,11 @@ +[Unit] +Description = Sinusbot the Teamspeak 3 and Discord MusicBot. +After = syslog.target network.target + +[Service] +User=YOURUSER +ExecStart=YOURPATH_TO_THE_BOT_BINARY +Type=simple + +[Install] +WantedBy=multi-user.target \ No newline at end of file From 3e1e5ab2c2119e7287f92c497e83e7dafbfd12b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20H=C3=BCbenthal?= Date: Sat, 21 Jan 2017 15:56:49 +0100 Subject: [PATCH 02/15] Fixed unclean process termination: Kill with Signal 2 (SIG_INTERRUPT). - Use SIG_KILL after timeout. --- sinusbot.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sinusbot.service b/sinusbot.service index 2f8fb57..415767c 100644 --- a/sinusbot.service +++ b/sinusbot.service @@ -6,6 +6,8 @@ After = syslog.target network.target User=YOURUSER ExecStart=YOURPATH_TO_THE_BOT_BINARY Type=simple +KillSignal=2 +SendSIGKILL=yes [Install] WantedBy=multi-user.target \ No newline at end of file From 946b6926a4e2fc90ca52dd73896cc425cc6e91f8 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 1 Mar 2017 14:00:14 +0100 Subject: [PATCH 03/15] Fixed working directory Fixed working directory of the script because without the bot will run in `/`. --- sinusbot.service | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sinusbot.service b/sinusbot.service index 415767c..0714a70 100644 --- a/sinusbot.service +++ b/sinusbot.service @@ -1,13 +1,14 @@ [Unit] -Description = Sinusbot the Teamspeak 3 and Discord MusicBot. -After = syslog.target network.target +Description=Sinusbot the Teamspeak 3 and Discord MusicBot. +After=syslog.target network.target [Service] User=YOURUSER ExecStart=YOURPATH_TO_THE_BOT_BINARY +WorkingDirectory=YOURPATH_TO_THE_BOT_DIRECTORY Type=simple KillSignal=2 SendSIGKILL=yes [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target From 6fec650f48e69e67937d526d12d3d98a6b19fdf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20H=C3=BCbenthal?= Date: Sat, 1 Apr 2017 18:20:05 +0200 Subject: [PATCH 04/15] fix bot side lock behavior Removed lock files in pre start and post stop actions. --- sinusbot.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sinusbot.service b/sinusbot.service index 0714a70..b7c0d64 100644 --- a/sinusbot.service +++ b/sinusbot.service @@ -4,6 +4,8 @@ After=syslog.target network.target [Service] User=YOURUSER +ExecStartPre=rm /tmp/.sinusbot.lock +ExecStopPost=rm /tmp/.sinusbot.lock ExecStart=YOURPATH_TO_THE_BOT_BINARY WorkingDirectory=YOURPATH_TO_THE_BOT_DIRECTORY Type=simple From dd3b0e909b56c8f7e8ffb2eee93b1a6945fcd3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20H=C3=BCbenthal?= Date: Sat, 1 Apr 2017 18:25:59 +0200 Subject: [PATCH 05/15] skip errors in rm Lock files may not exists, so show no error please! --- sinusbot.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sinusbot.service b/sinusbot.service index b7c0d64..fd919ec 100644 --- a/sinusbot.service +++ b/sinusbot.service @@ -4,8 +4,8 @@ After=syslog.target network.target [Service] User=YOURUSER -ExecStartPre=rm /tmp/.sinusbot.lock -ExecStopPost=rm /tmp/.sinusbot.lock +ExecStartPre=rm -f /tmp/.sinusbot.lock +ExecStopPost=rm -f /tmp/.sinusbot.lock ExecStart=YOURPATH_TO_THE_BOT_BINARY WorkingDirectory=YOURPATH_TO_THE_BOT_DIRECTORY Type=simple From 3a356bf34934cdad5543c77a4093dbc4eb230f20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20H=C3=BCbenthal?= Date: Sun, 16 Apr 2017 20:34:16 +0200 Subject: [PATCH 06/15] fix systemd paths Systemd requires relativ paths. Until now pre/post actions had no action at all. --- sinusbot.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sinusbot.service b/sinusbot.service index fd919ec..1b98a24 100644 --- a/sinusbot.service +++ b/sinusbot.service @@ -4,8 +4,8 @@ After=syslog.target network.target [Service] User=YOURUSER -ExecStartPre=rm -f /tmp/.sinusbot.lock -ExecStopPost=rm -f /tmp/.sinusbot.lock +ExecStartPre=/bin/rm -f /tmp/.sinusbot.lock +ExecStopPost=/bin/rm -f /tmp/.sinusbot.lock ExecStart=YOURPATH_TO_THE_BOT_BINARY WorkingDirectory=YOURPATH_TO_THE_BOT_DIRECTORY Type=simple From 7e0eaca65991130f216b1aa7a47ec7391f68fccb Mon Sep 17 00:00:00 2001 From: irgendwer / Jonas Date: Mon, 24 Apr 2017 18:58:20 +0200 Subject: [PATCH 07/15] Update sinusbot.service --- sinusbot.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sinusbot.service b/sinusbot.service index 1b98a24..ba3b41d 100644 --- a/sinusbot.service +++ b/sinusbot.service @@ -1,9 +1,9 @@ [Unit] -Description=Sinusbot the Teamspeak 3 and Discord MusicBot. +Description=Sinusbot, the Teamspeak 3 and Discord music bot. After=syslog.target network.target [Service] -User=YOURUSER +User=YOUR_USER ExecStartPre=/bin/rm -f /tmp/.sinusbot.lock ExecStopPost=/bin/rm -f /tmp/.sinusbot.lock ExecStart=YOURPATH_TO_THE_BOT_BINARY From 6cb5a21101ef41622289bcdc0b2f8e73507299de Mon Sep 17 00:00:00 2001 From: irgendwer / Jonas Date: Mon, 24 Apr 2017 19:15:29 +0200 Subject: [PATCH 08/15] added readme --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..853e494 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Sinusbot startscript +## installation +1. copy the file `sinusbot.service` to `/etc/systemd/system/sinusbot.service` + +2. Adjust the following placeholders to your installation: + + placeholder | description | example + -----------------------------|---------------------------------------------|------------------------ + YOUR_USER | Your user who starts the bot | sinusbot + YOUR_PATH_TO_THE_BOT\_BINARY | Your path to the SinusBot binary | /opt/sinusbot/sinusbot + YOU_PATH_TO_THE_BOT | Your path to the SinusBot install directory | /opt/sinusbot + +3. Reload systemd: `systemctl daemon-reload` + +4. Start the sinusbot: `service sinusbot start` From 4357daca5a117d78edd4b1fc52ee3ee4d6bbb56f Mon Sep 17 00:00:00 2001 From: irgendwer / Jonas Date: Fri, 28 Apr 2017 18:43:27 +0200 Subject: [PATCH 09/15] corrected path --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 853e494..a5b37ba 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Sinusbot startscript ## installation -1. copy the file `sinusbot.service` to `/etc/systemd/system/sinusbot.service` +1. copy the file `sinusbot.service` to `/lib/systemd/system/sinusbot.service` 2. Adjust the following placeholders to your installation: From c404790939589aaa60491f60b74c49c8d89ac27a Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Tue, 6 Jun 2017 13:55:10 +0200 Subject: [PATCH 10/15] Minor README.md changes - fixed placeholders - adjusted SinusBot naming convention - improved style --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a5b37ba..a7cc759 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ -# Sinusbot startscript -## installation -1. copy the file `sinusbot.service` to `/lib/systemd/system/sinusbot.service` +# SinusBot startscript +## Installation + +1. Copy the file `sinusbot.service` to `/lib/systemd/system/sinusbot.service` 2. Adjust the following placeholders to your installation: - placeholder | description | example - -----------------------------|---------------------------------------------|------------------------ - YOUR_USER | Your user who starts the bot | sinusbot - YOUR_PATH_TO_THE_BOT\_BINARY | Your path to the SinusBot binary | /opt/sinusbot/sinusbot - YOU_PATH_TO_THE_BOT | Your path to the SinusBot install directory | /opt/sinusbot + placeholder | description | example + ------------------------------|---------------------------------------------|------------------------ + YOUR_USER | Your user who starts the bot | sinusbot + YOURPATH_TO_THE_BOT\_BINARY | Your path to the SinusBot binary | /opt/sinusbot/sinusbot + YOURPATH_TO_THE_BOT_DIRECTORY | Your path to the SinusBot install directory | /opt/sinusbot 3. Reload systemd: `systemctl daemon-reload` - 4. Start the sinusbot: `service sinusbot start` From 7c29cb60e50d5ac72cb7f9a1437e860a3c43ce45 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 27 Dec 2017 20:35:46 +0100 Subject: [PATCH 11/15] Added autostart via systemctl --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a7cc759..5f4b583 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,9 @@ placeholder | description | example ------------------------------|---------------------------------------------|------------------------ YOUR_USER | Your user who starts the bot | sinusbot - YOURPATH_TO_THE_BOT\_BINARY | Your path to the SinusBot binary | /opt/sinusbot/sinusbot + YOURPATH_TO_THE_BOT\_BINARY | Your path to the SinusBot binary | /opt/sinusbot/sinusbot YOURPATH_TO_THE_BOT_DIRECTORY | Your path to the SinusBot install directory | /opt/sinusbot 3. Reload systemd: `systemctl daemon-reload` +4. Enable autostart (optional) `systemctl enable sinusbot` 4. Start the sinusbot: `service sinusbot start` From cd09a70032e7811ac3622fbdd21dc2d0e1d4e6c3 Mon Sep 17 00:00:00 2001 From: Haxe18 Date: Sat, 20 Jan 2018 00:56:07 +0100 Subject: [PATCH 12/15] Stop "hacking" and deleting files in TS3dir ... --- sinusbot.service | 1 + 1 file changed, 1 insertion(+) diff --git a/sinusbot.service b/sinusbot.service index ba3b41d..0be6c59 100644 --- a/sinusbot.service +++ b/sinusbot.service @@ -11,6 +11,7 @@ WorkingDirectory=YOURPATH_TO_THE_BOT_DIRECTORY Type=simple KillSignal=2 SendSIGKILL=yes +Environment=QT_XCB_GL_INTEGRATION=none [Install] WantedBy=multi-user.target From 8c78c6f29cebb38663cadc96233b407161a0a538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20B=C3=B6gle?= Date: Wed, 4 Jul 2018 19:09:41 +0200 Subject: [PATCH 13/15] ensure network connectivity --- sinusbot.service | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sinusbot.service b/sinusbot.service index 0be6c59..076f3f4 100644 --- a/sinusbot.service +++ b/sinusbot.service @@ -1,6 +1,7 @@ [Unit] Description=Sinusbot, the Teamspeak 3 and Discord music bot. -After=syslog.target network.target +Wants=network-online.target +After=syslog.target network.target network-online.target [Service] User=YOUR_USER From 54bf6b38f7a5fc09b5e8c4a502061c17c1e65dbd Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 1 Oct 2018 18:35:12 +0200 Subject: [PATCH 14/15] Added ulimit config --- sinusbot.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sinusbot.service b/sinusbot.service index 076f3f4..1417fd6 100644 --- a/sinusbot.service +++ b/sinusbot.service @@ -13,6 +13,8 @@ Type=simple KillSignal=2 SendSIGKILL=yes Environment=QT_XCB_GL_INTEGRATION=none +LimitNOFILE=512000 +LimitNPROC=512000 [Install] WantedBy=multi-user.target From 72a0b9c78adf237ea9bdd12a951ab164b4206bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20B=C3=B6gle?= Date: Tue, 10 Dec 2019 19:32:04 +0100 Subject: [PATCH 15/15] use systemctl instead of service --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f4b583..55e300d 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,4 @@ 3. Reload systemd: `systemctl daemon-reload` 4. Enable autostart (optional) `systemctl enable sinusbot` -4. Start the sinusbot: `service sinusbot start` +4. Start the sinusbot: `systemctl start sinusbot`