From 2110ef793b3b4e2e2659a15f0a3c0a2b8379ee68 Mon Sep 17 00:00:00 2001 From: mloe Date: Sat, 22 Oct 2022 15:54:45 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=E2=80=9EREADME.md=E2=80=9C=20hinzuf=C3=BCg?= =?UTF-8?q?en?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..0182144 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# Sample Discord Bot with self update + +## Prerequisites + +- Python 3.8 or higher +- Git +- (optional) systemd or equivalent, restarting the bot might be a bit messy otherwise + +## Installation + +- Just clone the repository to wherever you like + +### (optional) Setting up systemd user service + +Systemd only allows system wide services out of the box. Those require root access though. +If you don't wanna run the bot on an account with root access, here's what you can do: + +On an account with root access run: + +``` +loginctl enable-linger +export XDG_RUNTIME_DIR=/run/user/$(id -u) +``` + +Reboot your system. + +Afterwards you have to check two environment variables: +``` +echo $XDB_RUNTIME_DIR // should return something like /run/user/1001 +echo $DBUS_SESSION_BUS_ADDRESS // should return something like /run/user/1001/bus +``` + +Now you can create user services under /home//.config/systemd/user. +The bot service should look something like this: +``` +[Unit] +Description=Test Discord Bot +After=multi-user.target + +[Service] +Type=simple +WorkingDirectory=/home/marco/Projects/DiscordBot +ExecStart=/usr/bin/python3.10 /home/marco/Projects/DiscordBot/bot.py + +[Install] +WantedBy=multi-user.target +``` \ No newline at end of file From fb1aeff33ca6a2b9d84c07d618174fe4fc8a2221 Mon Sep 17 00:00:00 2001 From: mloe Date: Sat, 22 Oct 2022 16:03:56 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=E2=80=9EREADME.md=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0182144..4cacf08 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ loginctl enable-linger export XDG_RUNTIME_DIR=/run/user/$(id -u) ``` -Reboot your system. +Reboot your system and log in to the non-root account. Afterwards you have to check two environment variables: ``` @@ -30,9 +30,11 @@ echo $XDB_RUNTIME_DIR // should return something like /run/user/10 echo $DBUS_SESSION_BUS_ADDRESS // should return something like /run/user/1001/bus ``` -Now you can create user services under /home//.config/systemd/user. +Now you can create user services under /home/\/.config/systemd/user. The bot service should look something like this: ``` +# discord-bot.service + [Unit] Description=Test Discord Bot After=multi-user.target @@ -44,4 +46,14 @@ ExecStart=/usr/bin/python3.10 /home/marco/Projects/DiscordBot/bot.py [Install] WantedBy=multi-user.target +``` + +To control the service you then can do: +``` +systemctl --user [start/stop/restart] +``` + +To have the service start on boot do: +``` +systemctl --user enable ``` \ No newline at end of file From 555b560a298ef9ee1e65771bfa33a5ee0427402b Mon Sep 17 00:00:00 2001 From: mloe Date: Sat, 22 Oct 2022 19:29:50 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=E2=80=9EREADME.md=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 4cacf08..00aedd7 100644 --- a/README.md +++ b/README.md @@ -9,29 +9,7 @@ ## Installation - Just clone the repository to wherever you like - -### (optional) Setting up systemd user service - -Systemd only allows system wide services out of the box. Those require root access though. -If you don't wanna run the bot on an account with root access, here's what you can do: - -On an account with root access run: - -``` -loginctl enable-linger -export XDG_RUNTIME_DIR=/run/user/$(id -u) -``` - -Reboot your system and log in to the non-root account. - -Afterwards you have to check two environment variables: -``` -echo $XDB_RUNTIME_DIR // should return something like /run/user/1001 -echo $DBUS_SESSION_BUS_ADDRESS // should return something like /run/user/1001/bus -``` - -Now you can create user services under /home/\/.config/systemd/user. -The bot service should look something like this: +- If you run systemd, create a service. For example: ``` # discord-bot.service @@ -47,6 +25,34 @@ ExecStart=/usr/bin/python3.10 /home/marco/Projects/DiscordBot/bot.py [Install] WantedBy=multi-user.target ``` +- If you don't run systemd, you have to edit the update script to something like +``` +pkill -f 'bot.py' +git pull origin master +python3 bot.py +``` + +### (optional) Setting up systemd user service + +Systemd only allows system wide services out of the box. Those require root access though. +If you don't wanna run the bot on an account with root access, here's what you can do: + +On an account with root access run: + +``` +loginctl enable-linger // This will enable a user specific service manager +``` +More on that [here](https://www.freedesktop.org/software/systemd/man/loginctl.html#enable-linger%20USER%E2%80%A6). + +Now reboot your system and log in to the non-root account. + +You have to check two environment variables: +``` +echo $XDB_RUNTIME_DIR // should return something like /run/user/1001 +echo $DBUS_SESSION_BUS_ADDRESS // should return something like /run/user/1001/bus +``` + +Now you can create user services under /home/\/.config/systemd/user. To control the service you then can do: ```