app.in 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # source function library
  3. . /etc/%APP_NAME%/lib/start-stop-functions
  4. . /etc/%APP_NAME%/lib/init-multi-mode
  5. # Check for missing binaries (stale symlinks should not happen)
  6. # Note: Special treatment of stop for LSB conformance
  7. APP_BIN=/opt/%APP_NAME%/bin/%APP_NAME%
  8. test -x $APP_BIN || { echo "$APP_BIN not installed";
  9. if [ "$1" = "stop" ]; then exit 0;
  10. else exit 5; fi; }
  11. if [ "${MULTI_MODE}" = "YES" -o "${MULTI_MODE}" = "yes" ]; then
  12. init_multi_mode $1 $2
  13. exit $?
  14. fi
  15. PIDFILE=/var/run/%APP_NAME%.pid
  16. DAEMON_ARGS="pidFile=$PIDFILE"
  17. RETVAL=0
  18. # Return values acc. to LSB for all commands but status:
  19. # 0 - success
  20. # 1 - generic or unspecified error
  21. # 2 - invalid or excess argument(s)
  22. # 3 - unimplemented feature (e.g. "reload")
  23. # 4 - user had insufficient privileges
  24. # 5 - program is not installed
  25. # 6 - program is not configured
  26. # 7 - program is not running
  27. # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
  28. #
  29. # Note that starting an already running service, stopping
  30. # or restarting a not-running service as well as the restart
  31. # with force-reload (in case signaling is not supported) are
  32. # considered a success.
  33. case "$1" in
  34. start)
  35. echo -n "Starting %APP_NAME%: "
  36. ## create subfolder for lock files, on Debian systems needed
  37. mkdir -p /var/lock/subsys
  38. ## Start daemon with startproc(8). If this fails
  39. ## the return value is set appropriately by startproc.
  40. daemon --pidfile $PIDFILE $APP_BIN &
  41. RETVAL=$?
  42. echo
  43. ;;
  44. stop)
  45. echo -n "Shutting down %APP_NAME%: "
  46. ## Stop daemon with killproc(8) and if this fails
  47. ## killproc sets the return value according to LSB.
  48. killproc -p $PIDFILE $APP_BIN && rm -f /var/lock/subsys/%APP_NAME%
  49. RETVAL=$?
  50. echo
  51. ;;
  52. restart)
  53. ## Stop the service and regardless of whether it was
  54. ## running or not, start it again.
  55. $0 stop
  56. $0 start
  57. RETVAL=$?
  58. ;;
  59. status)
  60. echo -n "Checking for service %APP_NAME%: "
  61. ## Check status with checkproc(8), if process is running
  62. ## checkproc will return with exit status 0.
  63. # Return value is slightly different for the status command:
  64. # 0 - service up and running
  65. # 1 - service dead, but /var/run/ pid file exists
  66. # 2 - service dead, but /var/lock/ lock file exists
  67. # 3 - service not running (unused)
  68. # 4 - service status unknown :-(
  69. # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
  70. status -p $PIDFILE $APP_BIN
  71. RETVAL=$?
  72. echo
  73. ;;
  74. *)
  75. echo "Usage: $0 {start|stop|status|restart}"
  76. exit 3
  77. ;;
  78. esac
  79. exit $RETVAL