Hi,
I run Arch Linux, and got into troubles trying to manage Yate(BTS) instances using the sysv-init compatibility layer of systemd. Till recently this worked quite well using the init script provided with Yate source code (though lightly patched to always exit 0).
But its seems that newer (Arch) releases of systemd are not compiled anymore with the support to auto-generate unit service files from init scripts deployed to /etc/init.d. Which makes the provided one unhelpful.
I share bellow the simple tips I applied to get Yate(BTS) running as a systemd managed service.
First, create a unit file /etc/systemd/system/<unit-name>.service:
[Unit]
Description=<unit-name> or whatever
[Service]
User=root or any user with appropriate permissions/capabilities
Type=forking
PIDFile=<path-to>/var/run/<unit-name>.pid
EnvironmentFile=<path-to>/etc/sysconfig/<unit-name>
ExecStart=<path-to>/ybts-start-unit.sh
ExecStop=<path-to>/ybts-stop-unit.sh
[Install]
WantedBy=multi-user.target
Typically:
[Unit]
Description=yate
[Service]
User=root
Type=forking
PIDFile=/var/run/<unit-name>.pid
EnvironmentFile=/etc/sysconfig/<unit-name>
ExecStart=/usr/local/bin/ybts-start-unit.sh
ExecStop=/usr/local/bin/ybts-stop-unit.sh
[Install]
WantedBy=multi-user.target
The file /etc/sysconfig/<unit-name> sets the environment variables used by the ybts-{start,stop}-unit.sh scripts, and would typically contain:
YBTS_YATE=/usr/local/bin/yate
YBTS_PIDFILE=/var/run/<unit-name>.pid
YBTS_LOGFILE=/var/log/<unit-name>
YBTS_CONF_DIR=/etc/yate
YBTS_EXTRA_DIR=/usr/local/share/yate
Once both files are written appropriately, run:
# systemctl daemon-reload
to make systemd be aware of the new service, an then manage it using:
# systemctl {start,stop,status} <unit-name>
.
IMHO, it's correct that the ybts-{start,stop}-unit.sh scripts always exit 0, as systemd will handle the dameon process life-cycle through its PID file, and not through the scripts exit value. Please correct me if I'm wrong.
There are other ways to achieve this, and more options available. But this might help getting started.
This pointer may also be worth reading if new to systemd:
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-managing_services_with_systemd-unit_filesKind regards,
spina.