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.

119 lines
2.9 KiB

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