From bf3c6595ac1705c39db9c3102c9cb997c8c388ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20S=C3=B6derberg?= Date: Thu, 19 Mar 2026 23:20:13 +0100 Subject: [PATCH] Added a system service --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ weather-station@.service | 21 +++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 weather-station@.service diff --git a/README.md b/README.md index 2b086ce..aff9b27 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,41 @@ # Weather Station Code for the indoor Weather Station + +## Step 1: Install and Pass the "Variable" + +Move the template file to the system folder and reload the daemon: + +* `sudo cp weather-station@.service /etc/systemd/system/` +* `sudo systemctl daemon-reload` + +--- + +## Step 2: Enable and Start + +Now, when you enable and start the service, you **append your actual username** right after the `@` symbol. + +If your username was `pi-user`: + +* **Enable it to start on boot:** + + `sudo systemctl enable weather-station@pi-user.service` +* **Start the script right now:** + + `sudo systemctl start weather-station@pi-user.service` + +--- + +## Step 3: How to check on it + +* **To see if it's running:** + + `sudo systemctl status weather-station@pi-user.service` +* **To read the live console output (like seeing the print statements):** + + `sudo journalctl -u weather-station@pi-user.service -f` + *(Press `Ctrl+C` to exit the log view)* + +* **To manually restart it (if you update your code):** + + `sudo systemctl restart weather-station@pi-user.service` diff --git a/weather-station@.service b/weather-station@.service new file mode 100644 index 0000000..a5da704 --- /dev/null +++ b/weather-station@.service @@ -0,0 +1,21 @@ +# weather-station@.service + +[Unit] +Description=E-Ink Weather Station Daemon +After=network-online.target +Wants=network-online.target + +[Service] +User=%i +Group=%i + +WorkingDirectory=/home/%i/weather-station +ExecStart=/home/%i/weather-station/.venv/bin/python /home/%i/weather-station/main.py + +# Auto-restart logic +Restart=always +RestartSec=10 +Environment=PYTHONUNBUFFERED=1 + +[Install] +WantedBy=multi-user.target \ No newline at end of file