3 # Set up a default search path.
4 PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
7 VERSION="$(basename $0) ver. 0.91"
8 USAGE="Usage: $(basename $0) < option > | --status-all | \
9 [ service_name [ command | --full-restart ] ]"
13 . /etc/rc.d/init.d/functions
15 if [ -d /etc/rc.d/init.d ]; then
16 SERVICEDIR="/etc/rc.d/init.d"
18 SERVICEDIR="/etc/init.d"
27 grep -q '^task' "/etc/init/$1.conf"
30 initctl status "$1" 2>/dev/null | grep -q running
34 is_running "${SERVICE}" && return 0
35 msg_starting "${SERVICE}"
36 if errors=$(/sbin/initctl start ${SERVICE} 2>&1) ; then
47 if ! is_running "${SERVICE}" && ! is_task "${SERVICE}" ; then
50 msg_stopping "${SERVICE}"
51 if errors=$(/sbin/initctl stop ${SERVICE}) ; then
62 # should be compliant with
63 # http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
66 if is_task "${SERVICE}" ; then
67 # we probably should have a way to handle task status
70 if ! status=$(/sbin/initctl status "${SERVICE}") ; then
71 # program or service status is not known
74 if strstr "$status" "running" ; then
75 # program is running or service is OK
78 # program is not running
81 # TODO: other statuses
85 while [ $# -gt 0 ]; do
96 if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
99 if use_upstart && [ -f "/etc/init/${SERVICE}.conf" ] ; then
103 functions | halt | killall | single| linuxconf| kudzu | \
104 *rpmorig | *rpmnew | *rpmsave | *~ | *.orig)
107 if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
108 env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" status
113 if [ -d /etc/init ] && use_upstart ; then
118 control-alt-delete | rc | rcS-sulogin | rcS | start-ttys | tty)
121 /sbin/initctl status "${SERVICE}"
127 elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
129 if [ -f "/etc/init/${SERVICE}.conf" ] && use_upstart ; then
132 elif [ -x "${SERVICEDIR}/${SERVICE}" ]; then
133 env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" stop
134 env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" start
137 elif [ -z "${SERVICE}" ]; then
141 OPTIONS="${OPTIONS} ${1}"
148 if [ -f "/etc/init/${SERVICE}.conf" ] && use_upstart ; then
151 upstart_start "${SERVICE}"
155 upstart_stop "${SERVICE}"
159 upstart_status "${SERVICE}"
163 if ! grep -Eq '#\s*pld-flags:.*no-sighup-reload' "/etc/init/${SERVICE}.conf" ; then
164 upstart_reload "${SERVICE}"
167 upstart_stop "${SERVICE}"
168 upstart_start "${SERVICE}"
173 if ! grep -Eq '#\s*pld-flags:.*no-sighup-reload' "/etc/init/${SERVICE}.conf" ; then
174 upstart_reload "${SERVICE}"
177 if [ ! -x "${SERVICEDIR}/${SERVICE}" ]; then
178 msg_usage "$0 {start|stop|restart|status|force-reload}"
181 # if not handled here, pass it the rc.d/init.d script
184 if [ ! -x "${SERVICEDIR}/${SERVICE}" ]; then
185 commands="start|stop|restart|status|force-reload"
186 if ! grep -Eq '#\s*pld-flags:.*no-sighup-reload' "/etc/init/${SERVICE}.conf" ; then
187 commands="$commands|reload"
189 msg_usage "$0 {$commands}"
192 # pass the rest to the rc.d/init.d script
197 if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
198 env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" ${OPTIONS}
200 echo "${SERVICE}: unrecognized service" >&2