Add a service
General
.service files are in /etc/systemd/system
So we create the /etc/systemd/system/rlmserver.service file:
[Unit]
Description=Redshift License Manager Server
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=simple
User=redshift
ExecStart=/bin/bash -c /home/redshift/rlm/rlm -c /home/redshift/rlm/license.lic
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target
After that we need to reload the deamon et enable the service:
systemctl daemon-reload
systemctl enable rlmserver.service
systemctl start rlmserver.service
Lately, we check everything is running:
root@server ~# systemctl status rlmserver.service
* rlmserver.service
Loaded: loaded (/etc/systemd/system/rlmserver.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-08-15 10:25:36 UTC; 33min ago
Main PID: 83 (rlm)
Tasks: 3 (limit: 4915)
CGroup: /system.slice/rlmserver.service
|- 83 /home/redshift/rlm/rlm
`-189 /home/redshift/rlm/rlm -g redshift /home/redshift/rlm/redshift.set -s 6 -p "/home/redshift/rlm"
Aug 15 10:25:38 server bash[83]: 08/15 10:25 (redshift)
Aug 15 10:25:38 server bash[83]: 08/15 10:25 (redshift) Server started on server (hostid: 0123456789ab) for:
Aug 15 10:25:38 server bash[83]: 08/15 10:25 (redshift) redshift-core
Aug 15 10:25:38 server bash[83]: 08/15 10:25 (redshift)
Aug 15 10:25:38 server bash[83]: 08/15 10:25 (redshift) License files:
Aug 15 10:25:38 server bash[83]: 08/15 10:25 (redshift) /home/redshift/rlm/license.lic
Aug 15 10:25:38 server bash[83]: 08/15 10:25 (redshift)
Aug 15 10:25:38 server bash[83]: 08/15 10:25 (redshift) File descriptor limit increased from 1024 to 4096
Aug 15 10:48:00 server bash[83]: 08/15 10:47 (redshift) OUT: redshift-core v2019.07 by workstation@somepc
Aug 15 10:48:00 server bash[83]: 08/15 10:47 (redshift) IN: redshift-core v2019.07 by workstation@somepc
Options
Type=
Configures the process start-up type for this service unit. One of simple, exec, forking, oneshot, dbus, notify or idle:
simple | If set to simple (the default if ExecStart= is specified but neither Type= nor BusName= are), the service manager will consider the unit started immediately after the main service process has been forked off. |
oneshot | Behavior of oneshot is similar to simple; however, the service manager will consider the unit up after the main process exits. It will then start follow-up units. |
ExecStart=
Commands with their arguments that are executed when this service is started.
Unless Type= is oneshot, exactly one command must be given. When Type=oneshot is used, zero or more commands may be specified.
Documentation
- https://www.freedesktop.org/software/systemd/man/systemd.service.html
- https://opensource.com/article/20/7/systemd-timers
- https://www.linode.com/docs/guides/start-service-at-boot/
- https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6
- https://www.shubhamdipt.com/blog/how-to-create-a-systemd-service-in-linux/
- https://unix.stackexchange.com/questions/206315/whats-the-difference-between-usr-lib-systemd-system-and-etc-systemd-system
- https://stackoverflow.com/questions/48195340/systemd-with-multiple-execstart
man systemd.unit
man systemd.service
man systemd.timer