All about systemD and more importantly how to use and create services that automatically start on system startup

SystemD is the main adopted system and service manager for Linux

Common Commands

Show system status

systemctl status

List failed units

systemctl --failed

List installed unit files

systemctl list-unit-files

List all running services


Start a service

systemctl start <service_name>

Stop a service

systemctl stop <service_name>

Restart a service:

systemctl restart <service_name>

Show status of a service:

systemctl status <service_name>

Enable a service on startup:

systemctl enable <service_name>

Disable a service during startup:

systemctl disable example1

Creating or altering services

Units are defined by individual configuration files, called unit files

Unit files provided by debian are found in: /lib/systemd/system

An identically named unit file in /etc/systemd/system, takes precedence over those in /lib/systemd/system

System admins should put unit files in: /etc/systemd/system


Create this file

    Description= kong service postgresql.service

    ExecStart=/usr/local/bin/kong start
    ExecReload=/usr/local/bin/kong reload
    ExecStop=/usr/local/bin/kong stop


Then run

    systemctl start kong
    systemctl stop kong
    systemctl enable kong

Forking vs Simple

According to this post on the SystemD Forking vs Simple if a service does not return anything and can only be closed with ctrl+c you should use simple.

If it does daemonise itself, then you should use forking

If a service just does one thing, then oneshot is the right choice.