How to create Systemd system service/Daemon on Linux
Let's create a systemd system service daemon. in order to create a system service/Daemon in user space we need to create this directory ~/.config/systemd/user/ if it does not exist.
If this directory does not exist then create it by:
mkdir -p ~/.config/systemd/user/
Now, we need to creat the .service file inside the ~/.config/systemd/user/ directory. we are going to use nano text editor to do this:
nano ~/.config/systemd/user/example.service
Copy and paste the following systemd system daemon template in example.service file.
[Service]
WorkingDirectory=/usr/bin/
ExecStart=/usr/bin/syncthing
Restart=always
RestartSec=5
[Install]
WantedBy=default.target"
[!NOTE]
ExecStart=/usr/bin/syncthing: of this/usr/bin/syncthingline should be the path of the program you want to run as a service. You can get path of a any program by runningwhich program_nameif you have the program installed of cause.
Then enable it by calling systemctl --user enable
example
systemctl --user enable example.service