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
79 functions | halt | killall | single| linuxconf| kudzu)
82 if ! is_ignored_file "${SERVICE}" \
83 && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
84 if [ -f /etc/init/${SERVICE}.conf ]; then
91 if ! grep -qs "\Wstatus)" "$SERVICE"; then
92 #printf " %s %-60s %s\n" "[?]" "$SERVICE:" "unknown" 1>&2
93 echo " [ ? ]{$TYPE} $SERVICE"
96 out=$(env -i USE_UPSTART=$USE_UPSTART LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status 2>&1)
97 if [ "$?" = "0" -a -n "$out" ]; then
98 #printf " %s %-60s %s\n" "[+]" "$SERVICE:" "running"
99 echo " [ + ]{$TYPE} $SERVICE"
102 #printf " %s %-60s %s\n" "[-]" "$SERVICE:" "NOT running"
103 echo " [ - ]{$TYPE} $SERVICE"
107 #env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status
114 VERSION="$(basename $0) ver. 0.91-pld"
115 USAGE="Usage: $(basename $0) < option > | --status-all | \
116 [ service_name [ command | --full-restart ] ]"
122 if [ -d /etc/rc.d/init.d ]; then
123 SERVICEDIR="/etc/rc.d/init.d"
125 SERVICEDIR="/etc/init.d"
128 if [ $# -eq 0 ]; then
134 while [ $# -gt 0 ]; do
141 echo "${VERSION}" >&2
144 --ignore-dependencies)
145 export SYSTEMCTL_IGNORE_DEPENDENCIES=1
149 export SYSTEMCTL_SKIP_REDIRECT=1
165 if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
168 elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
170 if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
171 env -i USE_UPSTART=$USE_UPSTART LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" stop
172 env -i USE_UPSTART=$USE_UPSTART LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" start
175 elif [ -z "${SERVICE}" ]; then
177 elif [ -z "${ACTION}" ]; then
180 OPTIONS="${OPTIONS} ${1}"
187 if is_systemd_service "${SERVICE}" "${ACTION}"; then
188 echo >&2 "Redirecting to /bin/systemctl --output=cat ${ACTION} ${SERVICE}.service ${OPTIONS}"
189 exec /bin/systemctl --output=cat ${ACTION} ${SERVICE}.service ${OPTIONS}
190 elif [ -x "${SERVICEDIR}/${SERVICE}" ]; then
191 exec env -i USE_UPSTART=$USE_UPSTART LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" ${ACTION} ${OPTIONS}
193 echo "${SERVICE}: unrecognized service" >&2