Create Unix Service Under systemd

Most Linux distributions use systemd as a system and service manager. The systemctl is the main command in systemd, used to control services.

In my previous tutorial I described about creating any service under init.d. Here I will show how to create a systemd service file. Please follow these steps.

  • Create the service file, In my case i’ve tried with sphinx
    nano /etc/systemd/system/sphinx.service
  • Put this contents
    [Unit]
    Description=Sphinx Searchd service
    After=network.target
    StartLimitIntervalSec=0
    
    [Service]
    Type=simple
    Restart=always
    RestartSec=1
    User=root
    ExecStart=/usr/local/sphinx/bin/searchd
    ExecStop=/usr/local/sphinx/bin/searchd stop
    ExecReload=/usr/bin/fail2ban-client reload
    
    
    [Install]
    WantedBy=multi-user.target
    

Ref Link:
https://www.freedesktop.org/software/systemd/man/systemd.service.html
https://www.shellhacks.com/systemd-service-file-example/
https://www.commandlinux.com/man-page/man5/systemd.service.5.html