etcd 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/sh
  2. set -e
  3. ### BEGIN INIT INFO
  4. # Provides: etcd
  5. # Required-Start: $docker
  6. # Required-Stop:
  7. # Should-Start:
  8. # Should-Stop:
  9. # Default-Start:
  10. # Default-Stop:
  11. # Short-Description: Start distrubted key/value pair service
  12. # Description:
  13. # http://www.github.com/coreos/etcd
  14. ### END INIT INFO
  15. export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/opt/bin:
  16. BASE=$(basename $0)
  17. # modify these in /etc/default/$BASE (/etc/default/etcd)
  18. ETCD=/opt/bin/$BASE
  19. # This is the pid file managed by etcd itself
  20. ETCD_PIDFILE=/var/run/$BASE.pid
  21. ETCD_LOGFILE=/var/log/$BASE.log
  22. ETCD_OPTS=""
  23. ETCD_DESC="Etcd"
  24. # Get lsb functions
  25. . /lib/lsb/init-functions
  26. if [ -f /etc/default/$BASE ]; then
  27. . /etc/default/$BASE
  28. fi
  29. # see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it)
  30. if false && [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; then
  31. log_failure_msg "$ETCD_DESC is managed via upstart, try using service $BASE $1"
  32. exit 1
  33. fi
  34. # Check etcd is present
  35. if [ ! -x $ETCD ]; then
  36. log_failure_msg "$ETCD not present or not executable"
  37. exit 1
  38. fi
  39. fail_unless_root() {
  40. if [ "$(id -u)" != '0' ]; then
  41. log_failure_msg "$ETCD_DESC must be run as root"
  42. exit 1
  43. fi
  44. }
  45. ETCD_START="start-stop-daemon \
  46. --start \
  47. --background \
  48. --quiet \
  49. --exec $ETCD \
  50. --make-pidfile \
  51. --pidfile $ETCD_PIDFILE \
  52. -- $ETCD_OPTS \
  53. >> $ETCD_LOGFILE 2>&1"
  54. ETCD_STOP="start-stop-daemon \
  55. --stop \
  56. --pidfile $ETCD_PIDFILE"
  57. case "$1" in
  58. start)
  59. fail_unless_root
  60. log_begin_msg "Starting $ETCD_DESC: $BASE"
  61. $ETCD_START
  62. log_end_msg $?
  63. ;;
  64. stop)
  65. fail_unless_root
  66. log_begin_msg "Stopping $ETCD_DESC: $BASE"
  67. $ETCD_STOP
  68. log_end_msg $?
  69. ;;
  70. restart | force-reload)
  71. fail_unless_root
  72. log_begin_msg "Restarting $ETCD_DESC: $BASE"
  73. $ETCD_STOP
  74. $ETCD_START
  75. log_end_msg $?
  76. ;;
  77. status)
  78. status_of_proc -p "$ETCD_PIDFILE" "$ETCD" "$ETCD_DESC"
  79. ;;
  80. *)
  81. echo "Usage: $0 {start|stop|restart|status}"
  82. exit 1
  83. ;;
  84. esac