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.

140 lines
2.8 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 --format "{{.Image}}" | grep -cw 'calico/node') -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. {% if legacy_calicoctl %}
  49. $exec node --ip=${DEFAULT_IPV4} &>>$logfile
  50. {% else %}
  51. $exec node run --ip=${DEFAULT_IPV4} &>>$logfile
  52. {% endif %}
  53. success
  54. echo
  55. else
  56. echo -n "calico-node's already running"
  57. success
  58. exit 0
  59. fi
  60. }
  61. do_stop() {
  62. echo -n $"Stopping $prog: "
  63. {% if legacy_calicoctl %}
  64. $exec node stop >> /dev/null || $exec node stop --force >> /dev/null
  65. {% else %}
  66. echo "Current version of ${exec} doesn't support 'node stop' command!"
  67. return 1
  68. {% endif %}
  69. retval=$?
  70. echo
  71. return $retval
  72. }
  73. restart() {
  74. do_stop
  75. do_start
  76. }
  77. reload() {
  78. restart
  79. }
  80. force_reload() {
  81. restart
  82. }
  83. case "$1" in
  84. start)
  85. do_start
  86. case "$?" in
  87. 0|1) success || exit 0 ;;
  88. 2) failure || exit 1 ;;
  89. esac
  90. ;;
  91. stop)
  92. echo -n "Stopping $DESC" "$NAME"
  93. if do_stop; then
  94. success
  95. echo
  96. else
  97. echo -n "Can't stop calico-node"
  98. failure
  99. echo
  100. fi
  101. ;;
  102. restart)
  103. $1
  104. ;;
  105. reload)
  106. $1
  107. ;;
  108. force-reload)
  109. force_reload
  110. ;;
  111. status)
  112. if do_status; then
  113. echo -n "Calico-node is running"
  114. success
  115. echo
  116. else
  117. echo -n "Calico-node is not running"
  118. failure
  119. echo
  120. fi
  121. ;;
  122. *)
  123. echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
  124. exit 2
  125. esac
  126. exit $?