diff options
Diffstat (limited to 'add-service')
-rwxr-xr-x | add-service | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/add-service b/add-service index 9e25c37..46a98ac 100755 --- a/add-service +++ b/add-service @@ -26,6 +26,7 @@ options=--quiet [ -x /bin/systemctl -a -r /lib/systemd/system/${srv}.service ] && systemd=yes [ -r /etc/rc.d/init.d/${srv} ] && sysv=yes [ $sysv = yes ] && options="$options --no-reload" +unit=${srv}.service add_chkconfig_service() { srv=$1 @@ -33,7 +34,7 @@ add_chkconfig_service() { # support for systemd. chkconfig will do daemon-reload for us if [ $systemd = yes ]; then - /bin/systemctl $options enable ${srv}.service + /bin/systemctl $options enable ${unit} fi if [ $sysv = yes ]; then /sbin/chkconfig --add $srv @@ -82,26 +83,29 @@ if [ $num = 1 ]; then # First install mode add_service else - # Upgrade mode. Only really makes sense for SysV scripts - [ $sysv = yes ] || exit 0 + # Upgrade mode. # if the service is activated, add it again to be able to handle - # changes in start/stop levels and enable systemd unit as well - set -- /etc/rc3.d/S??$srv - if [ $# -gt 1 ]; then - echo 1>&2 "add-service: Error: $srv appears multiple times: $*" + # changes in start/stop levels or systemd WantedBy lines + + if [ $systemd = yes ] && /bin/systemctl is-enabled ${unit}; then + /bin/systemctl --quiet enable ${unit} fi - if [ -f "$1" ]; then - if [ $systemd = yes ]; then - /bin/systemctl $options enable ${srv}.service + if [ $sysv = yes ]; then + set -- /etc/rc3.d/S??$srv + if [ $# -gt 1 ]; then + echo 1>&2 "add-service: Error: $srv appears multiple times: $*" fi - /sbin/chkconfig --add $srv - fi - # restart the service if already running - if [ -f /var/lock/subsys/$srv ]; then - /sbin/service $srv restart > /dev/null || : + if [ -f "$1" ]; then + /sbin/chkconfig --add $srv + fi + + # restart the service if already running + if [ -f /var/lock/subsys/$srv ]; then + /sbin/service $srv restart > /dev/null || : + fi fi fi |