Eu escrevi o serviço LSB para o Ubuntu 16.04 e não tenho nenhum problema:
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.4 LTS
Release: 16.04
Codename: xenial
Adicionando novo serviço fake-service
em /etc/init.d
com 755 permissões:
#!/bin/sh
# fake-service Bring up/down fake-service
#
### BEGIN INIT INFO
# Provides: fake-service
# Default-Start: 2 3 4 5
# Default-Stop:
#Required-Start:
#Required-Stop:
# Should-Start:
# Should-Start:
# Short-Description: Bring up/down fake-service
# Description: Bring up/down fake service
### END INIT INFO
DAEMON=
NAME=fake-service
DESC="fake-service"
PIDFILE=/var/run/fake-service.pid
SCRIPTNAME=/etc/init.d/fake-service
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg "Starting fake-service ..." "$NAME"
touch $PIDFILE
log_end_msg $?
;;
stop)
log_daemon_msg "Stoping fake-service ..." "$NAME"
rm -f $PIDFILE
log_end_msg $?
;;
status)
status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
;;
*)
log_action_msg "Usage: $0 {start|stop|status}"
exit 2
;;
esac
exit 0
Adicionando-o aos níveis de execução:
# update-rc.d fake-service defaults
De man 8 update-rc.d
:
When run with the defaults option, update-rc.d makes links named /etc/rcrunlevel.d/[SK]NNname that point to the script /etc/init.d/name, using runlevel and dependency information from the init.d script LSB comment header.
Serviço de teste:
Início:
# service fake-service start
# service fake-service status
● fake-service.service - LSB: Bring up/down fake-service
Loaded: loaded (/etc/init.d/fake-service; bad; vendor preset: enabled)
Active: active (exited) since Mon 2018-04-09 19:14:18 MSK; 4s ago
Docs: man:systemd-sysv-generator(8)
Process: 3643 ExecStop=/etc/init.d/fake-service stop (code=exited, status=0/SUCCESS)
Process: 3713 ExecStart=/etc/init.d/fake-service start (code=exited, status=0/SUCCESS)
Apr 09 19:14:18 ubuntu16-04 systemd[1]: Starting LSB: Bring up/down fake-service...
Apr 09 19:14:18 ubuntu16-04 fake-service[3713]: * Starting fake-service ... fake-service
Apr 09 19:14:18 ubuntu16-04 fake-service[3713]: ...done.
Apr 09 19:14:18 ubuntu16-04 systemd[1]: Started LSB: Bring up/down fake-service.
Parando:
# service fake-service stop
# service fake-service status
● fake-service.service - LSB: Bring up/down fake-service
Loaded: loaded (/etc/init.d/fake-service; bad; vendor preset: enabled)
Active: inactive (dead) since Mon 2018-04-09 19:15:03 MSK; 3s ago
Docs: man:systemd-sysv-generator(8)
Process: 3757 ExecStop=/etc/init.d/fake-service stop (code=exited, status=0/SUCCESS)
Process: 3713 ExecStart=/etc/init.d/fake-service start (code=exited, status=0/SUCCESS)
Apr 09 19:14:18 ubuntu16-04 systemd[1]: Starting LSB: Bring up/down fake-service...
Apr 09 19:14:18 ubuntu16-04 fake-service[3713]: * Starting fake-service ... fake-service
Apr 09 19:14:18 ubuntu16-04 fake-service[3713]: ...done.
Apr 09 19:14:18 ubuntu16-04 systemd[1]: Started LSB: Bring up/down fake-service.
Apr 09 19:15:03 ubuntu16-04 systemd[1]: Stopping LSB: Bring up/down fake-service...
Apr 09 19:15:03 ubuntu16-04 fake-service[3757]: * Stoping fake-service ... fake-service
Apr 09 19:15:03 ubuntu16-04 fake-service[3757]: ...done.
Apr 09 19:15:03 ubuntu16-04 systemd[1]: Stopped LSB: Bring up/down fake-service.