]> git.pld-linux.org Git - projects/rc-scripts.git/blob - lib/functions
5956a97ca32d90723421649548ae5c8bd858a8b3
[projects/rc-scripts.git] / lib / functions
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.
4 #
5 #
6 # Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
7 # Hacked by:    Greg Galloway and Marc Ewing
8 # Modified for PLD Linux by:
9 #               Marek Obuchowicz <elephant@pld-linux.org>
10 #               Arkadiusz Miśkiewicz <misiek@pld-linux.org>
11 #               Michał Kochanowicz <mkochano@pld-linux.org>
12 #               Łukasz Pawelczyk <havner@pld-linux.org>
13
14 # First set up a default search path.
15 export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
16
17 # Set defaults
18 if [ -z "$COLUMNS" -o -z "$LINES" ]; then
19         _setterm() {
20                 set -- $(stty size 2>/dev/null)
21                 LINES=${LINES:-$1}
22                 COLUMNS=${COLUMNS:-$2}
23         }
24         _setterm
25         unset _setterm
26 fi
27 [ -z "$LINES" ] || [ "$LINES" -le 0 ] && LINES=40
28 [ -z "$COLUMNS" ] || [ "$COLUMNS" -le 0 ] && COLUMNS=80
29 export LINES COLUMNS
30 INIT_COL=$((COLUMNS - 13))
31
32 # Set colors
33 RED=1
34 GREEN=2
35 YELLOW=3
36 BLUE=4
37 MAGENTA=5
38 CYAN=6
39 WHITE=7
40 NORMAL=15
41 # Bold definition (second parameter to termput setaf)
42 BOLD=1
43 NOBOLD=0
44 # Default colors
45 CBRACKETS="$CYAN"       # brackets [ ] color
46 CDONE="$GREEN"          # DONE and WORK color
47 CBUSY="$MAGENTA"        # BUSY color
48 CFAIL="$RED"            # FAIL and DIED color
49 CPOWEREDBY="$CYAN"      # "Powered by" color
50 CPLD="$GREEN"           # "PLD Linux Distribution" color
51 CI="$RED"               # Capital I color (press I to enter interactive startup)
52 CRESMAN="$GREEN"        # "Resource Manager" color
53 CHARS=""                # Characters displayed on the beginning of show line
54 CCHARS="$NORMAL"        # Color of these characters (look at /etc/sysconfig/init-colors.gentoo example)
55
56 # save from env, set by /sbin/service
57 env_upstart=$USE_UPSTART
58
59 # Source configuration if available - may override default values
60 [ -r /etc/sysconfig/init-colors ] && . /etc/sysconfig/init-colors
61 [ -r /etc/sysconfig/system ] && . /etc/sysconfig/system
62 [ -r /etc/sysconfig/bootsplash ] && . /etc/sysconfig/bootsplash
63
64 # if initscript is invoked via bash, enable RedHat/Fedora compatibility
65 # RC_FEDORA is "set" if enabled and "unset" when not, but it's "value" is always empty
66 # this is useful for inline constructs
67 if [ "${BASH_VERSION+set}" = "set" ]; then
68         RC_LOGGING=yes
69         FASTRC=no
70         RC_FEDORA=
71 else
72         unset RC_FEDORA || :
73 fi
74
75 [ "$env_upstart" ] && USE_UPSTART=$env_upstart
76
77 if [ -z "$VSERVER" -o "$VSERVER" = "detect" ]; then
78         {
79                 while read _f _ctx; do
80                         [ "$_f" = "VxID:" -o "$_f" = "s_context:" ] && break
81                 done </proc/self/status
82         } 2>/dev/null
83         if [ -z "$_ctx" -o "$_ctx" = "0" ]; then
84                 VSERVER=no
85         else
86                 VSERVER=yes
87         fi
88         unset _f _ctx
89 fi
90
91 # VSERVER_ISOLATION_NET = isolation only inside of vserver guests
92 if [ -z "$VSERVER_ISOLATION_NET" -o "$VSERVER_ISOLATION_NET" = "detect" ]; then
93         VSERVER_ISOLATION_NET=no
94         if [ "$VSERVER" = "yes" ]; then
95                 if [ -f /proc/self/nsproxy ]; then
96                         {
97                                 while read _t _data; do
98                                         [ "$_t" = "net:" ] && break
99                                 done < /proc/self/nsproxy
100                         } 2> /dev/null
101                 else
102                         # assume old kernel mode
103                         VSERVER_ISOLATION_NET=yes
104                 fi
105                 if [ "${_data##*\(}" = "I)" ]; then
106                         VSERVER_ISOLATION_NET=yes
107                 fi
108                 unset _f _data
109         fi
110 fi
111
112 # we need to know in functions if we were called from a terminal
113 if [ -z "$ISATTY" ]; then
114         [ -t ] && ISATTY=yes || ISATTY=no
115         export ISATTY
116 fi
117
118 is_yes() {
119         # Test syntax
120         if [ $# = 0 ]; then
121                 msg_usage " is_yes {value}"
122                 return 2
123         fi
124
125         # Check value
126         case "$1" in
127         yes|Yes|YES|true|True|TRUE|on|On|ON|Y|y|1)
128                 # true returns zero
129                 return 0
130                 ;;
131         *)
132                 # false returns one
133                 return 1
134                 ;;
135         esac
136 }
137
138 is_no() {
139         # Test syntax
140         if [ $# = 0 ]; then
141                 msg_usage " is_no {value}"
142                 return 2
143         fi
144
145         case "$1" in
146         no|No|NO|false|False|FALSE|off|Off|OFF|N|n|0)
147                 # true returns zero
148                 return 0
149                 ;;
150         *)
151                 # false returns one
152                 return 1
153                 ;;
154         esac
155 }
156
157 # checks if file is empty
158 # empty lines and lines beginning with hash are ignored
159 is_empty_file() {
160         [ -s "$1" ] || return 0
161         grep -vqE "^(#|[[:blank:]]*$)" "$1" && return 1 || return 0
162 }
163
164 # returns OK if $1 contains $2
165 strstr() {
166         local a=$2
167         [ "${1#*$a*}" = "$1" ] && return 1
168         return 0
169 }
170
171 # Apply sysctl settings, including files in /etc/sysctl.d
172 apply_sysctl() {
173         if [ -x /lib/systemd/systemd-sysctl ]; then
174                 /lib/systemd/systemd-sysctl
175                 return
176         fi
177
178         local file
179         for file in /usr/lib/sysctl.d/*.conf; do
180                 [ -f /run/sysctl.d/${file##*/} ] && continue
181                 [ -f /etc/sysctl.d/${file##*/} ] && continue
182                 test -f "$file" && sysctl -q -e -p "$file"
183         done
184         for file in /run/sysctl.d/*.conf; do
185                 [ -f /etc/sysctl.d/${file##*/} ] && continue
186                 test -f "$file" && sysctl -q -e -p "$file"
187         done
188         for file in /etc/sysctl.d/*.conf; do
189                 test -f "$file" && sysctl -q -e -p "$file"
190         done
191         sysctl -q -e -p /etc/sysctl.conf
192 }
193
194 if is_yes "$FASTRC" || is_yes "$IN_SHUTDOWN"; then
195         RC_LOGGING=no
196 fi
197
198 if is_no "$RC_LOGGING"; then
199         initlog() {
200                 RESULT=0
201                 while [ "$1" != "${1##-}" ]; do
202                         case $1 in
203                         -c)
204                                 shift
205                                 $1
206                                 RESULT=$?
207                                 break
208                                 ;;
209                         *)
210                                 shift
211                                 ;;
212                         esac
213                 done
214                 return $RESULT
215         }
216 fi
217
218 kernelver() {
219         local _x _y _z v v1 old_IFS ver
220         {
221                 read _x _y v _z
222                 old_IFS=$IFS
223                 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
224                 IFS='_-'
225                 set -- $v
226                 v1=${1}
227                 IFS='.'
228                 set -- $v1
229                 IFS=$old_IFS
230
231                 ver=${3}
232                 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
233                 ver="$2$ver"
234                 while [ ${#ver} -lt 6 ]; do ver="0$ver"; done
235                 ver="$1$ver"
236                 while [ ${#ver} -lt 9 ]; do ver="0$ver"; done
237                 echo $ver
238         } < /proc/version
239 }
240
241 kernelverser() {
242         local _x _y _z v v1 old_IFS ver
243         {
244                 read _x _y v _z
245                 old_IFS=$IFS
246                 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
247                 IFS='_-'
248                 set -- $v
249                 v1=${1}
250                 IFS='.'
251                 set -- $v1
252                 IFS=$old_IFS
253                 ver=$2
254                 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
255                 ver="$1$ver"
256                 while [ ${#ver} -lt 6 ]; do ver="0$ver"; done
257                 echo $ver
258         } </proc/version
259 }
260
261 kernelvermser() {
262         local _x _y _z v v1 old_IFS ver
263         {
264                 read _x _y v _z
265                 old_IFS=$IFS
266                 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
267                 IFS='_-'
268                 set -- $v
269                 v1=${1}
270                 IFS='.'
271                 set -- $v1
272                 IFS=$old_IFS
273                 ver="$1"
274                 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
275                 echo $ver
276         } </proc/version
277 }
278
279 # Colors workaround
280 termput() {
281         is_yes "$ISATTY" || return
282
283         if is_yes "$FASTRC" || is_no "$TPUT"; then
284                 case "$1" in
285                 hpa)
286                         echo -ne "\033[$(($2+1))G"
287                         ;;
288                 cuu*)
289                         echo -ne "\033[${2}A"
290                         ;;
291                 el)
292                         echo -ne "\033[0K"
293                         ;;
294                 setaf)
295                         local ISBOLD
296                         if [ -n "$3" ]; then
297                                 ISBOLD="$3"
298                         else
299                                 ISBOLD="$NOBOLD";
300                         fi
301                         is_yes "$COLOR_INIT" && echo -ne "\033[${ISBOLD};3${2}m"
302                         ;;
303                 op)
304                         termput setaf $NORMAL
305                         ;;
306                 esac
307         else
308                 case "$1" in
309                 hpa | cuu* | el)
310                         tput "$@"
311                         ;;
312                 setaf)
313                         if [ "$3" = "1" ]; then tput bold; else tput sgr0; fi
314                         is_yes "$COLOR_INIT" && tput setaf "$2"
315                         ;;
316                 op)
317                         termput setaf $NORMAL
318                         ;;
319                 esac
320         fi
321 }
322
323 if [ ! -x /bin/printf ]; then
324         # printf equivalent
325         # FIXME: buggy when single or double quotes in message!
326         printf() {
327                 local text m
328                 text="$1"
329                 shift
330                 if [ $# -gt 0 ]; then
331                         m="$1"
332                         shift
333                         while [ $# -gt 0 ]; do
334                                 m="$m\",\"$1"
335                                 shift
336                         done
337                 fi
338                 awk "BEGIN {printf \"$text\", \"$m\"; }"
339         }
340 fi
341
342 # National language support function
343 nls() {
344         local msg_echo nls_domain text message
345         msg_echo='\n'
346         nls_domain="$NLS_DOMAIN"
347         while [ "$1" != "${1##-}" ]; do
348                 case "$1" in
349                 --nls-domain)
350                         shift
351                         nls_domain="$1"
352                         shift
353                         ;;
354                 -n)
355                         msg_echo=''
356                         shift
357                         ;;
358                 esac
359         done
360         message="$1"
361         shift
362
363         # empty message, so we return --misiek
364         if [ -z "$message" ]; then
365                 echo -en "$msg_echo"
366                 return
367         fi
368
369         if is_yes "$GETTEXT"; then
370                 message=$(TEXTDOMAINDIR="/etc/sysconfig/locale" gettext -e --domain="${nls_domain:-rc-scripts}" "$message")
371         fi
372
373         printf "$message" "$@"
374         echo -en "$msg_echo"
375 }
376
377 rc_splash() {
378         local action="$1"
379
380         if ! is_no "$BOOT_SPLASH" && ! is_yes "$VSERVER"; then
381                 [ -x /bin/splash ] && /bin/splash "$action"
382         fi
383
384         : $((progress++))
385 }
386
387 msg_network_down() {
388         nls "ERROR: Networking is down. %s can't be run." "$1" >&2
389 }
390
391 msg_starting() {
392         show "Starting %s service" "$1"
393 }
394
395 msg_already_running() {
396         nls "%s service is already running." "$1"
397 }
398
399 msg_stopping() {
400         show "Stopping %s service" "$1"
401 }
402
403 msg_not_running() {
404         nls "%s service is not running." "$1"
405 }
406
407 msg_reloading() {
408         show "Reloading %s service" "$1"
409 }
410
411 msg_usage() {
412         nls "Usage: %s" "$*"
413 }
414
415 # Some functions to handle PLD Linux-style messages
416 show() {
417         local text len time
418
419         if is_yes "$RC_UPTIME"; then
420                 time=$(awk '{printf("[%8.2f] ", $1)}' /proc/uptime)
421         fi
422
423         if is_no "$FASTRC" && is_yes "$GETTEXT"; then
424                 text=$time$(nls -n "$@")
425         else
426                 text=$time$(printf "$@")
427         fi
428         len=${#text}
429         while [ $((len++)) -lt $INIT_COL ]; do
430                 text="$text."
431         done
432         if [ -n "$CHARS" ]; then
433                 termput setaf $CCHARS
434                 echo -n "$CHARS"
435                 termput op
436         fi
437         echo -n "$text"
438 }
439
440 deltext() {
441         termput hpa $INIT_COL
442 }
443
444 # Displays message in square brackests ("[ DONE ]"). Takes two arguments.
445 # First is the text to display, second is color number to use (argument to
446 # tput setaf). If second argument is not given, default (2, green) will be
447 # used).
448 progress() {
449         local COLOR
450         if [ -n "$2" ]; then
451                 COLOR="$2"
452         else
453                 COLOR="$CDONE"
454         fi
455         deltext
456         echo -n "$(termput setaf $CBRACKETS)[$(termput setaf $COLOR) $(nls --nls-domain rc-scripts "$1") $(termput setaf $CBRACKETS)]$(termput op)"
457 }
458
459 busy() {
460         echo -n "$_busy"
461 }
462
463 ok() {
464         echo -ne "$_ok${RC_FEDORA+\\r}${RC_FEDORA-\\n}"
465 }
466
467 started() {
468         echo "$_started"
469 }
470
471 fail() {
472         echo -ne "$_fail${RC_FEDORA+\\r}${RC_FEDORA-\\n}"
473         return 1
474 }
475
476 died() {
477         echo "$_died"
478         return 1
479 }
480
481 # Check if $pid (could be plural) are running
482 checkpid() {
483         while [ "$1" ]; do
484                 [ -d "/proc/$1" ] && return 0
485                 shift
486         done
487         return 1
488 }
489
490 # - outside chroot get only those processes, which are outside chroot.
491 # - inside chroot get only those processes, which are inside chroot.
492 # - don't filter out pids which do not have corresponding running processes (process died etc)
493 # (note: some processes like named are chrooted but run outside chroot)
494 # - do nothing inside vserver
495 filter_chroot() {
496         # filter by pid namespace if such dir exists for current process
497         # we do filter in containers as stacked containers are possible with LXC
498         if [ -d /proc/$$/ns ]; then
499                 local pids
500                 pids=$(filter_ns "$@") && set -- "$pids"
501         fi
502
503         if is_yes "$VSERVER"; then
504                 echo $@
505                 return
506         fi
507
508         if [ $# -lt 1 -o ! -d /proc/1 ]; then
509                 echo $@
510                 return
511         fi
512
513         local root_dir good_pids="" good_add_pid
514         for root_pid in $@; do
515                 root_dir=$(resolvesymlink /proc/${root_pid}/root)
516                 if [ -n "$root_dir" ]; then
517                         good_add_pid=1
518                         if [ -n "${SYSTEM_CHROOTS}" ]; then
519                                 for r_dir in ${SYSTEM_CHROOTS}; do
520                                         echo "$root_dir" | grep -q "^${r_dir}" && good_add_pid=0
521                                 done
522                         fi
523                         [ "$good_add_pid" -eq 1 ] && good_pids="$good_pids $root_pid"
524                 elif [ ! -d "/proc/$root_pid" ]; then
525                         good_pids="$good_pids $root_pid"
526                 fi
527         done
528         echo $good_pids
529 }
530
531 # similar to filter_chroot, but filter based on /proc/PID/ns/pid value
532 filter_ns() {
533         local cur_ns=$(resolvesymlink /proc/$$/ns/pid)
534         [ "$cur_ns" ] || return 1
535
536         local pid ns pids=""
537         # add pids if it matches current pid namespace
538         # we should add pids what do not exist (dead processes),
539         # but not add pids whose namespace does not match
540         # (processes belonging to different NS do exist in /proc)
541         for pid in "$@"; do
542                 if [ ! -d /proc/$pid ]; then
543                         pids="$pids $pid"
544                         continue
545                 fi
546                 ns=$(resolvesymlink /proc/$pid/ns/pid)
547                 if [ "$ns" = "$cur_ns" ]; then
548                         pids="$pids $pid"
549                 fi
550         done
551         echo $pids
552         return 0
553 }
554
555 # Usage:
556 # run_cmd Message command_to_run
557 # run_cmd -a Message command_to_run
558 # run_cmd --user "username" "Message" command_to_run
559 run_cmd() {
560         local force_err=0 exit_code=0 errors user
561         while [ $# -gt 0 ]; do
562                 case "$1" in
563                 -a)
564                         force_err=1
565                         ;;
566                 --user)
567                         shift
568                         user=$1
569                         ;;
570                 *)
571                         break
572                 esac
573                 shift
574         done
575
576         local message=$1; shift
577         show "$message"; busy
578
579         if errors=$(
580                 cd /
581                 export HOME=/tmp TMPDIR=/tmp
582                 if is_no "$RC_LOGGING"; then
583                         ${user:+setuidgid -s $user} "$@" 2>&1
584                 else
585                         ${user:+setuidgid -s $user} initlog -c "$*" 2>&1
586                 fi
587                 ); then
588                 ok
589                 log_success "$1 $message"
590         else
591                 fail
592                 log_failed "$1 $message"
593                 exit_code=1
594         fi
595         [ -n "$errors" ] && [ $exit_code -eq 1 -o $force_err -eq 1 ] && echo "$errors"
596         return $exit_code
597 }
598
599 _daemon_set_ulimits() {
600         local opt val ksh=${KSH_VERSION:+1}
601         set -- ${SERVICE_LIMITS:-$DEFAULT_SERVICE_LIMITS}
602         while [ $# -gt 0 ]; do
603                 opt=$1
604                 val=$2
605                 if [ "$ksh" ]; then
606                         case "$opt" in
607                         -Hu)
608                                 opt=-Hp
609                         ;;
610                         -Su)
611                                 opt=-Sp
612                         ;;
613                         -u)
614                                 opt=-p
615                         ;;
616                         esac
617                 fi
618                 ulimit $opt $val
619                 shift 2
620         done
621 }
622
623 # A function to start a program (now it's useful on read-only filesystem too)
624 daemon() {
625         local errors="" prog="" end="" waitname="" waittime=""
626         local exit_code=0
627         local nice=$SERVICE_RUN_NICE_LEVEL
628         local fork user closefds redirfds pidfile makepid chdir=/
629
630         # NOTE: if you wonder how the shellish (by syntax) $prog works in ssd mode,
631         # then the answer is: it totally ignores $prog and uses "$@" itself.
632
633         while [ $# -gt 0 ]; do
634                 case $1 in
635                 '')
636                 msg_usage " daemon [--check] [--user user] [--fork] [--chdir directory] [--closefds] [--redirfds] [--waitforname procname] [--waitfortime seconds] [--pidfile file] [--makepid] [+/-nicelevel] {program} <program args>"
637                         return 2
638                         ;;
639                 --check)
640                         # for compatibility with redhat/mandrake
641                         nls "warning: --check option is ignored!"
642                         shift
643                         ;;
644                 --user)
645                         shift
646                         user=$1
647                         ;;
648                 --fork)
649                         fork=1
650                         end='&'
651                         ;;
652                 --chdir)
653                         shift
654                         chdir=$1
655                         ;;
656                 --closefds)
657                         closefds=1
658                         ;;
659                 --redirfds)
660                         redirfds=1
661                         ;;
662                 --waitforname)
663                         shift
664                         waitname="$1"
665                         ;;
666                 --waitfortime)
667                         shift
668                         waittime="$1"
669                         ;;
670                 --pidfile=?*)
671                         pidfile="${1#--pidfile=}"
672                         case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
673                         ;;
674                 --pidfile)
675                         shift
676                         pidfile="$1"
677                         case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
678                         ;;
679                 --makepid)
680                         makepid=1
681                         ;;
682                 -*|+*)
683                         nice=$1
684                         shift
685                         break
686                         ;;
687                 *)
688                         break
689                         ;;
690                 esac
691                 shift
692         done
693         if [ -n "$user" -a "$user" != "root" ]; then
694                 prog="/bin/su $user -s /bin/sh -c \""
695         fi
696         if [ "$fork" = "1" ]; then
697                 prog="/usr/bin/setsid ${prog:-sh -c \"}"
698         fi
699         # If command to execute ends with quotation mark, add remaining
700         # arguments and close quotation.
701         if [ "$prog" != "${prog%\"}" ]; then
702                 prog="$prog $*$end\""
703         else
704                 prog="$prog $*$end"
705         fi
706
707         _daemon_set_ulimits
708
709         [ -z "$DEFAULT_SERVICE_UMASK" ] && DEFAULT_SERVICE_UMASK=022
710         [ -z "$DEFAULT_SERVICE_RUN_NICE_LEVEL" ] && DEFAULT_SERVICE_RUN_NICE_LEVEL=0
711
712         # And start it up.
713         busy
714         cd $chdir
715         [ -n "$SERVICE_CPUSET" ] && is_yes "$CPUSETS" && echo $$ > "/dev/cpuset/${SERVICE_CPUSET}/tasks"
716         if errors=$(
717                 umask ${SERVICE_UMASK:-$DEFAULT_SERVICE_UMASK};
718                 export USER=root HOME=/tmp TMPDIR=/tmp
719
720                 nice=${nice:-$DEFAULT_SERVICE_RUN_NICE_LEVEL}
721                 nice=${nice:-0}
722
723                 # make nice level absolute, not to be dependant of nice level of shell where service started
724                 nice=$(($nice - $(nice)))
725
726                 if [ "$closefds" = 1 ]; then
727                         exec 1>&-
728                         exec 2>&-
729                         exec 0<&-
730                 elif [ "$redirfds" = 1 ]; then
731                         exec 1>/dev/null
732                         exec 2>/dev/null
733                         exec 0</dev/null
734                 else
735                         exec 2>&1
736                         exec 0</dev/null
737                 fi
738
739                 if is_no "$RC_LOGGING"; then
740                         prog=$1; shift
741                         if [ ! -x $prog ]; then
742                                 logger -t rc-scripts -p daemon.debug "daemon: Searching PATH for $prog, consider using full path in initscript"
743                                 local a o=$IFS
744                                 IFS=:
745                                 for a in $PATH; do
746                                         if [ -x $a/$prog ]; then
747                                                 prog=$a/$prog
748                                                 break
749                                         fi
750                                 done
751                                 IFS=$o
752                         fi
753                         set -- "$prog" "$@"
754
755                         # use setsid to detach from terminal,
756                         # needs pidfile or ssd would check setsid program instead of real program
757                         if [ "$pidfile" ]; then
758                                 set -- /usr/bin/setsid "$@"
759                         fi
760
761                         prog=$1; shift
762                         /sbin/start-stop-daemon -q --start \
763                                 --nicelevel $nice \
764                                 ${pidfile:+--pidfile $pidfile} \
765                                 ${makepid:+--make-pidfile} \
766                                 ${user:+--chuid $user} \
767                                 ${chdir:+--chdir "$chdir"} \
768                                 ${fork:+--background} \
769                                 ${waitname:+--name $waitname} \
770                                 ${SERVICE_DROPCAPS:+--dropcap $SERVICE_DROPCAPS} \
771                                 --exec "$prog" \
772                                 -- "$@"
773                 else
774                         nice -n $nice initlog -c "$prog" 2>&1 </dev/null
775                 fi
776                 ); then
777
778                 if [ -n "$waitname" -a -n "$waittime" ]; then
779                         # Save basename.
780                         base=${waitname##*/}
781                         # Find pid.
782                         pid=$(pidofproc "$waitname" "$pidfile")
783                         [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
784                         i=0
785                         while [ "$i" -lt "$waittime" ]; do
786                                 i=$((i + 1))
787                                 checkpid $pid && sleep 1 || break
788                         done
789                 fi
790                 log_success "$1 startup"
791                 ok
792         else
793                 exit_code=1
794                 fail
795                 log_failed "$1 startup"
796                 [ -n "$errors" ] && echo >&2 "$errors"
797         fi
798         return $exit_code
799 }
800
801 # A function to stop a program.
802 killproc() {
803         local notset killlevel base pid pidfile result delay=3 try
804         # Test syntax.
805         if [ $# = 0 ]; then
806                 msg_usage " killproc [--pidfile|-p PIDFILE] [-d DELAY] {program} [-SIGNAME]"
807                 return 2
808         fi
809
810         while [ "$1" != "${1##-}" ]; do
811                 case $1 in
812                 -d)
813                         delay="$2"
814                         shift 2
815                         ;;
816                 --pidfile|-p)
817                         pidfile="$2"
818                         case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
819                         shift 2
820                         ;;
821                 --waitforname)
822                         waitname="$2"
823                         shift 2
824                         ;;
825                 --waitfortime)
826                         waittime="$2"
827                         shift 2
828                         ;;
829                 esac
830         done
831
832         busy
833
834         local notset=0
835         # check for second arg to be kill level
836         if [ -n "$2" ]; then
837                 killlevel=$2
838         else
839                 notset=1
840         fi
841
842         # experimental start-stop-daemon based killing.
843         # works only with pidfile
844         if is_no "$RC_LOGGING" && [ "$pidfile" ]; then
845                 local sig=${killlevel:--TERM} retry
846                 # retry only if signal is not specified,
847                 # as otherwise impossible to send HUP if process pid stays in pidfile.
848                 if [ "${killlevel+set}" = "set" ]; then
849                         # if we send HUP it's ok if process does not die
850                         retry="--oknodo"
851                 else
852                         retry="--retry ${sig#-}/10/${sig#-}/60/KILL/10"
853                 fi
854                 /sbin/start-stop-daemon -q --stop \
855                         $retry \
856                         -s ${sig#-} \
857                         ${pidfile:+--pidfile $pidfile}
858                 result=$?
859                 if [ "$result" -eq 0 ]; then
860                         ok
861                 else
862                         fail
863                 fi
864                 return $result
865         fi
866
867
868         # Save basename.
869         base=${1##*/}
870
871         # Find pid.
872         pid=$(pidofproc "$1" "$pidfile")
873         [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
874
875         # Kill it.
876         if [ -n "$pid" -a "$pid" != "$$" ] && checkpid $pid 2>&1; then
877                 if [ "$notset" = "1" ]; then
878                         if checkpid $pid 2>&1; then
879                                 # TERM first, then KILL if not dead
880                                 kill -TERM $pid
881                                 usleep 50000
882
883                                 try=0
884                                 while [ $try -lt $delay ]; do
885                                         checkpid $pid || break
886                                         sleep 1
887                                         try=$((try+1))
888                                 done
889                                 if checkpid $pid; then
890                                         # XXX: SIGKILL is sent already on 4th second!
891                                         # HARMFUL for example to mysqld (which is already workarounded)
892                                         kill -KILL $pid
893                                         usleep 50000
894                                 fi
895                         fi
896                         checkpid $pid
897                         result=$?
898                         if [ "$result" -eq 0 ]; then
899                                 fail
900                                 log_failed "$1 shutdown"
901                         else
902                                 ok
903                                 log_success "$1 shutdown"
904                         fi
905                         result=$(( ! $result ))
906                 else
907                         # use specified level only
908                         if checkpid $pid > /dev/null 2>&1; then
909                                 kill $killlevel $pid
910                                 result=$?
911                                 if [ "$result" -eq 0 ]; then
912                                         ok
913                                         log_success "$1 got $killlevel"
914                                 else
915                                         result=7
916                                         fail
917                                         log_failed "$1 didn't get $killlevel"
918                                 fi
919                         else
920                                 result=7
921                                 died
922                                 log_failed "$1 shutdown"
923                         fi
924                 fi
925         else
926                 died
927                 log_failed "$1 shutdown"
928                 result=7
929         fi
930
931         if [ -n "$waitname" -a -n "$waittime" ]; then
932                 # Save basename.
933                 base=${waitname##*/}
934                 # Find pid.
935                 pid=$(pidofproc "$waitname" "$pidfile")
936                 [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
937                 i=0
938                 while [ "$i" -lt "$waittime" ]; do
939                         i=$(( i + 1 ))
940                         checkpid $pid && sleep 1 || break
941                 done
942         fi
943
944         # Remove pid file if any.
945         if [ "$notset" = "1" ]; then
946                 rm -f /var/run/${base}.pid
947         fi
948
949         return $result
950 }
951
952 # A function to find the pid of a program.
953 pidofproc() {
954         local pid pidfile base=${1##*/}
955         pidfile="$base.pid"
956         [ -n "$2" ] && pidfile="$2"
957
958         # Test syntax.
959         if [ $# = 0 ]; then
960                 msg_usage " pidofproc {program}"
961                 return 2
962         fi
963
964         # First try pidfile or "/var/run/*.pid"
965         case "$pidfile" in
966                 /*)pidfile="${pidfile}";;
967                 *) pidfile="/var/run/$pidfile";;
968         esac
969         if [ -f "${pidfile}" ]; then
970                 local p pid=""
971                 for p in $(< "${pidfile}"); do
972                         [ -z "$(echo "$p" | awk '{gsub(/[0-9]/,"");print;}')" ] && pid="$pid $p"
973                 done
974         fi
975
976         # Next try "pidof"
977         [ -z "$pid" ] && pidof -o $$ -o $PPID -o %PPID -x "$1"
978         pid=$(filter_chroot $pid)
979         echo $pid
980 }
981
982 # status [--pidfile PIDFILE] {subsys} [{daemon}]"
983 status() {
984         local pid subsys daemon cpuset_msg pidfile
985         if [ "$1" = "--pidfile" -o "$1" = "-p" ]; then
986                 pidfile=$2
987                 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
988                 shift 2
989         fi
990
991         subsys=$1
992         daemon=${2:-$subsys}
993
994         # Test syntax.
995         if [ $# = 0 ]; then
996                 msg_usage " status [--pidfile PIDFILE] {subsys} [{daemon}]"
997                 return 2
998         fi
999
1000         # if pidfile specified, pid must be there
1001         if [ "$pidfile" ]; then
1002                 [ -f "$pidfile" ] && read pid < $pidfile
1003                 # filter_chroot does not filter out dead pids, so this extra check, see t/status-pidfile.sh
1004                 if [ ! -d "/proc/$pid" ]; then
1005                         pid=
1006                 fi
1007         else
1008                 pid=$(pidof -o $$ -o $PPID -o %PPID -x $daemon)
1009         fi
1010         pid=$(filter_chroot $pid)
1011
1012         if [ "$pid" ]; then
1013                 cpuset_msg="..."
1014                 if [ -n "$SERVICE_CPUSET" ] && is_yes "$CPUSETS"; then
1015                         if grep -q "$pid" "/dev/cpuset/${SERVICE_CPUSET}/tasks"; then
1016                                 cpuset_msg=$(nls " in cpuset %s..." "$SERVICE_CPUSET")
1017                         else
1018                                 cpuset_msg=$(nls " outside of configured cpuset %s..." "$SERVICE_CPUSET")
1019                         fi
1020                 fi
1021                 nls "%s (pid %s) is running%s" "$daemon" "$pid" "$cpuset_msg"
1022                 return 0
1023         fi
1024
1025         # Next try "/var/run/*.pid" files; if pidfile is not set
1026         local base=${daemon##*/}
1027         if [ -z "$pidfile" -a -f /var/run/${base}.pid ]; then
1028                 read pid < /var/run/${base}.pid
1029                 pid=$(filter_chroot $pid)
1030                 if [ "$pid" ]; then
1031                         nls "%s dead but pid file (%s) exists" "$subsys" /var/run/${base}.pid
1032                         return 1
1033                 fi
1034         fi
1035
1036         # See if /var/lock/subsys/$subsys exists
1037         if [ -f /var/lock/subsys/$subsys ]; then
1038                 nls "daemon %s dead but subsys (%s) locked" "$daemon" "$subsys"
1039                 return 2
1040         fi
1041         nls "%s is stopped" "$subsys"
1042         return 3
1043 }
1044
1045 # Confirm whether we really want to run this service
1046 confirm() {
1047         local answer
1048         nls -n "Start service %s (Y)es/(N)o/(C)ontinue? [Y] " "$1"
1049         read answer
1050         case $answer in
1051         y|Y|t|T|j|J|"")
1052                 return 0
1053                 ;;
1054         c|C|k|K|w|W)
1055                 return 2
1056                 ;;
1057         n|N)
1058                 return 1
1059                 ;;
1060         *)
1061                 confirm $1
1062                 return $?
1063                 ;;
1064         esac
1065 }
1066
1067 # module is needed (ie. is requested, is available and isn't loaded already)
1068 is_module() {
1069         # module name without .o at end
1070         if ! lsmod | grep -q "$1"; then
1071                 if ls -1R /lib/modules/$(uname -r)/ 2> /dev/null | grep -q "^${1}.\(\|k\)o\(\|.gz\)"; then
1072                         # true
1073                         return 0
1074                 fi
1075         fi
1076         # false
1077         return 1
1078 }
1079
1080 _modprobe() {
1081         local parsed single die args foo result
1082         parsed=no
1083         while is_no "$parsed"; do
1084                 case "$1" in
1085                 "single")
1086                         single=yes
1087                         shift
1088                         ;;
1089                 "die")
1090                         die=yes
1091                         shift
1092                         ;;
1093                 -*)
1094                         args="$args $1"
1095                         shift
1096                         ;;
1097                 *)
1098                         parsed=yes
1099                         ;;
1100                 esac
1101         done
1102         if is_yes "${single}"; then
1103                 foo="$@"
1104                 show "Loading %s kernel module(s)" "$foo"
1105                 busy
1106         fi
1107         if [ -x /sbin/modprobe ]; then
1108                 /sbin/modprobe -s $args "$@"
1109                 result=$?
1110         else
1111                 deltext; fail
1112                 result=1
1113         fi
1114         if is_yes "${single}"; then
1115                 deltext
1116                 if [ $result = "0" ]; then
1117                         is_yes "$single" && ok
1118                 else
1119                         fail
1120                         if is_yes "$die"; then
1121                                 nls "Could not load %s kernel module(s)" "$@"
1122                                 exit 1
1123                         fi
1124                 fi
1125         fi
1126 }
1127
1128 if is_no "$RC_LOGGING"; then
1129         log_success() {
1130                 :
1131         }
1132
1133         log_failed() {
1134                 :
1135         }
1136 else
1137         log_success() {
1138                 initlog -n $0 -s "$1 $2" -e 1
1139         }
1140
1141         log_failed() {
1142                 initlog -n $0 -s "$1 $2" -e 2
1143         }
1144 fi
1145
1146 # Check if any flavor of portmapper is running
1147 check_portmapper() {
1148         if [ -x /usr/sbin/rpcinfo ]; then
1149                 if /usr/sbin/rpcinfo -p localhost >/dev/null 2>/dev/null; then
1150                         return 0
1151                 else
1152                         return 1
1153                 fi
1154         elif [ -z "$(pidof portmap)" -a -z "$(pidof rpcbind)" ]; then
1155                 return 1
1156         fi
1157         return 0
1158 }
1159
1160 # is_fsmounted fstype mntpoint
1161 # Check if filesystem fstype is mounted on mntpoint
1162 is_fsmounted() {
1163         local fstype=$1
1164         local mntpoint=$2
1165
1166         [ -n "$fstype" -a -n "$mntpoint" ] || return 1
1167
1168         if [ -r /proc/mounts ]; then
1169                 grep -qE "[[:blank:]]$mntpoint[[:blank:]]+$fstype[[:blank:]]" /proc/mounts
1170                 return $?
1171         else
1172                 if [ "$(stat -L -f -c %T $mntpoint 2>/dev/null)" = "$fstype" ]; then
1173                         return 0
1174                 else
1175                         return 1
1176                 fi
1177         fi
1178 }
1179
1180 # __umount_loop awk_program fstab_file first_msg retry_msg umount_args
1181 # awk_program should process fstab_file and return a list of fstab-encoded
1182 # paths; it doesn't have to handle comments in fstab_file.
1183 __umount_loop() {
1184         local remaining sig=
1185         local retry=3 count
1186
1187         remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1188         while [ -n "$remaining" -a "$retry" -gt 0 ]; do
1189                 if [ "$retry" -eq 3 ]; then
1190                         run_cmd "$3" fstab-decode umount $5 $remaining
1191                 else
1192                         run_cmd "$4" fstab-decode umount $5 $remaining
1193                 fi
1194                 count=4
1195                 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1196                 while [ "$count" -gt 0 ]; do
1197                         [ -z "$remaining" ] && break
1198                         count=$(($count-1))
1199                         usleep 500000
1200                         remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1201                 done
1202                 [ -z "$remaining" ] && break
1203                 fstab-decode /bin/fuser -k -m $sig $remaining >/dev/null
1204                 sleep 3
1205                 retry=$(($retry -1))
1206                 sig=-9
1207         done
1208 }
1209
1210 # Similar to __umount loop above, specialized for loopback devices
1211 __umount_loopback_loop() {
1212         local remaining devremaining sig=
1213         local retry=3
1214
1215         remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
1216         devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
1217         while [ -n "$remaining" -a "$retry" -gt 0 ]; do
1218                 if [ "$retry" -eq 3 ]; then
1219                         run_cmd "Unmounting loopback filesystems: " \
1220                                 fstab-decode umount $remaining
1221                 else
1222                         run_cmd "Unmounting loopback filesystems (retry):" \
1223                                 fstab-decode umount $remaining
1224                 fi
1225                 for dev in $devremaining ; do
1226                         losetup $dev > /dev/null 2>&1 && \
1227                                 run_cmd "Detaching loopback device $dev: " \
1228                                 losetup -d $dev
1229                 done
1230                 remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
1231                 devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
1232                 [ -z "$remaining" ] && break
1233                 fstab-decode /bin/fuser -k -m $sig $remaining >/dev/null
1234                 sleep 3
1235                 retry=$(($retry -1))
1236                 sig=-9
1237         done
1238 }
1239
1240 rc_cache_init() {
1241         # If we have cachefile, use it.
1242         # If we don't, create memory variables and try to save silently,
1243         local cachefile='/var/cache/rc-scripts/msg.cache'
1244
1245         local term
1246         if is_yes "$ISATTY"; then
1247                 term=$TERM
1248         else
1249                 term=dumb
1250         fi
1251
1252         # We create $check variable which is used to invalidate the cache.
1253         # The $check contains user locale and terminal.
1254         local check="$term.$LC_MESSAGES.$INIT_COL"
1255
1256         if [ -f "$cachefile" -a "$cachefile" -nt /etc/sysconfig/system -a "$cachefile" -nt /etc/sysconfig/init-colors ]; then
1257                 if . "$cachefile" 2>/dev/null; then
1258                         if [ "$check" = "$_check" ]; then
1259                                 return
1260                         fi
1261                 fi
1262         fi
1263
1264         # primitive caching
1265         _busy=$(progress "BUSY" "$CBUSY")
1266         _ok=$(progress "DONE")
1267         _started=$(progress "WORK")
1268         _fail=$(progress "FAIL" "$CFAIL")
1269         _died=$(progress "DIED" "$CFAIL")
1270
1271         # we don't use heredoc, as ksh attempts to create tempfile then
1272         (> "$cachefile" ) 2>/dev/null || return
1273         echo "_busy='$_busy';" >> "$cachefile"
1274         echo "_ok='$_ok';" >> "$cachefile"
1275         echo "_started='$_started';" >> "$cachefile"
1276         echo "_fail='$_fail';" >> "$cachefile"
1277         echo "_died='$_died';" >> "$cachefile"
1278         echo "_check='$check';" >> "$cachefile"
1279 }
1280
1281 rc_gettext_init() {
1282         if [ -z "$GETTEXT" ]; then
1283                 if [ -x /bin/gettext -o -x /usr/bin/gettext ]; then
1284                         GETTEXT=yes
1285                 else
1286                         GETTEXT=no
1287                 fi
1288         fi
1289
1290         if [ -z "$TPUT" ]; then
1291                 if [ -d /usr/share/terminfo ] && [ -x /usr/bin/tput -o -x /bin/tput ]; then
1292                         TPUT=yes
1293                         # check if we are on proper terminal
1294                         tput longname >/dev/null 2>&1 || TPUT=no
1295                 else
1296                         TPUT=no
1297                 fi
1298         fi
1299 }
1300
1301 use_upstart () {
1302         # True when upstart-event-based boot should be used
1303         is_yes "$USE_UPSTART" && return 0
1304         is_no "$USE_UPSTART" && return 1
1305         if [ ! -x /sbin/initctl ] ; then
1306                 USE_UPSTART="no"
1307                 return 1
1308         fi
1309         local cmdline=$(cat /proc/cmdline 2>/dev/null)
1310         if strstr "$cmdline" "pld.no-upstart" ; then
1311                 USE_UPSTART="no"
1312                 return 1
1313         else
1314                 USE_UPSTART="yes"
1315                 return 0
1316         fi
1317 }
1318
1319 emit () {
1320         # emit upstart signal
1321         # only when 'upstart' boot is enabled
1322         use_upstart || return 0
1323         /sbin/initctl emit "$@"
1324 }
1325
1326 is_upstart_task() {
1327         # Return 0 if the given service is an upstart task.
1328         grep -q '^task' "/etc/init/$1.conf"
1329 }
1330 is_upstart_running() {
1331         # Return 0 if the given service is running via upstart
1332         initctl status "$1" 2>/dev/null | grep -q running
1333 }
1334 upstart_start() {
1335         local service=$1
1336         if is_upstart_running "${service}"; then
1337                 msg_already_running "$service"
1338                 return 0
1339         fi
1340
1341         msg_starting "${service}"
1342         if errors=$(/sbin/initctl start ${service} 2>&1) ; then
1343                 ok
1344                 return 0
1345         else
1346                 fail
1347                 echo "$errors" >&2
1348                 return 1
1349         fi
1350 }
1351 upstart_stop() {
1352         local service=$1
1353         if ! is_upstart_running "${service}"; then
1354                 msg_not_running "$name"
1355                 return 0
1356         fi
1357         msg_stopping "${service}"
1358         if errors=$(/sbin/initctl stop ${service}) ; then
1359                 ok
1360                 return 0
1361         else
1362                 fail
1363                 echo "$errors" >&2
1364                 return 1
1365         fi
1366 }
1367 upstart_reload() {
1368         local service=$1
1369         if ! is_upstart_running "${service}" && ! is_upstart_task "${service}" ; then
1370                 return 0
1371         fi
1372         msg_reloading "${service}"
1373         if errors=$(/sbin/initctl reload ${service}) ; then
1374                 ok
1375                 return 0
1376         else
1377                 fail
1378                 echo "$errors" >&2
1379                 return 1
1380         fi
1381 }
1382 upstart_status() {
1383         # get service status
1384         # should be compliant with
1385         # http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
1386         local service=$1
1387         local status
1388         if is_upstart_task "${service}" ; then
1389                 # we probably should have a way to handle task status
1390                 return 0
1391         fi
1392         if ! status=$(/sbin/initctl status "${service}") ; then
1393                 # program or service status is not known
1394                 return 4
1395         fi
1396         if strstr "$status" "running" ; then
1397                 # program is running or service is OK
1398                 echo "$status"
1399                 return 0
1400         else
1401                 # program is not running
1402                 echo "$status"
1403                 return 3
1404         fi
1405         # TODO: other statuses
1406 }
1407
1408 _upstart_controlled() {
1409         # If the service is to be handled by upstart
1410         # execute the start/stop/etc. commands the upstart way
1411         if ! use_upstart; then
1412                 return 0
1413         fi
1414         local script=$1
1415         shift
1416         local command=$1
1417         [ $# -gt 0 ] && shift
1418         local name=$(basename "$script")
1419         if [ ! -f /etc/init/${name}.conf ] ; then
1420                 return 0
1421         fi
1422         local commands
1423         local extra_commands
1424         local has_configtest
1425         if [ "$1" = "--except" ] ; then
1426                 shift
1427                 commands="$*"
1428                 for cmd in $commands ; do
1429                         if [ "$command" = "$cmd" ] ; then
1430                                 return 0
1431                         fi
1432                         case "$cmd" in
1433                                 start|stop|status|reload|restart|try-restart|force-reload)
1434                                         ;;
1435                                 configtest)
1436                                         has_configtest=yes
1437                                         extra_commands="|$cmd"
1438                                         ;;
1439                                 *)
1440                                         extra_commands="|$cmd"
1441                                         ;;
1442                         esac
1443                 done
1444         elif [ -n "$*" ] ; then
1445                 commands="$*"
1446                 local cmd
1447                 local found=0
1448                 # is there a better way
1449                 for cmd in $commands ; do
1450                         if [ "$command" = "$cmd" ] ; then
1451                                 found=1
1452                                 break;
1453                         fi
1454                 done
1455                 if [ $found = 0 ] ; then
1456                         # let the script handle it
1457                         return 0
1458                 fi
1459         fi
1460         case "$command" in
1461                 start)
1462                         upstart_start $name
1463                         exit $?
1464                         ;;
1465                 stop)
1466                         upstart_stop $name
1467                         exit $?
1468                         ;;
1469                 status)
1470                         upstart_status $name
1471                         exit $?
1472                         ;;
1473                 restart)
1474                         if is_yes "$has_configtest" ; then
1475                                 "$script" configtest || exit 1
1476                         fi
1477                         upstart_stop $name
1478                         upstart_start $name
1479                         exit $?
1480                         ;;
1481                 try-restart)
1482                         if ! is_upstart_running "$name" ; then
1483                                 exit 0
1484                         fi
1485                         if is_yes "$has_configtest" ; then
1486                                 "$script" configtest || exit 1
1487                         fi
1488                         upstart_stop $name
1489                         upstart_start $name
1490                         exit $?
1491                         ;;
1492                 reload)
1493                         if is_yes "$has_configtest" ; then
1494                                 "$script" configtest || exit 1
1495                         fi
1496                         if is_upstart_task "$name" ; then
1497                                 nls "$command not implemented for $name"
1498                                 exit 3
1499                         else
1500                                 upstart_reload "$name"
1501                                 exit $?
1502                         fi
1503                         ;;
1504                 force-reload)
1505                         if is_yes "$has_configtest" ; then
1506                                 "$script" configtest || exit 1
1507                         fi
1508                         if is_upstart_task "$name" ; then
1509                                 upstart_stop "$name"
1510                                 upstart_start "$name"
1511                                 exit $?
1512                         else
1513                                 upstart_reload "$name"
1514                                 exit $?
1515                         fi
1516                         ;;
1517                 *)
1518                         msg_usage "$0 {start|stop|restart|reload|force-reload|status$extra_commands}"
1519                         exit 3
1520                         ;;
1521         esac
1522         return 1 # should not happen
1523 }
1524
1525 # Usage:
1526 #       somewhere at the begining of init script:
1527 #     upstart_controlled
1528 #               - to pass implement all upstart commands via initctl
1529 #                 start, stop, status, restart, reload and force_reload
1530 #                 are implemented
1531 #     upstart_controlled command...
1532 #               - to pass handle only specific commands the upstart way
1533 #                 and leave the rest to the script
1534 #
1535 alias upstart_controlled='_upstart_controlled $0 "$@"'
1536
1537 rc_gettext_init
1538 rc_cache_init
1539
1540 #/*
1541 # * Local variables:
1542 # * mode: sh
1543 # * indent-tabs-mode: notnil
1544 # * End:
1545 # *
1546 # */
This page took 0.229734 seconds and 3 git commands to generate.