Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # consul Manage the consul agent
  4. #
  5. # chkconfig: 2345 95 95
  6. # description: Consul is a tool for service discovery and configuration
  7. # processname: consul
  8. # config: /etc/consul/consul.conf
  9. # pidfile: /var/run/consul.pid
  10.  
  11. ### BEGIN INIT INFO
  12. # Provides: consul
  13. # Required-Start: $local_fs $network
  14. # Required-Stop:
  15. # Should-Start:
  16. # Should-Stop:
  17. # Default-Start: 2 3 4 5
  18. # Default-Stop: 0 1 6
  19. # Short-Description: Manage the consul agent
  20. # Description: Consul is a tool for service discovery and configuration
  21. ### END INIT INFO
  22.  
  23. # source function library
  24. . /etc/rc.d/init.d/functions
  25.  
  26. prog="consul"
  27. user="consul"
  28. exec="/usr/local/bin/$prog"
  29. pidfile="/var/run/$prog.pid"
  30. lockfile="/var/lock/subsys/$prog"
  31. logdir="/var/log/$prog"
  32. logfile="$logdir/$prog.log"
  33. conffile="/etc/consul/consul.conf"
  34. confdir="/etc/consul/conf.d"
  35.  
  36. # pull in sysconfig settings
  37. [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
  38.  
  39. export GOMAXPROCS=${GOMAXPROCS:-2}
  40.  
  41. start() {
  42. [ -x $exec ] || exit 5
  43.  
  44. [ -f $conffile ] || exit 6
  45. [ -d $confdir ] || exit 6
  46. [ -d $logdir ] || exit 6
  47.  
  48. umask 077
  49.  
  50. touch $logfile $pidfile
  51. chown $user:$user $logfile $pidfile
  52.  
  53. echo -n $"Starting $prog: "
  54.  
  55. ## holy shell shenanigans, batman!
  56. ## daemon can't be backgrounded. we need the pid of the spawned process,
  57. ## which is actually done via runuser thanks to --user. you can't do "cmd
  58. ## &; action" but you can do "{cmd &}; action".
  59. daemon \
  60. --pidfile=$pidfile \
  61. --user=$user \
  62. " { $exec agent -config-file=$conffile -config-dir=$confdir &>> $logfile & } ; echo \$! >| $pidfile "
  63.  
  64. RETVAL=$?
  65. echo
  66.  
  67. [ $RETVAL -eq 0 ] && touch $lockfile
  68.  
  69. return $RETVAL
  70. }
  71.  
  72. stop() {
  73. echo -n $"Shutting down $prog: "
  74. ## graceful shutdown with SIGINT
  75. killproc -p $pidfile $exec -INT
  76. RETVAL=$?
  77. echo
  78. [ $RETVAL -eq 0 ] && rm -f $lockfile
  79. return $RETVAL
  80. }
  81.  
  82. restart() {
  83. stop
  84. while ps -p `cat $pidfile`; do sleep 1; done
  85. start
  86. }
  87.  
  88. reload() {
  89. echo -n $"Reloading $prog: "
  90. killproc -p $pidfile $exec -HUP
  91. echo
  92. }
  93.  
  94. force_reload() {
  95. restart
  96. }
  97.  
  98. rh_status() {
  99. status -p "$pidfile" -l $prog $exec
  100. }
  101.  
  102. rh_status_q() {
  103. rh_status >/dev/null 2>&1
  104. }
  105.  
  106. case "$1" in
  107. start)
  108. rh_status_q && exit 0
  109. $1
  110. ;;
  111. stop)
  112. rh_status_q || exit 0
  113. $1
  114. ;;
  115. restart)
  116. $1
  117. ;;
  118. reload)
  119. rh_status_q || exit 7
  120. $1
  121. ;;
  122. force-reload)
  123. force_reload
  124. ;;
  125. status)
  126. rh_status
  127. ;;
  128. condrestart|try-restart)
  129. rh_status_q || exit 0
  130. restart
  131. ;;
  132. *)
  133. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
  134. exit 2
  135. esac
  136.  
  137. exit $?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement