- Copy the program you want to run to
/usr/bin
folder and make it executable.
$ sudo cp my_service_program.sh /usr/bin
$ sudo chmod +x /usr/bin/my_service_program.sh
- Create the unit file
The service file should be located at this folder: /lib/systemd/system/
Run:
$ sudo nano /lib/systemd/system/my_service_program.service
Add this content to the file.
[Unit]
Description=Example systemd service.
[Service]
Type=simple
ExecStart=/usr/bin/my_service_program.sh
User=osboxes
Group=osboxes
Restart=always
[Install]
WantedBy=multi-user.target
- Start your service
$ sudo systemctl start my_service_program
- (Optional) Start your service even after rebooting your machine
$ sudo systemctl enable my_service_program
Resources
https://www.linode.com/docs/quick-answers/linux/start-service-at-boot/#create-a-custom-systemd-service
https://www.linode.com/docs/quick-answers/linux/start-service-at-boot/
https://askubuntu.com/questions/676007/how-do-i-make-my-systemd-service-run-via-specific-user-and-start-on-boot