1 #!/bin/sh - keep it for file(1) to get bourne shell script result
2 # functions This file contains functions to be used by most or all
3 # shell scripts in the /etc/rc.d/init.d directory.
7 # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
8 # Hacked by: Greg Galloway and Marc Ewing
9 # Modified for PLD Linux by:
10 # Marek Obuchowicz <elephant@pld-linux.org>
11 # Arkadiusz Miśkiewicz <misiek@pld-linux.org>
12 # Michał Kochanowicz <mkochano@pld-linux.org>
13 # Łukasz Pawelczyk <havner@pld-linux.org>
15 # First set up a default search path.
16 export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
19 if [ -z "$COLUMNS" -o -z "$LINES" ]; then
21 set -- $(stty size 2>/dev/null)
23 COLUMNS=${COLUMNS:-$2}
28 [ -z "$LINES" ] || [ "$LINES" -le 0 ] && LINES=40
29 [ -z "$COLUMNS" ] || [ "$COLUMNS" -le 0 ] && COLUMNS=80
31 INIT_COL=$((COLUMNS - 13))
42 # Bold definition (second parameter to termput setaf)
46 CBRACKETS="$CYAN" # brackets [ ] color
47 CDONE="$GREEN" # DONE and WORK color
48 CBUSY="$MAGENTA" # BUSY color
49 CFAIL="$RED" # FAIL and DIED color
50 CPOWEREDBY="$CYAN" # "Powered by" color
51 CPLD="$GREEN" # "PLD Linux Distribution" color
52 CI="$RED" # Capital I color (press I to enter interactive startup)
53 CRESMAN="$GREEN" # "Resource Manager" color
54 CHARS="" # Characters displayed on the beginning of show line
55 CCHARS="$NORMAL" # Color of these characters (look at /etc/sysconfig/init-colors.gentoo example)
57 # Source configuration if available - may override default values
58 [ -r /etc/sysconfig/init-colors ] && . /etc/sysconfig/init-colors
59 [ -r /etc/sysconfig/system ] && . /etc/sysconfig/system
60 [ -r /etc/sysconfig/bootsplash ] && . /etc/sysconfig/bootsplash
62 if [ -z "$VSERVER" -o "$VSERVER" = "detect" ]; then
64 while read _f _ctx; do
65 [ "$_f" = "VxID:" -o "$_f" = "s_context:" ] && break
66 done </proc/self/status
68 if [ -z "$_ctx" -o "$_ctx" = "0" ]; then
76 # VSERVER_ISOLATION_NET = isolation only inside of vserver guests
77 if [ -z "$VSERVER_ISOLATION_NET" -o "$VSERVER_ISOLATION_NET" = "detect" ]; then
78 VSERVER_ISOLATION_NET=no
79 if [ "$VSERVER" = "yes" ]; then
80 if [ -f /proc/self/nsproxy ]; then
82 while read _t _data; do
83 [ "$_t" = "net:" ] && break
84 done < /proc/self/nsproxy
87 # assume old kernel mode
88 VSERVER_ISOLATION_NET=yes
90 if [ "${_data##*\(}" = "I)" ]; then
91 VSERVER_ISOLATION_NET=yes
97 # we need to know in functions if we were called from a terminal
98 if [ -z "$ISATTY" ]; then
99 [ -t ] && ISATTY=yes || ISATTY=no
106 msg_usage " is_yes {value}"
112 yes|Yes|YES|true|True|TRUE|on|On|ON|Y|y|1)
126 msg_usage " is_no {value}"
131 no|No|NO|false|False|FALSE|off|Off|OFF|N|n|0)
142 # checks if file is empty
143 # empty lines and lines beginning with hash are ignored
145 [ -s "$1" ] || return 0
146 grep -vqE "^(#|[[:blank:]]*$)" "$1" && return 1 || return 0
149 # returns OK if $1 contains $2
152 [ "${1#*$a*}" = "$1" ] && return 1
156 if is_yes "$FASTRC" || is_yes "$IN_SHUTDOWN"; then
160 if is_no "$RC_LOGGING"; then
163 while [ "$1" != "${1##-}" ]; do
181 local _x _y _z v v1 old_IFS ver
185 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
194 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
196 while [ ${#ver} -lt 6 ]; do ver="0$ver"; done
198 while [ ${#ver} -lt 9 ]; do ver="0$ver"; done
204 local _x _y _z v v1 old_IFS ver
208 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
216 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
218 while [ ${#ver} -lt 6 ]; do ver="0$ver"; done
224 local _x _y _z v v1 old_IFS ver
228 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
236 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
243 is_yes "$ISATTY" || return
245 if is_yes "$FASTRC" || is_no "$TPUT"; then
248 echo -ne "\033[$(($2+1))G"
251 echo -ne "\033[${2}A"
263 is_yes "$COLOR_INIT" && echo -ne "\033[${ISBOLD};3${2}m"
266 termput setaf $NORMAL
275 if [ "$3" = "1" ]; then tput bold; else tput sgr0; fi
276 is_yes "$COLOR_INIT" && tput setaf "$2"
279 termput setaf $NORMAL
285 if [ ! -x /bin/printf ]; then
287 # FIXME: buggy when single or double quotes in message!
292 if [ $# -gt 0 ]; then
295 while [ $# -gt 0 ]; do
300 awk "BEGIN {printf \"$text\", \"$m\"; }"
304 # National language support function
306 local msg_echo nls_domain text message
308 nls_domain="$NLS_DOMAIN"
309 while [ "$1" != "${1##-}" ]; do
325 # empty message, so we return --misiek
326 if [ -z "$message" ]; then
331 if is_yes "$GETTEXT"; then
332 message=$(TEXTDOMAINDIR="/etc/sysconfig/locale" gettext -e --domain="${nls_domain:-rc-scripts}" "$message")
335 printf "$message" "$@"
342 if ! is_no "$BOOT_SPLASH" && ! is_yes "$VSERVER"; then
343 [ -x /bin/splash ] && /bin/splash "$action"
350 nls "ERROR: Networking is down. %s can't be run." "$1" >&2
354 show "Starting %s service" "$1"
357 msg_already_running() {
358 nls "%s service is already running." "$1"
362 show "Stopping %s service" "$1"
366 nls "%s service is not running." "$1"
370 show "Reloading %s service" "$1"
377 # Some functions to handle PLD Linux-style messages
381 if is_no "$FASTRC" && is_yes "$GETTEXT"; then
387 while [ $((len++)) -lt $INIT_COL ]; do
390 if [ -n "$CHARS" ]; then
391 termput setaf $CCHARS
399 termput hpa $INIT_COL
402 # Displays message in square brackests ("[ DONE ]"). Takes two arguments.
403 # First is the text to display, second is color number to use (argument to
404 # tput setaf). If second argument is not given, default (2, green) will be
414 echo -n "$(termput setaf $CBRACKETS)[$(termput setaf $COLOR) $(nls --nls-domain rc-scripts "$1") $(termput setaf $CBRACKETS)]$(termput op)"
439 # Check if $pid (could be plural) are running
442 [ -d "/proc/$1" ] && return 0
448 # - outside chroot get only those processes, which are outside chroot.
449 # - inside chroot get only those processes, which are inside chroot.
450 # - don't filter out pids which do not have corresponding running processes (process died etc)
451 # (note: some processes like named are chrooted but run outside chroot)
452 # - do nothing inside vserver
454 if is_yes "$VSERVER"; then
458 if [ $# -lt 1 -o ! -d /proc/1 ]; then
462 local root_dir good_pids="" good_add_pid
463 for root_pid in $@; do
464 root_dir=$(resolvesymlink /proc/${root_pid}/root)
465 if [ -n "$root_dir" ]; then
467 if [ -n "${SYSTEM_CHROOTS}" ]; then
468 for r_dir in ${SYSTEM_CHROOTS}; do
469 echo "$root_dir" | grep -q "^${r_dir}" && good_add_pid=0
472 [ "$good_add_pid" -eq 1 ] && good_pids="$good_pids $root_pid"
473 elif [ ! -d "/proc/$root_pid" ]; then
474 good_pids="$good_pids $root_pid"
481 # run_cmd Message command_to_run
482 # run_cmd -a Message command_to_run
483 # run_cmd --user "username" "Message" command_to_run
485 local force_err=0 exit_code=0 errors user
486 while [ $# -gt 0 ]; do
501 local message=$1; shift
502 show "$message"; busy
506 export HOME=/tmp TMPDIR=/tmp
507 if is_no "$RC_LOGGING"; then
508 ${user:+setuidgid -s $user} "$@" 2>&1
510 ${user:+setuidgid -s $user} initlog -c "$*" 2>&1
514 log_success "$1 $message"
517 log_failed "$1 $message"
520 [ -n "$errors" ] && [ $exit_code -eq 1 -o $force_err -eq 1 ] && echo "$errors"
524 _daemon_set_ulimits() {
525 local opt val ksh=${KSH_VERSION:+1}
526 set -- ${SERVICE_LIMITS:-$DEFAULT_SERVICE_LIMITS}
527 while [ $# -gt 0 ]; do
548 # A function to start a program (now it's useful on read-only filesystem too)
550 local errors="" prog="" end="" waitname="" waittime=""
552 local nice=$SERVICE_RUN_NICE_LEVEL
553 local fork user closefds redirfds pidfile makepid chdir=/
555 # NOTE: if you wonder how the shellish (by syntax) $prog works in ssd mode,
556 # then the answer is: it totally ignores $prog and uses "$@" itself.
558 while [ $# -gt 0 ]; do
561 msg_usage " daemon [--check] [--user user] [--fork] [--chdir directory] [--closefds] [--redirfds] [--waitforname procname] [--waitfortime seconds] [--pidfile file] [--makepid] [+/-nicelevel] {program} <program args>"
565 # for compatibility with redhat/mandrake
566 nls "warning: --check option is ignored!"
571 [ "$1" != "root" ] && prog="/bin/su $1 -s /bin/sh -c \""
576 prog="/usr/bin/setsid sh -c \""
600 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
616 # If command to execute ends with quotation mark, add remaining
617 # arguments and close quotation.
618 if [ "$prog" != "${prog%\"}" ]; then
619 prog="$prog $*$end\""
626 [ -z "$DEFAULT_SERVICE_UMASK" ] && DEFAULT_SERVICE_UMASK=022
627 [ -z "$DEFAULT_SERVICE_RUN_NICE_LEVEL" ] && DEFAULT_SERVICE_RUN_NICE_LEVEL=0
632 [ -n "$SERVICE_CPUSET" ] && is_yes "$CPUSETS" && echo $$ > "/dev/cpuset/${SERVICE_CPUSET}/tasks"
634 umask ${SERVICE_UMASK:-$DEFAULT_SERVICE_UMASK};
635 export USER=root HOME=/tmp TMPDIR=/tmp
636 nice=${nice:-$DEFAULT_SERVICE_RUN_NICE_LEVEL}
639 if [ "$closefds" = 1 ]; then
643 elif [ "$redirfds" = 1 ]; then
651 if is_no "$RC_LOGGING"; then
653 if [ ! -x $prog ]; then
654 logger -t rc-scripts -p daemon.debug "daemon: Searching PATH for $prog, consider using full path in initscript"
658 if [ -x $a/$prog ]; then
665 /sbin/start-stop-daemon -q --start \
667 ${pidfile:+--pidfile $pidfile} \
668 ${makepid:+--make-pidfile} \
669 ${user:+--chuid $user} \
670 ${chdir:+--chdir "$chdir"} \
671 ${fork:+--background} \
672 ${waitname:+--name $waitname} \
673 ${SERVICE_DROPCAPS:+--dropcap $SERVICE_DROPCAPS} \
677 nice -n $nice initlog -c "$prog" 2>&1
681 if [ -n "$waitname" -a -n "$waittime" ]; then
685 pid=$(pidofproc "$waitname" "$pidfile")
686 [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
688 while [ "$i" -lt "$waittime" ]; do
690 checkpid $pid && sleep 1 || break
693 log_success "$1 startup"
698 log_failed "$1 startup"
699 [ -n "$errors" ] && echo >&2 "$errors"
704 # A function to stop a program.
706 local notset killlevel base pid pidfile result
709 msg_usage " killproc [--pidfile PIDFILE] {program} [-SIGNAME]"
713 while [ "$1" != "${1##-}" ]; do
717 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
734 # check for second arg to be kill level
741 # experimental start-stop-daemon based killing.
742 # works only with pidfile
743 if is_no "$RC_LOGGING" && [ "$pidfile" ]; then
744 local sig=${killlevel:--TERM}
745 /sbin/start-stop-daemon -q --stop \
746 --retry ${sig#-}/10/${sig#-}/60/KILL/10 \
748 ${pidfile:+--pidfile $pidfile}
750 if [ "$result" -eq 0 ]; then
763 pid=$(pidofproc "$1" "$pidfile")
764 [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
767 if [ -n "$pid" -a "$pid" != "$$" ] && checkpid $pid 2>&1; then
768 if [ "$notset" = "1" ]; then
769 if checkpid $pid 2>&1; then
770 # TERM first, then KILL if not dead
773 if checkpid $pid && sleep 1 &&
774 checkpid $pid && sleep 3 &&
776 # XXX: SIGKILL is sent already on 4th second!
777 # HARMFUL for example to mysqld (which is already workarounded)
784 if [ "$result" -eq 0 ]; then
786 log_failed "$1 shutdown"
789 log_success "$1 shutdown"
791 result=$(( ! $result ))
793 # use specified level only
794 if checkpid $pid > /dev/null 2>&1; then
797 if [ "$result" -eq 0 ]; then
799 log_success "$1 got $killlevel"
803 log_failed "$1 didn't get $killlevel"
808 log_failed "$1 shutdown"
813 log_failed "$1 shutdown"
817 if [ -n "$waitname" -a -n "$waittime" ]; then
821 pid=$(pidofproc "$waitname" "$pidfile")
822 [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
824 while [ "$i" -lt "$waittime" ]; do
826 checkpid $pid && sleep 1 || break
830 # Remove pid file if any.
831 if [ "$notset" = "1" ]; then
832 rm -f /var/run/${base}.pid
838 # A function to find the pid of a program.
840 local pid pidfile base=${1##*/}
842 [ -n "$2" ] && pidfile="$2"
846 msg_usage " pidofproc {program}"
850 # First try pidfile or "/var/run/*.pid"
852 /*)pidfile="${pidfile}";;
853 *) pidfile="/var/run/$pidfile";;
855 if [ -f "${pidfile}" ]; then
857 for p in $(< "${pidfile}"); do
858 [ -z "$(echo "$p" | awk '{gsub(/[0-9]/,"");print;}')" ] && pid="$pid $p"
863 [ -z "$pid" ] && pidof -o $$ -o $PPID -o %PPID -x "$1"
864 pid=$(filter_chroot "$pid")
868 # status [--pidfile PIDFILE] {subsys} [{daemon}]"
870 local pid subsys daemon cpuset_msg pidfile
871 if [ "$1" = "--pidfile" -o "$1" = "-p" ]; then
873 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
882 msg_usage " status [--pidfile PIDFILE] {subsys} [{daemon}]"
886 # if pidfile specified, pid must be there
887 if [ "$pidfile" ]; then
888 [ -f "$pidfile" ] && read pid < $pidfile
889 # filter_chroot does not filter out dead pids, so this extra check, see t/status-pidfile.sh
890 if [ ! -d "/proc/$pid" ]; then
894 pid=$(pidof -o $$ -o $PPID -o %PPID -x $daemon)
896 pid=$(filter_chroot "$pid")
900 if [ -n "$SERVICE_CPUSET" ] && is_yes "$CPUSETS"; then
901 if grep -q "$pid" "/dev/cpuset/${SERVICE_CPUSET}/tasks"; then
902 cpuset_msg=$(nls " in cpuset %s..." "$SERVICE_CPUSET")
904 cpuset_msg=$(nls " outside of configured cpuset %s..." "$SERVICE_CPUSET")
907 nls "%s (pid %s) is running%s" "$daemon" "$pid" "$cpuset_msg"
911 # Next try "/var/run/*.pid" files; if pidfile is not set
912 local base=${daemon##*/}
913 if [ -z "$pidfile" -a -f /var/run/${base}.pid ]; then
914 read pid < /var/run/${base}.pid
915 pid=$(filter_chroot "$pid")
917 nls "%s dead but pid file (%s) exists" "$subsys" /var/run/${base}.pid
922 # See if /var/lock/subsys/$subsys exists
923 if [ -f /var/lock/subsys/$subsys ]; then
924 nls "daemon %s dead but subsys (%s) locked" "$daemon" "$subsys"
927 nls "%s is stopped" "$subsys"
931 # Confirm whether we really want to run this service
934 nls -n "Start service %s (Y)es/(N)o/(C)ontinue? [Y] " "$1"
953 # module is needed (ie. is requested, is available and isn't loaded already)
955 # module name without .o at end
956 if ! lsmod | grep -q "$1"; then
957 if ls -1R /lib/modules/$(uname -r)/ 2> /dev/null | grep -q "^${1}.\(\|k\)o\(\|.gz\)"; then
967 local parsed single die args foo result
969 while is_no "$parsed"; do
988 if is_yes "${single}"; then
990 show "Loading %s kernel module(s)" "$foo"
993 if [ -x /sbin/modprobe ]; then
994 /sbin/modprobe -s $args "$@"
1000 if is_yes "${single}"; then
1002 if [ $result = "0" ]; then
1003 is_yes "$single" && ok
1006 if is_yes "$die"; then
1007 nls "Could not load %s kernel module(s)" "$@"
1014 if is_no "$RC_LOGGING"; then
1024 initlog -n $0 -s "$1 $2" -e 1
1028 initlog -n $0 -s "$1 $2" -e 2
1032 # Check if any flavor of portmapper is running
1033 check_portmapper() {
1034 if [ -x /usr/sbin/rpcinfo ]; then
1035 if /usr/sbin/rpcinfo -p localhost >/dev/null 2>/dev/null; then
1040 elif [ -z "$(pidof portmap)" -a -z "$(pidof rpcbind)" ]; then
1046 # is_fsmounted fstype mntpoint
1047 # Check if filesystem fstype is mounted on mntpoint
1052 [ -n "$fstype" -a -n "$mntpoint" ] || return 1
1054 if [ -r /proc/mounts ]; then
1055 grep -qE "[[:blank:]]$mntpoint[[:blank:]]+$fstype[[:blank:]]" /proc/mounts
1058 if [ "$(stat -L -f -c %T $mntpoint 2>/dev/null)" = "$fstype" ]; then
1066 # __umount_loop awk_program fstab_file first_msg retry_msg umount_args
1067 # awk_program should process fstab_file and return a list of fstab-encoded
1068 # paths; it doesn't have to handle comments in fstab_file.
1070 local remaining sig=
1073 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1074 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
1075 if [ "$retry" -eq 3 ]; then
1076 run_cmd "$3" fstab-decode umount $5 $remaining
1078 run_cmd "$4" fstab-decode umount $5 $remaining
1081 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1082 while [ "$count" -gt 0 ]; do
1083 [ -z "$remaining" ] && break
1086 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1088 [ -z "$remaining" ] && break
1089 fstab-decode /sbin/fuser -k -m $sig $remaining >/dev/null
1091 retry=$(($retry -1))
1096 # Similar to __umount loop above, specialized for loopback devices
1097 __umount_loopback_loop() {
1098 local remaining devremaining sig=
1101 remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
1102 devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
1103 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
1104 if [ "$retry" -eq 3 ]; then
1105 run_cmd "Unmounting loopback filesystems: " \
1106 fstab-decode umount $remaining
1108 run_cmd "Unmounting loopback filesystems (retry):" \
1109 fstab-decode umount $remaining
1111 for dev in $devremaining ; do
1112 losetup $dev > /dev/null 2>&1 && \
1113 run_cmd "Detaching loopback device $dev: " \
1116 remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
1117 devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
1118 [ -z "$remaining" ] && break
1119 fstab-decode /sbin/fuser -k -m $sig $remaining >/dev/null
1121 retry=$(($retry -1))
1127 # If we have cachefile, use it.
1128 # If we don't, create memory variables and try to save silently,
1129 local cachefile='/var/cache/rc-scripts/msg.cache'
1132 if is_yes "$ISATTY"; then
1138 # We create $check variable which is used to invalidate the cache.
1139 # The $check contains user locale and terminal.
1140 local check="$term.$LC_MESSAGES.$INIT_COL"
1142 if [ -f "$cachefile" -a "$cachefile" -nt /etc/sysconfig/system -a "$cachefile" -nt /etc/sysconfig/init-colors ]; then
1143 if . "$cachefile" 2>/dev/null; then
1144 if [ "$check" = "$_check" ]; then
1151 _busy=$(progress "BUSY" "$CBUSY")
1152 _ok=$(progress "DONE")
1153 _started=$(progress "WORK")
1154 _fail=$(progress "FAIL" "$CFAIL")
1155 _died=$(progress "DIED" "$CFAIL")
1157 # we don't use heredoc, as ksh attempts to create tempfile then
1158 (> "$cachefile" ) 2>/dev/null || return
1159 echo "_busy='$_busy';" >> "$cachefile"
1160 echo "_ok='$_ok';" >> "$cachefile"
1161 echo "_started='$_started';" >> "$cachefile"
1162 echo "_fail='$_fail';" >> "$cachefile"
1163 echo "_died='$_died';" >> "$cachefile"
1164 echo "_check='$check';" >> "$cachefile"
1168 if [ -z "$GETTEXT" ]; then
1169 if [ -x /bin/gettext -o -x /usr/bin/gettext ]; then
1176 if [ -z "$TPUT" ]; then
1177 if [ -d /usr/share/terminfo ] && [ -x /usr/bin/tput -o -x /bin/tput ]; then
1179 # check if we are on proper terminal
1180 tput longname >/dev/null 2>&1 || TPUT=no
1188 # True when upstart-event-based boot should be used
1189 is_yes "$USE_UPSTART" && return 0
1190 is_no "$USE_UPSTART" && return 1
1191 if [ ! -x /sbin/initctl ] ; then
1195 local cmdline=$(cat /proc/cmdline 2>/dev/null)
1196 if strstr "$cmdline" "pld.no-upstart" ; then
1206 # emit upstart signal
1207 # only when 'upstart' boot is enabled
1208 use_upstart || return 0
1209 /sbin/initctl emit "$@"
1213 # Return 0 if the given service is an upstart task.
1214 grep -q '^task' "/etc/init/$1.conf"
1216 is_upstart_running() {
1217 # Return 0 if the given service is running via upstart
1218 initctl status "$1" 2>/dev/null | grep -q running
1222 is_upstart_running "${service}" && return 0
1223 msg_starting "${service}"
1224 if errors=$(/sbin/initctl start ${service} 2>&1) ; then
1235 if ! is_upstart_running "${service}" && ! is_upstart_task "${service}" ; then
1238 msg_stopping "${service}"
1239 if errors=$(/sbin/initctl stop ${service}) ; then
1250 if ! is_upstart_running "${service}" && ! is_upstart_task "${service}" ; then
1253 msg_reloading "${service}"
1254 if errors=$(/sbin/initctl reload ${service}) ; then
1264 # get service status
1265 # should be compliant with
1266 # http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
1269 if is_upstart_task "${service}" ; then
1270 # we probably should have a way to handle task status
1273 if ! status=$(/sbin/initctl status "${service}") ; then
1274 # program or service status is not known
1277 if strstr "$status" "running" ; then
1278 # program is running or service is OK
1282 # program is not running
1286 # TODO: other statuses
1289 _upstart_controlled () {
1290 # If the service is to be handled by upstart
1291 # execute the start/stop/etc. commands the upstart way
1292 if ! use_upstart ; then
1299 local name=$(basename "$script")
1300 if [ ! -f /etc/init/${name}.conf ] ; then
1304 local extra_commands
1305 local has_configtest
1306 if [ "$1" = "--except" ] ; then
1309 for cmd in $commands ; do
1310 if [ "$command" = "$cmd" ] ; then
1314 start|stop|status|reload|restart|try-restart|force-reload)
1318 extra_commands="|$cmd"
1321 extra_commands="|$cmd"
1325 elif [ -n "$*" ] ; then
1329 # is there a better way
1330 for cmd in $commands ; do
1331 if [ "$command" = "$cmd" ] ; then
1336 if [ $found = 0 ] ; then
1337 # let the script handle it
1351 upstart_status $name
1355 if is_yes "$has_configtest" ; then
1356 "$script" configtest || exit 1
1363 if ! is_upstart_running "$name" ; then
1366 if is_yes "$has_configtest" ; then
1367 "$script" configtest || exit 1
1374 if is_yes "$has_configtest" ; then
1375 "$script" configtest || exit 1
1377 if is_upstart_task "$name" ; then
1378 nls "$command not implemented for $name"
1381 upstart_reload "$name"
1386 if is_yes "$has_configtest" ; then
1387 "$script" configtest || exit 1
1389 if is_upstart_task "$name" ; then
1390 upstart_stop "$name"
1391 upstart_start "$name"
1394 upstart_reload "$name"
1399 msg_usage "$0 {start|stop|restart|reload|force-reload|status$extra_commands}"
1403 return 1 # should not happen
1407 # somewhere at the begining of init script:
1408 # upstart_controlled
1409 # - to pass implement all upstart commands via initctl
1410 # start, stop, status, restart, reload and force_reload
1412 # upstart_controlled command...
1413 # - to pass handle only specific commands the upstart way
1414 # and leave the rest to the script
1416 alias upstart_controlled='_upstart_controlled $0 "$@"'
1422 # * Local variables:
1424 # * indent-tabs-mode: notnil