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.

117 lines
2.7 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={{ docker_bin_dir | default("/usr/bin") }}/docker
  17. DAEMON_ARGS='--restart=always --env-file=/etc/etcd-proxy.env \
  18. --net=host \
  19. --stop-signal=SIGKILL \
  20. -v /usr/share/ca-certificates/:/etc/ssl/certs:ro \
  21. --name={{ etcd_proxy_member_name | default("etcd-proxy") }} \
  22. {{ etcd_image_repo }}:{{ etcd_image_tag }} \
  23. {% if etcd_after_v3 %}
  24. {{ etcd_container_bin_dir }}etcd
  25. {% endif %}'
  26. SCRIPTNAME=/etc/init.d/$NAME
  27. DAEMON_USER=etcd-proxy
  28. STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/5/KILL/5}"
  29. PID=/var/run/etcd-proxy.pid
  30. # Exit if the binary is not present
  31. [ -x "$DAEMON" ] || exit 0
  32. # Define LSB log_* functions.
  33. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  34. # and status_of_proc is working.
  35. . /lib/lsb/init-functions
  36. do_status()
  37. {
  38. status_of_proc -p $PID "$DAEMON" "$NAME" && exit 0 || exit $?
  39. }
  40. # Function that starts the daemon/service
  41. #
  42. do_start()
  43. {
  44. start-stop-daemon --background --start --quiet --make-pidfile --pidfile $PID --user $DAEMON_USER --exec $DAEMON -- \
  45. $DAEMON_ARGS \
  46. || return 2
  47. }
  48. #
  49. # Function that stops the daemon/service
  50. #
  51. do_stop()
  52. {
  53. start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PID --name $NAME
  54. RETVAL="$?"
  55. sleep 1
  56. return "$RETVAL"
  57. }
  58. case "$1" in
  59. start)
  60. log_daemon_msg "Starting $DESC" "$NAME"
  61. do_start
  62. case "$?" in
  63. 0|1) log_end_msg 0 || exit 0 ;;
  64. 2) log_end_msg 1 || exit 1 ;;
  65. esac
  66. ;;
  67. stop)
  68. log_daemon_msg "Stopping $DESC" "$NAME"
  69. if do_stop; then
  70. log_end_msg 0
  71. else
  72. log_failure_msg "Can't stop etcd-proxy"
  73. log_end_msg 1
  74. fi
  75. ;;
  76. status)
  77. if do_status; then
  78. log_end_msg 0
  79. else
  80. log_failure_msg "etcd-proxy is not running"
  81. log_end_msg 1
  82. fi
  83. ;;
  84. restart|force-reload)
  85. log_daemon_msg "Restarting $DESC" "$NAME"
  86. if do_stop; then
  87. if do_start; then
  88. log_end_msg 0
  89. exit 0
  90. else
  91. rc="$?"
  92. fi
  93. else
  94. rc="$?"
  95. fi
  96. log_failure_msg "Can't restart etcd-proxy"
  97. log_end_msg ${rc}
  98. ;;
  99. *)
  100. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  101. exit 3
  102. ;;
  103. esac