|
| 1 | +#!/bin/sh |
| 2 | +### BEGIN INIT INFO |
| 3 | +# Provides: opal-prd |
| 4 | +# Required-Start: $local_fs $network $remote_fs $syslog |
| 5 | +# Required-Stop: $local_fs $network $remote_fs $syslog |
| 6 | +# Default-Start: 2 3 4 5 |
| 7 | +# Default-Stop: 0 1 6 |
| 8 | +# Short-Description: Run the skiboot opal-prd daemon |
| 9 | +# Description: The opal-prd daemon provides hardware error recovery |
| 10 | +# support for OPAL-based POWER systems. |
| 11 | +### END INIT INFO |
| 12 | + |
| 13 | +# Author: Jeremy Kerr <[email protected]> |
| 14 | + |
| 15 | +# Do NOT "set -e" |
| 16 | + |
| 17 | +# PATH should only include /usr/* if it runs after the mountnfs.sh script |
| 18 | +PATH=/sbin:/usr/sbin:/bin:/usr/bin |
| 19 | +DESC="opal-prd" |
| 20 | +NAME=opal-prd |
| 21 | +DAEMON=/usr/sbin/opal-prd |
| 22 | +DAEMON_ARGS="" |
| 23 | +PIDFILE=/var/run/$NAME.pid |
| 24 | +SCRIPTNAME=/etc/init.d/$NAME |
| 25 | + |
| 26 | +# Exit if the package is not installed |
| 27 | +[ -x "$DAEMON" ] || exit 0 |
| 28 | + |
| 29 | +# Read configuration variable file if it is present |
| 30 | +[ -r /etc/default/$NAME ] && . /etc/default/$NAME |
| 31 | + |
| 32 | +# Load the VERBOSE setting and other rcS variables |
| 33 | +. /lib/init/vars.sh |
| 34 | + |
| 35 | +# Define LSB log_* functions. |
| 36 | +# Depend on lsb-base (>= 3.2-14) to ensure that this file is present |
| 37 | +# and status_of_proc is working. |
| 38 | +. /lib/lsb/init-functions |
| 39 | + |
| 40 | +if [ "$PNOR_DEVICE" ] |
| 41 | +then |
| 42 | + PNOR_OPTS="--pnor $PNOR_DEVICE" |
| 43 | +fi |
| 44 | + |
| 45 | +[ "$OPAL_PRD_ENABLED" = "true" -o "$OPAL_PRD_ENABLED" = "1" ] || exit 0 |
| 46 | + |
| 47 | +# |
| 48 | +# Function that starts the daemon/service |
| 49 | +# |
| 50 | +do_start() |
| 51 | +{ |
| 52 | + # Return |
| 53 | + # 0 if daemon has been started |
| 54 | + # 1 if daemon was already running |
| 55 | + # 2 if daemon could not be started |
| 56 | + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ |
| 57 | + || return 1 |
| 58 | + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ |
| 59 | + $PNOR_OPTS $DAEMON_ARGS \ |
| 60 | + || return 2 |
| 61 | +} |
| 62 | + |
| 63 | +# |
| 64 | +# Function that stops the daemon/service |
| 65 | +# |
| 66 | +do_stop() |
| 67 | +{ |
| 68 | + # Return |
| 69 | + # 0 if daemon has been stopped |
| 70 | + # 1 if daemon was already stopped |
| 71 | + # 2 if daemon could not be stopped |
| 72 | + # other if a failure occurred |
| 73 | + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME |
| 74 | + RETVAL="$?" |
| 75 | + [ "$RETVAL" = 2 ] && return 2 |
| 76 | + # Many daemons don't delete their pidfiles when they exit. |
| 77 | + rm -f $PIDFILE |
| 78 | + return "$RETVAL" |
| 79 | +} |
| 80 | + |
| 81 | +case "$1" in |
| 82 | + start) |
| 83 | + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
| 84 | + do_start |
| 85 | + case "$?" in |
| 86 | + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 87 | + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 88 | + esac |
| 89 | + ;; |
| 90 | + stop) |
| 91 | + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
| 92 | + do_stop |
| 93 | + case "$?" in |
| 94 | + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
| 95 | + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
| 96 | + esac |
| 97 | + ;; |
| 98 | + status) |
| 99 | + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? |
| 100 | + ;; |
| 101 | + #reload|force-reload) |
| 102 | + # |
| 103 | + # If do_reload() is not implemented then leave this commented out |
| 104 | + # and leave 'force-reload' as an alias for 'restart'. |
| 105 | + # |
| 106 | + #log_daemon_msg "Reloading $DESC" "$NAME" |
| 107 | + #do_reload |
| 108 | + #log_end_msg $? |
| 109 | + #;; |
| 110 | + restart|force-reload) |
| 111 | + log_daemon_msg "Restarting $DESC" "$NAME" |
| 112 | + do_stop |
| 113 | + case "$?" in |
| 114 | + 0|1) |
| 115 | + do_start |
| 116 | + case "$?" in |
| 117 | + 0) log_end_msg 0 ;; |
| 118 | + 1) log_end_msg 1 ;; # Old process is still running |
| 119 | + *) log_end_msg 1 ;; # Failed to start |
| 120 | + esac |
| 121 | + ;; |
| 122 | + *) |
| 123 | + # Failed to stop |
| 124 | + log_end_msg 1 |
| 125 | + ;; |
| 126 | + esac |
| 127 | + ;; |
| 128 | + *) |
| 129 | + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 |
| 130 | + exit 3 |
| 131 | + ;; |
| 132 | +esac |
| 133 | + |
| 134 | +: |
0 commit comments