2 # Copyright (C) 2006-2011 OpenWrt.org
4 .
$IPKG_INSTROOT/etc
/functions.sh
11 # service: simple wrapper around start-stop-daemon
13 # Usage: service ACTION EXEC ARGS...
16 # -S,--start start EXEC, passing it ARGS as its arguments
17 # -K,--stop stop EXEC (send it a $SERVICE_SIG_STOP signal)
18 # -R,--reload reload EXEC (send it a $SERVICE_SIG_RELOAD signal)
20 # Environment variables used:
21 # SERVICE_DAEMONIZE run EXEC in background
22 # SERVICE_WRITE_PID create a pid file and use it
23 # SERVICE_USE_PID assume EXEC creates its own pid file and use it
24 # SERVICE_PID_FILE pid file to use (default to /var/run/EXEC.pid)
25 # SERVICE_SIG_RELOAD signal used for reloading
26 # SERVICE_SIG_STOP signal used for stopping
27 # SERVICE_UID user EXEC should be run as
28 # SERVICE_GID group EXEC should be run as
30 # SERVICE_DEBUG don't do anything, but show what would be done
31 # SERVICE_QUIET don't print anything
35 SERVICE_SIG_RELOAD
="HUP"
36 SERVICE_SIG_STOP
="TERM"
43 ssd
="${SERVICE_DEBUG:+echo }start-stop-daemon${SERVICE_QUIET:+ -q}"
51 ssd_sig
="$SERVICE_SIG_STOP"
55 ssd_sig
="$SERVICE_SIG_RELOAD"
58 echo "ssd: unknow action '$1'" 1>&2
63 echo "ssd: missing arguments" 1>&2
67 if [ -n "$SERVICE_PID_FILE$SERVICE_USE_PID$SERVICE_WRITE_PID" ]; then
68 ssd
="$ssd -p ${SERVICE_PID_FILE:-/var/run/${1##*/}.pid}"
70 ssd
="$ssd${SERVICE_UID:+ -c $SERVICE_UID${SERVICE_GID:+:$SERVICE_GID}}"
71 if [ -n "$ssd_start" ]; then
72 ssd
="$ssd${SERVICE_DAEMONIZE:+ -b}${SERVICE_WRITE_PID:+ -m}"
74 ssd
="$ssd${ssd_sig:+ -s $ssd_sig}"
119 name
="$(basename "${initscript}")"
120 rm -f "$IPKG_INSTROOT"/etc
/rc.d
/S??
$name
121 rm -f "$IPKG_INSTROOT"/etc
/rc.d
/K??
$name
125 name
="$(basename "${initscript}")"
127 [ -n "$START" -o -n "$STOP" ] ||
{
128 echo "/etc/init.d/$name does not have a START or STOP value"
131 [ "$START" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
132 [ "$STOP" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
136 name
="$(basename "${initscript}")"
137 [ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
146 Syntax: $initscript [command]
149 start Start the service
150 stop Stop the service
151 restart Restart the service
152 reload Reload configuration files (or restart if that fails)
153 enable Enable service autostart
154 disable Disable service autostart
161 ALL_COMMANDS
="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
162 list_contains ALL_COMMANDS
"$action" || action
=help
163 [ "$action" = "reload" ] && action
='eval reload "$@" || restart "$@" && :'