Skip to content

Instantly share code, notes, and snippets.

@ikbelkirasan
Created February 13, 2019 14:23
Show Gist options
  • Save ikbelkirasan/41a39b654c25d03d0dc9eedd49717fbd to your computer and use it in GitHub Desktop.
Save ikbelkirasan/41a39b654c25d03d0dc9eedd49717fbd to your computer and use it in GitHub Desktop.
Create a systemd service

Create a systemd service

  1. 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
  1. 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
  1. Start your service
$ sudo systemctl start my_service_program
  1. (Optional) Start your service even after rebooting your machine
$ sudo systemctl enable my_service_program