|
| 1 | +#! /bin/sh |
| 2 | +### BEGIN INIT INFO |
| 3 | +# Provides: heka |
| 4 | +# Required-Start: $remote_fs $syslog |
| 5 | +# Required-Stop: $remote_fs $syslog |
| 6 | +# Default-Start: 2 3 4 5 |
| 7 | +# Default-Stop: 0 1 6 |
| 8 | +# Short-Description: heka - data collector and processor daemon |
| 9 | +# Description: heka - data collector and processor daemon |
| 10 | +### END INIT INFO |
| 11 | + |
| 12 | +PATH=/sbin:/usr/sbin:/bin:/usr/bin |
| 13 | +DESC=hekad |
| 14 | +NAME=hekad |
| 15 | +DAEMON=/usr/bin/$NAME |
| 16 | +DAEMON_USER=heka |
| 17 | +DAEMON_ARGS="-config=/etc/heka/conf.d/" |
| 18 | +PIDFILE=/var/run/$NAME.pid |
| 19 | +LOGFILE=/var/log/$NAME.log |
| 20 | +SCRIPTNAME=/etc/init.d/heka |
| 21 | + |
| 22 | +# Exit if the package is not installed |
| 23 | +[ -x "$DAEMON" ] || exit 0 |
| 24 | + |
| 25 | +# Read configuration variable file if it is present |
| 26 | +[ -r /etc/default/$NAME ] && . /etc/default/$NAME |
| 27 | + |
| 28 | +# Load the VERBOSE setting and other rcS variables |
| 29 | +. /lib/init/vars.sh |
| 30 | + |
| 31 | +# Define LSB log_* functions. |
| 32 | +# Depend on lsb-base (>= 3.2-14) to ensure that this file is present |
| 33 | +# and status_of_proc is working. |
| 34 | +. /lib/lsb/init-functions |
| 35 | + |
| 36 | +# |
| 37 | +# Function that starts the daemon/service |
| 38 | +# |
| 39 | +do_start() |
| 40 | +{ |
| 41 | + # Return |
| 42 | + # 0 if daemon has been started |
| 43 | + # 1 if daemon was already running |
| 44 | + # 2 if daemon could not be started |
| 45 | + pid=$(pidofproc -p $PIDFILE "$NAME") |
| 46 | + if [ -n "$pid" ] ; then |
| 47 | + log_daemon_msg "$desc is already running (PID `cat ${PIDFILE}`)" |
| 48 | + return 1 |
| 49 | + fi |
| 50 | + start-stop-daemon --start --quiet --chuid $DAEMON_USER --make-pidfile --background --pidfile $PIDFILE \ |
| 51 | + --no-close --exec $DAEMON -- $DAEMON_ARGS >> $LOGFILE 2>&1 \ |
| 52 | + || return 2 |
| 53 | + # Add code here, if necessary, that waits for the process to be ready |
| 54 | + # to handle requests from services started subsequently which depend |
| 55 | + # on this one. As a last resort, sleep for some time. |
| 56 | +} |
| 57 | + |
| 58 | +# |
| 59 | +# Function that stops the daemon/service |
| 60 | +# |
| 61 | +do_stop() |
| 62 | +{ |
| 63 | + # Return |
| 64 | + # 0 if daemon has been stopped |
| 65 | + # 1 if daemon was already stopped |
| 66 | + # 2 if daemon could not be stopped |
| 67 | + # other if a failure occurred |
| 68 | + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME |
| 69 | + RETVAL="$?" |
| 70 | + [ "$RETVAL" = 2 ] && return 2 |
| 71 | + # Wait for children to finish too if this is a daemon that forks |
| 72 | + # and if the daemon is only ever run from this initscript. |
| 73 | + # If the above conditions are not satisfied then add some other code |
| 74 | + # that waits for the process to drop all resources that could be |
| 75 | + # needed by services started subsequently. A last resort is to |
| 76 | + # sleep for some time. |
| 77 | + start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON |
| 78 | + [ "$?" = 2 ] && return 2 |
| 79 | + # Many daemons don't delete their pidfiles when they exit. |
| 80 | + rm -f $PIDFILE |
| 81 | + return "$RETVAL" |
| 82 | +} |
| 83 | + |
| 84 | +# |
| 85 | +# Function that sends a SIGHUP to the daemon/service |
| 86 | +# |
| 87 | +do_reload() { |
| 88 | + # |
| 89 | + # If the daemon can reload its configuration without |
| 90 | + # restarting (for example, when it is sent a SIGHUP), |
| 91 | + # then implement that here. |
| 92 | + # |
| 93 | + start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME |
| 94 | + return 0 |
| 95 | +} |
| 96 | + |
| 97 | +case "$1" in |
| 98 | + start) |
| 99 | + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
| 100 | + do_start |
| 101 | + case "$?" in |
| 102 | + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 103 | + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 104 | + esac |
| 105 | + ;; |
| 106 | + stop) |
| 107 | + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
| 108 | + do_stop |
| 109 | + case "$?" in |
| 110 | + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 111 | + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 112 | + esac |
| 113 | + ;; |
| 114 | + status) |
| 115 | + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? |
| 116 | + ;; |
| 117 | + reload|force-reload) |
| 118 | + log_daemon_msg "Reloading $DESC" "$NAME" |
| 119 | + do_reload |
| 120 | + log_end_msg $? |
| 121 | + ;; |
| 122 | + restart|force-reload) |
| 123 | + # |
| 124 | + # If the "reload" option is implemented then remove the |
| 125 | + # 'force-reload' alias |
| 126 | + # |
| 127 | + log_daemon_msg "Restarting $DESC" "$NAME" |
| 128 | + do_stop |
| 129 | + case "$?" in |
| 130 | + 0|1) |
| 131 | + do_start |
| 132 | + case "$?" in |
| 133 | + 0) log_end_msg 0 ;; |
| 134 | + 1) log_end_msg 1 ;; # Old process is still running |
| 135 | + *) log_end_msg 1 ;; # Failed to start |
| 136 | + esac |
| 137 | + ;; |
| 138 | + *) |
| 139 | + # Failed to stop |
| 140 | + log_end_msg 1 |
| 141 | + ;; |
| 142 | + esac |
| 143 | + ;; |
| 144 | + *) |
| 145 | + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 |
| 146 | + exit 3 |
| 147 | + ;; |
| 148 | +esac |
| 149 | + |
| 150 | +: |
0 commit comments