Changeset 28991


Ignore:
Timestamp:
2011-11-12T14:53:15+01:00 (6 years ago)
Author:
nico
Message:

package/base-files: enhance service functions

  • allow matching process by name (useful for processes changing it)
  • check if first argument is executable
  • fix function name used in error messages
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/package/base-files/files/lib/functions.sh

    r28871 r28991  
    288288# Environment variables exposed: 
    289289#   SERVICE_DAEMONIZE    run EXEC in background 
    290 #   SERVICE_WRITE_PID    create a pid file and use it 
    291 #   SERVICE_USE_PID      assume EXEC creates its own pid file and use it 
    292 #   SERVICE_PID_FILE     pid file to use (default to /var/run/EXEC.pid) 
     290#   SERVICE_WRITE_PID    create a pid-file and use it for matching 
     291#   SERVICE_MATCH_EXEC   use EXEC command-line for matching (default) 
     292#   SERVICE_MATCH_NAME   use EXEC process name for matching 
     293#   SERVICE_USE_PID      assume EXEC create its own pid-file and use it for matching 
     294#   SERVICE_NAME         process name to use (default to EXEC file part) 
     295#   SERVICE_PID_FILE     pid file to use (default to /var/run/$SERVICE_NAME.pid) 
    293296#   SERVICE_SIG          signal to send when using -K 
    294 #   SERVICE_SIG_RELOAD   default signal used for reloading 
    295 #   SERVICE_SIG_STOP     default signal used for stopping 
     297#   SERVICE_SIG_RELOAD   default signal used when reloading 
     298#   SERVICE_SIG_STOP     default signal used when stopping 
    296299#   SERVICE_STOP_TIME    time to wait for a process to stop gracefully before killing it 
    297300#   SERVICE_UID          user EXEC should be run as 
     
    306309SERVICE_SIG_STOP="TERM" 
    307310SERVICE_STOP_TIME=5 
     311SERVICE_MATCH_EXEC=1 
    308312 
    309313service() { 
    310314        local ssd 
     315        local exec 
     316        local name 
     317        local start 
    311318        ssd="${SERVICE_DEBUG:+echo }start-stop-daemon${SERVICE_QUIET:+ -q}" 
    312319        case "$1" in 
     
    316323          -S) 
    317324                ssd="$ssd -S${SERVICE_DAEMONIZE:+ -b}${SERVICE_WRITE_PID:+ -m}" 
     325                start=1 
    318326                ;; 
    319327          -K) 
     
    321329                ;; 
    322330          *) 
    323                 echo "ssd: unknow action '$1'" 1>&2 
     331                echo "service: unknown ACTION '$1'" 1>&2 
    324332                return 1 
    325333        esac 
    326334        shift 
    327         if [ -z "$1" ]; then 
    328                 echo "ssd: missing arguments" 1>&2 
     335        exec="$1" 
     336        [ -n "$exec" ] || { 
     337                echo "service: missing argument" 1>&2 
    329338                return 1 
    330         fi 
    331         ssd="$ssd -x $1" 
    332         if [ -n "$SERVICE_PID_FILE$SERVICE_USE_PID$SERVICE_WRITE_PID" ]; then 
    333                 ssd="$ssd -p ${SERVICE_PID_FILE:-/var/run/${1##*/}.pid}" 
    334         fi 
     339        } 
     340        [ -x "$exec" ] || { 
     341                echo "service: file '$exec' is not executable" 1>&2 
     342                return 1 
     343        } 
     344        name="${SERVICE_NAME:-${exec##*/}}" 
     345        [ -z "$SERVICE_USE_PID$SERVICE_WRITE_PID$SERVICE_PID_FILE" ] \ 
     346                || ssd="$ssd -p ${SERVICE_PID_FILE:-/var/run/$name.pid}" 
     347        [ -z "$SERVICE_MATCH_NAME" ] || ssd="$ssd -n $name" 
    335348        ssd="$ssd${SERVICE_UID:+ -c $SERVICE_UID${SERVICE_GID:+:$SERVICE_GID}}" 
     349        [ -z "$SERVICE_MATCH_EXEC$start" ] || ssd="$ssd -x $exec" 
    336350        shift 
    337351        $ssd${1:+ -- "$@"} 
Note: See TracChangeset for help on using the changeset viewer.