Advertisement
Guest User

Untitled

a guest
Oct 7th, 2013
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. #!/bin/sh -e
  2. # upstart-job
  3. #
  4. # Symlink target for initscripts that have been converted to Upstart.
  5.  
  6. set -e
  7.  
  8. UPSTART_JOB_CONF="/etc/default/upstart-job"
  9. INITSCRIPT="$(basename "$0")"
  10. JOB="${INITSCRIPT%.sh}"
  11.  
  12. if [ "$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
  21. else
  22. if [ -z "$1" ]; then
  23. echo "Usage: $0 COMMAND" 1>&2
  24. exit 1
  25. fi
  26. fi
  27.  
  28. COMMAND="$1"
  29. shift
  30.  
  31. ECHO=echo
  32. ECHO_ERROR=echo
  33. if [ -e "$UPSTART_JOB_CONF" ]; then
  34. . "$UPSTART_JOB_CONF"
  35. fi
  36. if [ -n "$DPKG_MAINTSCRIPT_PACKAGE" ]; then
  37. ECHO=:
  38. ECHO_ERROR=:
  39. fi
  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.  
  58. UPSTART_VERSION_RUNNING=$(initctl version|awk '{print $3}'|tr -d ')')
  59.  
  60. if dpkg --compare-versions "$UPSTART_VERSION_RUNNING" ge 0.9.7
  61. then
  62. initctl show-config -e "$JOB"|grep -q '^ start on' || DISABLED=1
  63. fi
  64.  
  65. case $COMMAND in
  66. status)
  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. ;;
  72. start|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. ;;
  88. restart)
  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. ;;
  108. reload|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
  119. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement