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.

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