[kgb-bot] Convert the initscript to RHEL.
averi
averi at fedoraproject.org
Thu May 16 21:10:15 UTC 2013
commit c5c8bd9c712eac65a61c062b4a9ab978c12412d6
Author: Andrea Veri <av at gnome.org>
Date: Thu May 16 23:05:36 2013 +0200
Convert the initscript to RHEL.
kgb-bot.init | 141 ++++++++++++++++------------------------------------------
1 files changed, 39 insertions(+), 102 deletions(-)
---
diff --git a/kgb-bot.init b/kgb-bot.init
index 0c755e2..d55c1d5 100644
--- a/kgb-bot.init
+++ b/kgb-bot.init
@@ -10,8 +10,6 @@
# notifying an IRC channel when a commit occures.
### END INIT INFO
-# Author: Damyan Ivanov <dmn at debian.org>
-
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
@@ -23,19 +21,15 @@ DAEMON_ARGS="--config /etc/kgb-bot/kgb.conf"
PIDFILE=/var/run/kgb-bot/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
+# source function library
+. /etc/init.d/functions
+
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
RUN_AS='Fedora-kgb'
# Read configuration variable file if it is present
-[ -r /etc/default/$NAME ] && . /etc/default/$NAME
-
-# Load the VERBOSE setting and other rcS variables
-. /lib/init/vars.sh
-
-# Define LSB log_* functions.
-# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
-. /lib/lsb/init-functions
+[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
#
# create /var/run/kgb-bot and ensure right permissions
@@ -64,125 +58,68 @@ init_log_file() {
fi
}
+RETVAL=0
#
# Function that starts the daemon/service
#
-do_start()
+start()
{
- # Return
- # 0 if daemon has been started
- # 1 if daemon was already running
- # 2 if daemon could not be started
init_run_dir || return 2
init_log_file || return 2
- start-stop-daemon --start --quiet --chuid $RUN_AS --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
- || return 1
- start-stop-daemon --start --quiet --chuid $RUN_AS --pidfile $PIDFILE --exec $DAEMON -- \
- $DAEMON_ARGS \
- || return 2
- # Add code here, if necessary, that waits for the process to be ready
- # to handle requests from services started subsequently which depend
- # on this one. As a last resort, sleep for some time.
-}
+ echo -n $"Starting KGB-Bot: "
+ $DAEMON $DAEMON_ARGS
+ echo
-#
-# Function that stops the daemon/service
-#
-do_stop()
-{
- # Return
- # 0 if daemon has been stopped
- # 1 if daemon was already stopped
- # 2 if daemon could not be stopped
- # other if a failure occurred
- start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
- RETVAL="$?"
- [ "$RETVAL" = 2 ] && return 2
- # Wait for children to finish too if this is a daemon that forks
- # and if the daemon is only ever run from this initscript.
- # If the above conditions are not satisfied then add some other code
- # that waits for the process to drop all resources that could be
- # needed by services started subsequently. A last resort is to
- # sleep for some time.
- start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
- [ "$?" = 2 ] && return 2
- # Many daemons don't delete their pidfiles when they exit.
- rm -f $PIDFILE
- return "$RETVAL"
+ RETVAL=$?
+ [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$NAME
}
-#
-# Function that sends a SIGHUP to the daemon/service
-#
-do_reload() {
- init_log_file || return 2
- start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
- return 0
+stop()
+{
+ echo -n $"Stopping KGB-Bot: "
+ killproc -p $PIDFILE $NAME
+ RETVAL=$?
+ echo
+ if [ $RETVAL -eq 0 ]; then
+ rm -f /var/lock/subsys/$NAME
+ rm -f $pidfile
+ fi
}
-#
-# Function that sends a SIGQUIT to the daemon/service
-#
-do_soft_restart() {
- init_log_file || return 2
- start-stop-daemon --stop --signal 3 --quiet --pidfile $PIDFILE --name $NAME
- return 0
+reload()
+{
+ echo -n $"Reloading $NAME: "
+ killproc -p $PIDFILE $DAEMON -HUP
+ RETVAL=$?
+ echo
}
case "$1" in
start)
- [ "$BOT_ENABLED" != "1" ] && echo $DAEMON disabled in /etc/default/$NAME>&2 && exit 0
-
- [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
- do_start
- case "$?" in
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
- esac
+ [ "$BOT_ENABLED" != "1" ] && echo $DAEMON disabled in /etc/sysconfig/$NAME>&2 && exit 0
+
+ [ "$VERBOSE" != no ] && echo "Starting $DESC" "$NAME"
+ start
;;
stop)
- [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
- do_stop
- case "$?" in
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
- esac
+ [ "$VERBOSE" != no ] && echo "Stopping $DESC" "$NAME"
+ stop
;;
status)
status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
;;
- soft-restart)
- log_daemon_msg "Reloading $DESC" "$NAME"
- do_soft_restart
- log_end_msg $?
- ;;
- reload|force-reload)
- log_daemon_msg "Reloading $DESC" "$NAME"
- do_reload
- log_end_msg $?
+ reload)
+ echo "Reloading $DESC" "$NAME"
+ reload
;;
restart)
log_daemon_msg "Restarting $DESC" "$NAME"
- do_stop
- case "$?" in
- 0|1)
- do_start
- case "$?" in
- 0) log_end_msg 0 ;;
- 1) log_end_msg 1 ;; # Old process is still running
- *) log_end_msg 1 ;; # Failed to start
- esac
- ;;
- *)
- # Failed to stop
- log_end_msg 1
- ;;
- esac
+ stop
+ start
;;
*)
- echo "Usage: $SCRIPTNAME {start|stop|restart|force-restart|reload|force-reload}" >&2
- #echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
+ echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
More information about the scm-commits
mailing list