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
77 if [ "$USE_SYSTEMD" != "no" ] && [ -x /bin/systemd_booted ] && /bin/systemd_booted; then
86 functions | halt | killall | single| linuxconf| kudzu)
89 if ! is_ignored_file "${SERVICE}" \
90 && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
91 if [ "$has_systemd" ] && [ -f /lib/systemd/system/${SERVICE}.service ]; then
98 if ! grep -qs "\Wstatus)" "$SERVICE"; then
99 printf " %s %-60s %s\n" "$TYPE:[?]" "$SERVICE:" "unknown"
102 out=$(env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status 2>&1)
103 if [ "$?" = "0" -a -n "$out" ]; then
104 printf " %s %-60s %s\n" "$TYPE:[+]" "$SERVICE:" "running"
107 printf " %s %-60s %s %s\n" "$TYPE:[-]" "$SERVICE:" "NOT running"
117 VERSION="$(basename $0) ver. 1.0-tld"
118 USAGE="Usage: $(basename $0) < option > | --status-all | \
119 [ service_name [ command | --full-restart ] ]"
124 if [ -d /etc/rc.d/init.d ]; then
125 SERVICEDIR="/etc/rc.d/init.d"
127 SERVICEDIR="/etc/init.d"
130 if [ $# -eq 0 ]; then
136 while [ $# -gt 0 ]; do
143 echo "${VERSION}" >&2
146 --ignore-dependencies)
147 export SYSTEMCTL_IGNORE_DEPENDENCIES=1
151 export SYSTEMCTL_SKIP_REDIRECT=1
159 if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
162 elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
164 if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
165 env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" stop
166 env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" start
169 elif [ -z "${SERVICE}" ]; then
171 elif [ -z "${ACTION}" ]; then
174 OPTIONS="${OPTIONS} ${1}"
181 if is_systemd_service "${SERVICE}" "${ACTION}"; then
182 echo >&2 "Redirecting to /bin/systemctl --output=cat ${ACTION} ${SERVICE}.service ${OPTIONS}"
183 exec /bin/systemctl --output=cat ${ACTION} ${SERVICE}.service ${OPTIONS}
184 elif [ -x "${SERVICEDIR}/${SERVICE}" ]; then
185 exec env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" ${ACTION} ${OPTIONS}
187 echo "${SERVICE}: unrecognized service" >&2