From a0e448eaf00884ffb31e596d751971f03987a090 Mon Sep 17 00:00:00 2001 From: Ron Smits Date: Thu, 22 Oct 2020 22:54:58 +0200 Subject: [PATCH 1/2] updated the command sequence and location of the service file --- linux/usage/systemd.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/linux/usage/systemd.md b/linux/usage/systemd.md index 433196572e..bb5e6062af 100644 --- a/linux/usage/systemd.md +++ b/linux/usage/systemd.md @@ -26,12 +26,18 @@ WantedBy=multi-user.target ``` So in this instance, the service would run Python 3 from our working directory `/home/pi/myscript` which contains our python program to run `main.py`. But you are not limited to Python programs: simply change the ExecStart line to be the command to start any program/script that you want running from booting. -Copy this file into `/etc/systemd/system` as root, for example: +Copy this file into `/var/run/systemd/system` as root, for example: ``` -sudo cp myscript.service /etc/systemd/system/myscript.service +sudo cp myscript.service /var/run/systemd/system/myscript.service ``` -Once this has been copied, you can attempt to start the service using the following command: +Once this has been copied, you have to inform `systemd` that a new service has been added. This is done with the following command: + +``` +sudo systemctl daemon-reload +``` + +Now you can attempt to start the service using the following command: ``` sudo systemctl start myscript.service ``` From 7749c99a4a63887ea3dbe5d4dd49a76832b546ff Mon Sep 17 00:00:00 2001 From: Ron Smits Date: Tue, 27 Oct 2020 19:26:15 +0100 Subject: [PATCH 2/2] reverted the information about /var/run --- linux/usage/systemd.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux/usage/systemd.md b/linux/usage/systemd.md index bb5e6062af..343d245dcb 100644 --- a/linux/usage/systemd.md +++ b/linux/usage/systemd.md @@ -26,9 +26,9 @@ WantedBy=multi-user.target ``` So in this instance, the service would run Python 3 from our working directory `/home/pi/myscript` which contains our python program to run `main.py`. But you are not limited to Python programs: simply change the ExecStart line to be the command to start any program/script that you want running from booting. -Copy this file into `/var/run/systemd/system` as root, for example: +Copy this file into `/etc/systemd/system` as root, for example: ``` -sudo cp myscript.service /var/run/systemd/system/myscript.service +sudo cp myscript.service /etc/systemd/system/myscript.service ``` Once this has been copied, you have to inform `systemd` that a new service has been added. This is done with the following command: