PageRenderTime 58ms CodeModel.GetById 48ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/init.d/qemu-kvm

http://github.com/brinkman83/bashrc
Shell | 119 lines | 87 code | 11 blank | 21 comment | 17 complexity | 9304ff4a5c63a4ec61b429f5af102868 MD5 | raw file
  1#!/bin/sh -e
  2# upstart-job
  3#
  4# Symlink target for initscripts that have been converted to Upstart.
  5
  6set -e
  7
  8UPSTART_JOB_CONF="/etc/default/upstart-job"
  9INITSCRIPT="$(basename "$0")"
 10JOB="${INITSCRIPT%.sh}"
 11
 12if [ "$JOB" = "upstart-job" ]; then
 13    if [ -z "$1" ]; then
 14        echo "Usage: upstart-job JOB COMMAND" 1>&2
 15	exit 1
 16    fi
 17
 18    JOB="$1"
 19    INITSCRIPT="$1"
 20    shift
 21else
 22    if [ -z "$1" ]; then
 23        echo "Usage: $0 COMMAND" 1>&2
 24	exit 1
 25    fi
 26fi
 27
 28COMMAND="$1"
 29shift
 30
 31ECHO=echo
 32ECHO_ERROR=echo
 33if [ -e "$UPSTART_JOB_CONF" ]; then
 34	. "$UPSTART_JOB_CONF"
 35fi
 36if [ -n "$DPKG_MAINTSCRIPT_PACKAGE" ]; then
 37	ECHO=:
 38	ECHO_ERROR=:
 39fi
 40
 41$ECHO "Rather than invoking init scripts through /etc/init.d, use the service(8)"
 42$ECHO "utility, e.g. service $INITSCRIPT $COMMAND"
 43
 44# Only check if jobs are disabled if the currently _running_ version of
 45# Upstart (which may be older than the latest _installed_ version)
 46# supports such a query.
 47#
 48# This check is necessary to handle the scenario when upgrading from a
 49# release without the 'show-config' command (introduced in
 50# Upstart for Ubuntu version 0.9.7) since without this check, all
 51# installed packages with associated Upstart jobs would be considered
 52# disabled.
 53#
 54# Once Upstart can maintain state on re-exec, this change can be
 55# dropped (since the currently running version of Upstart will always
 56# match the latest installed version).
 57
 58UPSTART_VERSION_RUNNING=$(initctl version|awk '{print $3}'|tr -d ')')
 59
 60if dpkg --compare-versions "$UPSTART_VERSION_RUNNING" ge 0.9.7
 61then
 62    initctl show-config -e "$JOB"|grep -q '^  start on' || DISABLED=1
 63fi
 64
 65case $COMMAND in
 66status)
 67    $ECHO
 68    $ECHO "Since the script you are attempting to invoke has been converted to an"
 69    $ECHO "Upstart job, you may also use the $COMMAND(8) utility, e.g. $COMMAND $JOB"
 70    $COMMAND "$JOB"
 71    ;;
 72start|stop)
 73    $ECHO
 74    $ECHO "Since the script you are attempting to invoke has been converted to an"
 75    $ECHO "Upstart job, you may also use the $COMMAND(8) utility, e.g. $COMMAND $JOB"
 76    if status "$JOB" 2>/dev/null | grep -q ' start/'; then
 77        RUNNING=1
 78    fi
 79    if [ -z "$RUNNING" ] && [ "$COMMAND" = "stop" ]; then
 80        exit 0
 81    elif [ -n "$RUNNING" ] && [ "$COMMAND" = "start" ]; then
 82        exit 0
 83    elif [ -n "$DISABLED" ] && [ "$COMMAND" = "start" ]; then
 84        exit 0
 85    fi
 86    $COMMAND "$JOB"
 87    ;;
 88restart)
 89    $ECHO
 90    $ECHO "Since the script you are attempting to invoke has been converted to an"
 91    $ECHO "Upstart job, you may also use the stop(8) and then start(8) utilities,"
 92    $ECHO "e.g. stop $JOB ; start $JOB. The restart(8) utility is also available."
 93    if status "$JOB" 2>/dev/null | grep -q ' start/'; then
 94        RUNNING=1
 95    fi
 96    if [ -n "$RUNNING" ] ; then
 97        stop "$JOB"
 98    fi
 99    # If the job is disabled and is not currently running, the job is
100    # not restarted. However, if the job is disabled but has been forced into the
101    # running state, we *do* stop and restart it since this is expected behaviour
102    # for the admin who forced the start.
103    if [ -n "$DISABLED" ] && [ -z "$RUNNING" ]; then
104        exit 0
105    fi
106    start "$JOB"
107    ;;
108reload|force-reload)
109    $ECHO
110    $ECHO "Since the script you are attempting to invoke has been converted to an"
111    $ECHO "Upstart job, you may also use the reload(8) utility, e.g. reload $JOB"
112    reload "$JOB"
113    ;;
114*)
115    $ECHO_ERROR
116    $ECHO_ERROR "The script you are attempting to invoke has been converted to an Upstart" 1>&2
117    $ECHO_ERROR "job, but $COMMAND is not supported for Upstart jobs." 1>&2
118    exit 1
119esac