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