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.

115 lines
2.5 KiB

  1. #!/bin/bash
  2. #
  3. ### BEGIN INIT INFO
  4. # Provides: calico-node
  5. # Required-Start: $local_fs $network $syslog
  6. # Required-Stop:
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: Calico docker container
  10. # Description:
  11. # Runs calico as a docker container
  12. ### END INIT INFO
  13. set -a
  14. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  15. DESC="Calico-node Docker"
  16. NAME=calico-node
  17. DAEMON={{ bin_dir }}/calicoctl
  18. DAEMON_ARGS=""
  19. DOCKER=$(which docker)
  20. SCRIPTNAME=/etc/init.d/$NAME
  21. DAEMON_USER=root
  22. # Exit if the binary is not present
  23. [ -x "$DAEMON" ] || exit 0
  24. # Exit if the docker package is not installed
  25. [ -x "$DOCKER" ] || exit 0
  26. # Read configuration variable file if it is present
  27. [ -r /etc/network-environment ] && . /etc/network-environment
  28. # Define LSB log_* functions.
  29. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  30. # and status_of_proc is working.
  31. . /lib/lsb/init-functions
  32. do_status()
  33. {
  34. if [ $($DOCKER ps | awk '{ print $2 }' | grep calico/node | wc -l) -eq 1 ]; then
  35. return 0
  36. else
  37. return 1
  38. fi
  39. }
  40. # Function that starts the daemon/service
  41. #
  42. do_start()
  43. {
  44. do_status
  45. retval=$?
  46. if [ $retval -ne 0 ]; then
  47. ${DAEMON} node --ip=${DEFAULT_IPV4} >>/dev/null && return 0 || return 2
  48. else
  49. return 1
  50. fi
  51. }
  52. #
  53. # Function that stops the daemon/service
  54. #
  55. do_stop()
  56. {
  57. ${DAEMON} node stop >> /dev/null || ${DAEMON} node stop --force >> /dev/null
  58. }
  59. case "$1" in
  60. start)
  61. log_daemon_msg "Starting $DESC" "$NAME"
  62. do_start
  63. case "$?" in
  64. 0|1) log_end_msg 0 || exit 0 ;;
  65. 2) log_end_msg 1 || exit 1 ;;
  66. esac
  67. ;;
  68. stop)
  69. log_daemon_msg "Stopping $DESC" "$NAME"
  70. if do_stop; then
  71. log_end_msg 0
  72. else
  73. log_failure_msg "Can't stop calico-node"
  74. log_end_msg 1
  75. fi
  76. ;;
  77. status)
  78. if do_status; then
  79. log_end_msg 0
  80. else
  81. log_failure_msg "Calico-node is not running"
  82. log_end_msg 1
  83. fi
  84. ;;
  85. restart|force-reload)
  86. log_daemon_msg "Restarting $DESC" "$NAME"
  87. if do_stop; then
  88. if do_start; then
  89. log_end_msg 0
  90. exit 0
  91. else
  92. rc="$?"
  93. fi
  94. else
  95. rc="$?"
  96. fi
  97. log_failure_msg "Can't restart Calico-node"
  98. log_end_msg ${rc}
  99. ;;
  100. *)
  101. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  102. exit 3
  103. ;;
  104. esac