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.

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