aboutsummaryrefslogtreecommitdiffstats
path: root/rc.d/init.d/functions
diff options
context:
space:
mode:
Diffstat (limited to 'rc.d/init.d/functions')
-rwxr-xr-xrc.d/init.d/functions120
1 files changed, 115 insertions, 5 deletions
diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions
index a651d699..e69f27f4 100755
--- a/rc.d/init.d/functions
+++ b/rc.d/init.d/functions
@@ -1,4 +1,5 @@
-#! /bin/sh
+
+#!/bin/sh
#
# functions This file contains functions to be used by most or all
# shell scripts in the /etc/init.d directory.
@@ -12,6 +13,15 @@
# First set up a default search path.
export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
+# Read in our configuration
+if [ -f /etc/sysconfig/init ]; then
+ . /etc/sysconfig/init
+else
+ BOOTUP=color
+fi
+
+
+
# A function to start a program.
daemon() {
# Test syntax.
@@ -30,15 +40,17 @@ daemon() {
pid=`pidofproc $base`
[ -n "$pid" ] && ps h $pid >/dev/null 2>&1 && return
- # echo basename of the program.
- echo -n "$base "
-
# make sure it doesn't core dump anywhere; while this could mask
# problems with the daemon, it also closes some security problems
ulimit -c 0
+
+ #
+ if [ $BOOTUP != "color" ]; then
+ echo -n $base
+ fi
# And start it up.
- nice -n $nicelevel "$@"
+ nice -n $nicelevel initlog -q -c "$*" && success -n "$base startup" || failure -n "$base startup"
}
# A function to stop a program.
@@ -150,3 +162,101 @@ status() {
echo "$1 is stopped"
return 3
}
+
+echo_success() {
+ echo $* "[ OK ]"
+ return 0
+}
+
+echo_failure() {
+ echo $* "[FAILED]"
+ return 0
+}
+
+success() {
+ if [ "$1" = "-n" ]; then
+ ECHOARGS="-n"
+ shift
+ else
+ ECHOARGS=""
+ fi
+ if [ -z "$IN_INITLOG" ]; then
+ initlog -n $0 -s "$1" -e 1
+ else
+ echo "-n $0 -s \"$1\" -e 1" >&21
+ fi
+ [ "$BOOTUP" = "color" ] && echo_success $ECHOARGS
+ return 0
+}
+
+failure() {
+ if [ "$1" = "-n" ]; then
+ ECHOARGS="-n"
+ shift
+ else
+ ECHOARGS=""
+ fi
+ if [ -z "$IN_INITLOG" ]; then
+ initlog -n $0 -s "$1" -e 2
+ else
+ echo "-n $0 -s \"$1\" -e 2" >&21
+ fi
+ [ "$BOOTUP" = "color" ] && echo_failure $ECHOARGS
+ return 0
+}
+
+action() {
+ if [ "$1" = "-n" ]; then
+ ECHOARGS="-n"
+ shift
+ else
+ ECHOARGS=""
+ fi
+ STRING=$1
+ echo $ECHOARGS "$STRING "
+ shift
+ if [ -z "$IN_INITLOG" ]; then
+ initlog -q -c "$*" && success "$STRING" || failure "$STRING"
+ else
+ # This sucks.
+ output=`$*`
+ rc=$?
+ if [ -n "$output" ]; then
+ cmdname=`basename $1`
+ initlogcmds=`echo $output | sed -e "s/^/ -n $cmdname -s \"/" | sed -e "s/$/\"/"`
+ echo "$initlogcmds" >&21
+ fi
+
+ if [ $rc ]; then
+ success "$STRING"
+ else
+ echo $output
+ failure "$STRING"
+ fi
+ fi
+ return 0
+}
+
+# Confirm whether we really want to run this service
+confirm() {
+ echo -n "Start service $1 (Y)es/(N)o/(C)ontinue? [Y] "
+ read answer
+ case $answer in
+ y|Y|"")
+ return 0
+ ;;
+ c|C)
+ return 2
+ ;;
+ n|N)
+ return 1
+ ;;
+ *)
+ confirm $1
+ return $?
+ ;;
+ esac
+}
+
+
+