Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame^] | 1 | #! /bin/sh |
| 2 | # |
| 3 | # This is an init script for openembedded |
| 4 | # Copy it to /etc/init.d/rsyslog and type |
| 5 | # > update-rc.d rsyslog defaults 5 |
| 6 | # |
| 7 | |
| 8 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
| 9 | NAME=rsyslog |
| 10 | RSYSLOGD=rsyslogd |
| 11 | RSYSLOGD_BIN=/usr/sbin/rsyslogd |
| 12 | RSYSLOGD_OPTIONS="" |
| 13 | RSYSLOGD_PIDFILE=/var/run/rsyslogd.pid |
| 14 | SCRIPTNAME=/etc/init.d/$NAME |
| 15 | # Exit if the package is not installed |
| 16 | [ -x "$RSYSLOGD_BIN" ] || exit 0 |
| 17 | # Read configuration variable file if it is present |
| 18 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME |
| 19 | # |
| 20 | # Function that starts the daemon/service |
| 21 | # |
| 22 | do_start() |
| 23 | { |
| 24 | DAEMON=$1 |
| 25 | DAEMON_ARGS=$2 |
| 26 | PIDFILE=$3 |
| 27 | # Return |
| 28 | # 0 if daemon has been started |
| 29 | # 1 if daemon could not be started |
| 30 | # if daemon had already been started, start-stop-daemon will return 1 |
| 31 | # so add -o/--oknodo(if nothing is done, exit 0) |
| 32 | start-stop-daemon -S --quiet --pidfile $PIDFILE --exec $DAEMON \ |
| 33 | --oknodo -- $DAEMON_ARGS || return 1 |
| 34 | } |
| 35 | # |
| 36 | # Function that stops the daemon/service |
| 37 | # |
| 38 | do_stop() |
| 39 | { |
| 40 | NAME=$1 |
| 41 | PIDFILE=$2 |
| 42 | # Return |
| 43 | # 0 if daemon has been stopped |
| 44 | # 1 if daemon was already stopped |
| 45 | # 2 if daemon could not be stopped |
| 46 | # other if a failure occurred |
| 47 | # QUIT/TERM/INT should work here, but they don't ????? |
| 48 | start-stop-daemon -K --quiet --signal KILL --pidfile $PIDFILE --name $NAME |
| 49 | RETVAL="$?" |
| 50 | rm -f $PIDFILE |
| 51 | return "$RETVAL" |
| 52 | } |
| 53 | # |
| 54 | # Function that sends a SIGHUP to the daemon/service |
| 55 | # |
| 56 | do_reload() { |
| 57 | NAME=$1 |
| 58 | PIDFILE=$2 |
| 59 | start-stop-daemon -K --signal HUP --quiet --pidfile $PIDFILE --name $NAME |
| 60 | return 0 |
| 61 | } |
| 62 | |
| 63 | do_status() { |
| 64 | NAME=$1 |
| 65 | PIDFILE=$2 |
| 66 | # -t: test only but not stop |
| 67 | start-stop-daemon -K -t --quiet --pidfile $PIDFILE --name $NAME |
| 68 | # exit with status 0 if process is found |
| 69 | if [ "$?" = "0" ]; then |
| 70 | return 0 |
| 71 | else |
| 72 | return 1 |
| 73 | fi |
| 74 | } |
| 75 | |
| 76 | case "$1" in |
| 77 | start) |
| 78 | echo -n "starting $RSYSLOGD ... " |
| 79 | do_start "$RSYSLOGD_BIN" "$RSYSLOGD_OPTIONS" "$RSYSLOGD_PIDFILE" |
| 80 | case "$?" in |
| 81 | 0) echo "done" ;; |
| 82 | 1) echo "failed" ;; |
| 83 | esac |
| 84 | ;; |
| 85 | stop) |
| 86 | echo -n "stopping $RSYSLOGD ... " |
| 87 | do_stop "$RSYSLOGD" "$RSYSLOGD_PIDFILE" |
| 88 | case "$?" in |
| 89 | 0|1) echo "done" ;; |
| 90 | 2) echo "failed" ;; |
| 91 | esac |
| 92 | ;; |
| 93 | reload|force-reload) |
| 94 | echo -n "reloading $RSYSLOGD ... " |
| 95 | do_reload "$RSYSLOGD" "$RSYSLOGD_PIDFILE" |
| 96 | echo "done" |
| 97 | ;; |
| 98 | restart) |
| 99 | $0 stop |
| 100 | $0 start |
| 101 | ;; |
| 102 | status) |
| 103 | echo -n "status $RSYSLOGD ... " |
| 104 | do_status "$RSYSLOGD" "$RSYSLOGD_PIDFILE" |
| 105 | if [ "$?" = "0" ]; then |
| 106 | echo "running" |
| 107 | exit 0 |
| 108 | else |
| 109 | echo "stopped" |
| 110 | exit 1 |
| 111 | fi |
| 112 | ;; |
| 113 | *) |
| 114 | echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2 |
| 115 | exit 3 |
| 116 | ;; |
| 117 | esac |
| 118 | exit 0 |