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.

131 lines
2.6 KiB

  1. #!/bin/bash
  2. #
  3. # /etc/rc.d/init.d/calico-node
  4. #
  5. # chkconfig: 2345 95 95
  6. # description: Daemon for calico-node (http://www.projectcalico.org/)
  7. set -a
  8. ### BEGIN INIT INFO
  9. # Provides: calico-node
  10. # Required-Start: $local_fs $network $syslog cgconfig
  11. # Required-Stop:
  12. # Should-Start:
  13. # Should-Stop:
  14. # Default-Start: 2 3 4 5
  15. # Default-Stop: 0 1 6
  16. # Short-Description: start and stop calico-node
  17. # Description:
  18. # Manage calico-docker container
  19. ### END INIT INFO
  20. # Source function library.
  21. . /etc/rc.d/init.d/functions
  22. prog="calicoctl"
  23. exec="{{ bin_dir }}/$prog"
  24. dockerexec="$(which docker)"
  25. logfile="/var/log/$prog"
  26. [ -e /etc/network-environment ] && for i in $(cat /etc/network-environment | egrep '(^$|^#)'); do export $i; done
  27. do_status()
  28. {
  29. if [ $($dockerexec ps | awk '{ print $2 }' | grep calico/node | wc -l) -ne 1 ]; then
  30. return 1
  31. fi
  32. }
  33. do_start() {
  34. if [ ! -x $exec ]; then
  35. if [ ! -e $exec ]; then
  36. echo "calico-node executable $exec not found"
  37. else
  38. echo "You do not have permission to execute the calico-node executable $exec"
  39. fi
  40. exit 5
  41. fi
  42. [ -x "$dockerexec" ] || exit 0
  43. do_status
  44. retval=$?
  45. if [ $retval -ne 0 ]; then
  46. printf "Starting $prog:\t"
  47. echo "\n$(date)\n" >> $logfile
  48. $exec node --ip=${DEFAULT_IPV4} &>>$logfile
  49. success
  50. echo
  51. else
  52. echo -n "calico-node's already running"
  53. success
  54. exit 0
  55. fi
  56. }
  57. do_stop() {
  58. echo -n $"Stopping $prog: "
  59. $exec node stop >> /dev/null || $exec node stop --force >> /dev/null
  60. retval=$?
  61. echo
  62. return $retval
  63. }
  64. restart() {
  65. do_stop
  66. do_start
  67. }
  68. reload() {
  69. restart
  70. }
  71. force_reload() {
  72. restart
  73. }
  74. case "$1" in
  75. start)
  76. do_start
  77. case "$?" in
  78. 0|1) success || exit 0 ;;
  79. 2) failure || exit 1 ;;
  80. esac
  81. ;;
  82. stop)
  83. echo -n "Stopping $DESC" "$NAME"
  84. if do_stop; then
  85. success
  86. echo
  87. else
  88. echo -n "Can't stop calico-node"
  89. failure
  90. echo
  91. fi
  92. ;;
  93. restart)
  94. $1
  95. ;;
  96. reload)
  97. $1
  98. ;;
  99. force-reload)
  100. force_reload
  101. ;;
  102. status)
  103. if do_status; then
  104. echo -n "Calico-node is running"
  105. success
  106. echo
  107. else
  108. echo -n "Calico-node is not running"
  109. failure
  110. echo
  111. fi
  112. ;;
  113. *)
  114. echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
  115. exit 2
  116. esac
  117. exit $?