3 # Set up a default search path.
4 PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
9 skeleton | README | *.dpkg-dist | *.dpkg-old | rc | rcS | single | reboot | bootclean.sh)
12 *rpmorig | *rpmnew | *rpmsave | *~ | *.orig)
19 # check if SERVICE is present in systemd and ACTION is valid systemctl command
20 # returns false if systemd is disabled or not active
21 is_systemd_service() {
22 local SERVICE=$1 ACTION=$2
24 [ "$USE_SYSTEMD" = "no" ] && return 1
26 # if we are called from systemd itself, because some .service specified
27 # invocation via /sbin/service. this avoids loops
28 # detect this via CMDLINE var, which has leaked from geninitrd
29 if [ -n "$CMDLINE" ]; then
30 echo >&2 "Warning: CMDLINE env set, likely you are defining .service to use /sbin/service, please use /etc/rc.d/init.d/<SERVICE> instead"
35 # list obtained as: man systemctl | grep N.*A.*M.*E
42 reload-or-try-restart | \
64 #echo "Not valid systemd command"
68 [ -x /bin/systemd_booted ] || return 1
69 /bin/systemd_booted || return 1
71 /bin/systemctl show "$SERVICE".service | grep -q LoadError= && return 1 || return 0
75 local SERVICE TYPE has_systemd has_upstart
77 if [ "$USE_SYSTEMD" != "no" ] && [ -x /bin/systemd_booted ] && /bin/systemd_booted; then
83 if [ "$USE_UPSTART" != "no" ] && [ -x /sbin/initctl ]; then
92 functions | halt | killall | single| linuxconf| kudzu)
95 if ! is_ignored_file "${SERVICE}" \
96 && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
97 if [ "$has_systemd" ] && [ -f /lib/systemd/system/${SERVICE}.service ]; then
100 elif [ "$has_upstart" ] && [ -f /etc/init/${SERVICE}.conf ]; then
107 if ! grep -qs "\Wstatus)" "$SERVICE"; then
108 printf " %s %-60s %s\n" "$TYPE:[?]" "$SERVICE:" "unknown"
111 out=$(env -i USE_UPSTART=$USE_UPSTART LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status 2>&1)
112 if [ "$?" = "0" -a -n "$out" ]; then
113 printf " %s %-60s %s\n" "$TYPE:[+]" "$SERVICE:" "running"
116 printf " %s %-60s %s %s\n" "$TYPE:[-]" "$SERVICE:" "NOT running"
126 VERSION="$(basename $0) ver. 0.91-pld"
127 USAGE="Usage: $(basename $0) < option > | --status-all | \
128 [ service_name [ command | --full-restart ] ]"
134 if [ -d /etc/rc.d/init.d ]; then
135 SERVICEDIR="/etc/rc.d/init.d"
137 SERVICEDIR="/etc/init.d"
140 if [ $# -eq 0 ]; then
146 while [ $# -gt 0 ]; do
153 echo "${VERSION}" >&2
156 --ignore-dependencies)
157 export SYSTEMCTL_IGNORE_DEPENDENCIES=1
161 export SYSTEMCTL_SKIP_REDIRECT=1
177 if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
180 elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
182 if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
183 env -i USE_UPSTART=$USE_UPSTART LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" stop
184 env -i USE_UPSTART=$USE_UPSTART LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" start
187 elif [ -z "${SERVICE}" ]; then
189 elif [ -z "${ACTION}" ]; then
192 OPTIONS="${OPTIONS} ${1}"
199 if is_systemd_service "${SERVICE}" "${ACTION}"; then
200 echo >&2 "Redirecting to /bin/systemctl --output=cat ${ACTION} ${SERVICE}.service ${OPTIONS}"
201 exec /bin/systemctl --output=cat ${ACTION} ${SERVICE}.service ${OPTIONS}
202 elif [ -x "${SERVICEDIR}/${SERVICE}" ]; then
203 exec env -i USE_UPSTART=$USE_UPSTART LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" ${ACTION} ${OPTIONS}
205 echo "${SERVICE}: unrecognized service" >&2