From 60c2b4048320104788d1bf07efa269be4359313f Mon Sep 17 00:00:00 2001 From: Philipp Kolmann Date: Sat, 14 Jan 2023 09:05:30 +0100 Subject: [PATCH 1/2] Add systemd user service --- README.md | 1 + docs/systemd-user-service.md | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 docs/systemd-user-service.md diff --git a/README.md b/README.md index 34607fa..d5effbc 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ * [Environment Variables](docs/environment-variables.md) * [Development](docs/development.md) * [Ngrok Support](docs/ngrok.md) +* [systemd user service](docs/systemd-user-service.md) ## Installation and Usage diff --git a/docs/systemd-user-service.md b/docs/systemd-user-service.md new file mode 100644 index 0000000..61dfda9 --- /dev/null +++ b/docs/systemd-user-service.md @@ -0,0 +1,52 @@ +# Add a systemd user service to automatically run twitch-stream-monitor + +After installing twitch-stream-monitor you might want to have the service start automatically. You can use a systemd unit, that runs in the user context. + +## Create necessary directory +In the user context of the user running twitch-stream-monitor create the following directory: +```sh +mkdir -p ~/.config/systemd/user/ +``` + +## Add service unit +edit with your preferred editor the following file: +$EDITOR ~/.config/systemd/user/twitch-stream-monitor.service + +Add the following content (adapt the paths to your setup (WorkingDirectory, ExecStart)): +``` +[Unit] +Description=twitch-stream-monitor +Documentation=https://github.com/ZipFile/twitch-stream-monitor +After=network-online.target +Wants=network-online.target + +[Service] +WorkingDirectory=/home/streamsaver/twitch +ExecStart=/home/streamsaver/go/bin/twitch-stream-monitor monitor +Restart=on-failure +RestartSec=3 +RestartPreventExitStatus=3 + +[Install] +WantedBy=default.target +``` + +## Enable and start service +After saving the file, you need to reload the system daemon, enable and start the service: +```sh +systemctl --user daemon-reload +systemctl --user enable twitch-stream-monitor.service +systemctl --user start twitch-stream-monitor.service +``` + +## query service status +To check if the service is running, you can query systemd: +```sh +systemctl --user status twitch-stream-monitor.service +``` + +To show all logfiles from your service, you can use: +```sh +journalctl --user-unit twitch-stream-monitor.service +``` + From db35044450144e8836128e12c735a36c5cd8ab26 Mon Sep 17 00:00:00 2001 From: Philipp Kolmann Date: Sat, 14 Jan 2023 12:38:22 +0100 Subject: [PATCH 2/2] Add doc about enable-linger --- docs/systemd-user-service.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/systemd-user-service.md b/docs/systemd-user-service.md index 61dfda9..0829214 100644 --- a/docs/systemd-user-service.md +++ b/docs/systemd-user-service.md @@ -2,6 +2,13 @@ After installing twitch-stream-monitor you might want to have the service start automatically. You can use a systemd unit, that runs in the user context. +## Allow user services to run without user logged in +According to https://wiki.archlinux.org/title/Systemd/User#Automatic_start-up_of_systemd_user_instances you need to enable the possibility to have user services running, even when the user is not logged in: + +```sh +sudo loginctl enable-linger _username_ +``` + ## Create necessary directory In the user context of the user running twitch-stream-monitor create the following directory: ```sh