Changelog for 605a506
[systemd] / debian / lsb-base-logging.sh
1 # -*-Shell-script-*-
2 # /etc/lsb-base-logging.sh
3
4 if [ -e /sys/fs/cgroup/systemd ] ; then
5
6     # Some init scripts use "set -e" and "set -u", we don't want that
7     # here
8     set +e
9     set +u
10
11     if [ -n "$DPKG_MAINTSCRIPT_PACKAGE" ] ; then
12     # If we are called by a maintainer script, chances are good that a
13     # new or updated sysv init script was installed.  Reload daemon to
14     # pick up any changes.
15         echo "Reloading systemd"
16         systemctl daemon-reload
17     fi
18
19     # Redirect SysV init scripts when executed by the user
20     if [ $PPID -ne 1 ] && [ -z "$init" ] && [ -z "$_SYSTEMCTL_SKIP_REDIRECT" ] ; then
21         case "$0" in
22             /etc/init.d/*)
23                 # Don't redirect if the init script has X-Interactive: true
24                 if ! grep -qs "^# X-Interactive:.*true" "$0"; then
25                     _use_systemctl=1
26                 fi
27                 ;;
28         esac
29     else
30         export _SYSTEMCTL_SKIP_REDIRECT="true"
31     fi
32 else
33     _use_systemctl=0
34 fi
35
36 systemctl_redirect () {
37         local s
38         local rc
39         local prog=${1##*/}
40         local command=$2
41
42         case "$command" in
43         start)
44                 s="Starting $prog (via systemctl)"
45                 ;;
46         stop)
47                 s="Stopping $prog (via systemctl)"
48                 ;;
49         reload|force-reload)
50                 s="Reloading $prog configuration (via systemctl)"
51                 ;;
52         restart)
53                 s="Restarting $prog (via systemctl)"
54                 ;;
55         esac
56
57         service="${prog%.sh}.service"
58
59         # Don't try to run masked services. Don't check for errors, if
60         # this errors, we'll just call systemctl and possibly explode
61         # there.
62         state=$(systemctl -p LoadState show $service 2>/dev/null)
63         [ "$state" = "LoadState=masked" ] && return 0
64
65         [ "$command" = status ] || log_daemon_msg "$s" "$service"
66         /bin/systemctl $command "$service"
67         rc=$?
68         [ "$command" = status ] || log_end_msg $rc
69
70         return $rc
71 }
72
73 if [ "$_use_systemctl" = "1" ]; then
74         if  [ "x$1" = xstart -o \
75                 "x$1" = xstop -o \
76                 "x$1" = xrestart -o \
77                 "x$1" = xreload -o \
78                 "x$1" = xforce-reload -o \
79                 "x$1" = xstatus ] ; then
80
81                 systemctl_redirect $0 $1
82                 exit $?
83         fi
84 fi