Today, I’ve learnt more about systemd on Linux.

I saw that it can be separated into user based or system based and there are three locations to save these services into:

/etc/systemd/system - ROOT
/usr/lib/systemd/system - ROOT but for package manager
/usr/lib/systemd/user - User

In order to work with root services, one must use sudo systemctl and to work with user services, use systemctl --user.

User services will run when a user is logged in, so for any GUI software, it’s best to use the user services.

For any kind of services that is to run when system start, such as critical services, it’s best to use root services.

Below is a simple USER systemd which runs transmission-gtk on login:

[Unit]
Description=Start transmission-gtk at startup.

[Service]
Type=simple
#User=jerry
#ExecStartPre=/bin/sleep 10
ExecStart=/usr/bin/transmission-gtk --minimized
Restart=on-failure
RestartSec=5

[Install]
WantedBy=default.target

And another which runs a server backend as jerry user on system boot (means if the user logs out, it will still be running)

[Unit]
Description=Go AIOServer
After=network.target

[Service]
Type=simple
WorkingDirectory=/home/jerry/aioserver
ExecStartPre=/bin/sleep 10
ExecStart=/home/jerry/aioserver/aio-server -https
Restart=always
User=jerry
Group=jerry

[Install]
WantedBy=multi-user.target

In fact, the whole structure is actually similar to Docker compose syntax.