You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.5 KiB

  1. #!/bin/sh
  2. set -a
  3. ### BEGIN INIT INFO
  4. # Provides: etcd-proxy
  5. # Required-Start: $local_fs $network $syslog
  6. # Required-Stop:
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: etcd-proxy
  10. # Description:
  11. # etcd-proxy is a proxy for etcd: distributed, consistent key-value store for shared configuration and service discovery
  12. ### END INIT INFO
  13. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  14. DESC="etcd-proxy"
  15. NAME=etcd-proxy
  16. DAEMON={{ bin_dir }}/etcd
  17. DAEMON_ARGS=""
  18. SCRIPTNAME=/etc/init.d/$NAME
  19. DAEMON_USER=etcd
  20. STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/5/KILL/5}"
  21. PID=/var/run/etcd-proxy.pid
  22. # Exit if the binary is not present
  23. [ -x "$DAEMON" ] || exit 0
  24. # Read configuration variable file if it is present
  25. [ -f /etc/etcd-proxy.env ] && . /etc/etcd-proxy.env
  26. # Define LSB log_* functions.
  27. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  28. # and status_of_proc is working.
  29. . /lib/lsb/init-functions
  30. do_status()
  31. {
  32. status_of_proc -p $PID "$DAEMON" "$NAME" && exit 0 || exit $?
  33. }
  34. # Function that starts the daemon/service
  35. #
  36. do_start()
  37. {
  38. start-stop-daemon --background --start --quiet --make-pidfile --pidfile $PID --user $DAEMON_USER --exec $DAEMON -- \
  39. $DAEMON_ARGS \
  40. || return 2
  41. }
  42. #
  43. # Function that stops the daemon/service
  44. #
  45. do_stop()
  46. {
  47. start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PID --name $NAME
  48. RETVAL="$?"
  49. sleep 1
  50. return "$RETVAL"
  51. }
  52. case "$1" in
  53. start)
  54. log_daemon_msg "Starting $DESC" "$NAME"
  55. do_start
  56. case "$?" in
  57. 0|1) log_end_msg 0 || exit 0 ;;
  58. 2) log_end_msg 1 || exit 1 ;;
  59. esac
  60. ;;
  61. stop)
  62. log_daemon_msg "Stopping $DESC" "$NAME"
  63. if do_stop; then
  64. log_end_msg 0
  65. else
  66. log_failure_msg "Can't stop etcd-proxy"
  67. log_end_msg 1
  68. fi
  69. ;;
  70. status)
  71. if do_status; then
  72. log_end_msg 0
  73. else
  74. log_failure_msg "etcd-proxy is not running"
  75. log_end_msg 1
  76. fi
  77. ;;
  78. restart|force-reload)
  79. log_daemon_msg "Restarting $DESC" "$NAME"
  80. if do_stop; then
  81. if do_start; then
  82. log_end_msg 0
  83. exit 0
  84. else
  85. rc="$?"
  86. fi
  87. else
  88. rc="$?"
  89. fi
  90. log_failure_msg "Can't restart etcd-proxy"
  91. log_end_msg ${rc}
  92. ;;
  93. *)
  94. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  95. exit 3
  96. ;;
  97. esac