Changeset 2136


Ignore:
Timestamp:
Aug 21, 2012, 2:43:06 PM (7 years ago)
Author:
matthijs
Message:

base-files: Update rc.common.

This takes the rc.common from OpenWRT trunk (r28834). This adds the
various service_* functions to rc.common, which allows backporting some
more packages from OpenWRT without extra changes.

Closes: #1205

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/openwrt/package/base-files/files/etc/rc.common

    r1 r2136  
    11#!/bin/sh
    2 # Copyright (C) 2006 OpenWrt.org
     2# Copyright (C) 2006-2011 OpenWrt.org
    33
    44. $IPKG_INSTROOT/etc/functions.sh
     5
     6initscript=$1
     7action=${2:-help}
     8shift 2
     9
     10#
     11# service: simple wrapper around start-stop-daemon
     12#
     13# Usage: service ACTION EXEC ARGS...
     14#
     15# Action:
     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)
     19#
     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
     29#
     30#   SERVICE_DEBUG        don't do anything, but show what would be done
     31#   SERVICE_QUIET        don't print anything
     32#
     33
     34SERVICE_QUIET=1
     35SERVICE_SIG_RELOAD="HUP"
     36SERVICE_SIG_STOP="TERM"
     37
     38service() {
     39        local ssd
     40        local ssd_pid_file
     41        local ssd_sig
     42        local ssd_start
     43        ssd="${SERVICE_DEBUG:+echo }start-stop-daemon${SERVICE_QUIET:+ -q}"
     44        case "$1" in
     45          -S|--start|start)
     46                ssd="$ssd -S"
     47                ssd_start=1
     48                ;;
     49          -K|--stop|stop)
     50                ssd="$ssd -K"
     51                ssd_sig="$SERVICE_SIG_STOP"
     52                ;;
     53          -R|--reload|reload)
     54                ssd="$ssd -K"
     55                ssd_sig="$SERVICE_SIG_RELOAD"
     56                ;;
     57          *)
     58                echo "ssd: unknow action '$1'" 1>&2
     59                return 1
     60        esac
     61        shift
     62        if [ -z "$1" ]; then
     63                echo "ssd: missing arguments" 1>&2
     64                return 1
     65        fi
     66        ssd="$ssd -x $1"
     67        if [ -n "$SERVICE_PID_FILE$SERVICE_USE_PID$SERVICE_WRITE_PID" ]; then
     68                ssd="$ssd -p ${SERVICE_PID_FILE:-/var/run/${1##*/}.pid}"
     69        fi
     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}"
     73        else
     74                ssd="$ssd${ssd_sig:+ -s $ssd_sig}"
     75        fi
     76        shift
     77        $ssd${1:+ -- "$@"}
     78}
     79
     80service_start() {
     81        service -S "$@"
     82}
     83
     84service_stop() {
     85        service -K "$@"
     86}
     87
     88service_reload() {
     89        service -R "$@"
     90}
    591
    692start() {
     
    27113
    28114shutdown() {
    29         return 0
     115        stop
    30116}
    31117
     
    39125        name="$(basename "${initscript}")"
    40126        disable
    41         [ "$START" ] && ln -s "/etc/init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
    42         [ "$STOP"  ] && ln -s "/etc/init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
     127        [ -n "$START" -o -n "$STOP" ] || {
     128                echo "/etc/init.d/$name does not have a START or STOP value"
     129                return 1
     130        }
     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]}"
    43133}
    44134
     
    67157}
    68158
    69 initscript="$1"
    70 [ "$#" -ge 1 ] && shift
    71 action="$1"
    72 [ "$#" -ge 1 ] && shift
    73 
    74159. "$initscript"
    75160
    76 cmds=
    77 for cmd in $EXTRA_COMMANDS; do
    78         cmds="${cmds:+$cmds$N}$cmd) $cmd \"\$@\";;"
    79 done
    80 eval "case \"\$action\" in
    81         start) start \"\$@\";;
    82         stop) stop \"\$@\";;
    83         reload) reload \"\$@\" || restart \"\$@\";;
    84         restart) restart \"\$@\";;
    85         boot) boot \"\$@\";;
    86         shutdown) shutdown \"\$@\";;
    87         enable) enable \"\$@\";;
    88         enabled) enabled \"\$@\";;
    89         disable) disable \"\$@\";;
    90         $cmds
    91         *) help;;
    92 esac"
     161ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
     162list_contains ALL_COMMANDS "$action" || action=help
     163[ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :'
     164$action "$@"
Note: See TracChangeset for help on using the changeset viewer.