zerotier-one 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/sh
  2. #
  3. # zerotier-one Virtual distributed Ethernet service
  4. #
  5. # chkconfig: 2345 11 89
  6. # description: ZeroTier One provides public and private distributed ethernet \
  7. # networks. See https://www.zerotier.com/ for more information.
  8. ### BEGIN INIT INFO
  9. # Provides: zerotier-one
  10. # Required-Start: $local_fs $network
  11. # Required-Stop: $local_fs
  12. # Default-Start: 2345
  13. # Default-Stop: 90
  14. # Short-Description: start ZeroTier One
  15. # Description: ZeroTier One provides public and private distributed ethernet \
  16. # networks. See https://www.zerotier.com/ for more information.
  17. ### END INIT INFO
  18. #
  19. # This script is written to avoid distro-specific dependencies, so it does not
  20. # use the rc bash script libraries found on some systems. It should work on
  21. # just about anything, even systems using Upstart. Upstart native support may
  22. # come in the future.
  23. #
  24. zthome=/var/lib/zerotier-one
  25. # Add $zthome to path so we can invoke zerotier-one naked, makes it look
  26. # better in a ps listing.
  27. export PATH=/bin:/usr/bin:/sbin:/usr/sbin:$zthome
  28. if [ "`id -u`" -ne 0 ]; then
  29. echo "Init script must be called as root."
  30. exit 4
  31. fi
  32. if [ ! -f "$zthome/zerotier-one" ]; then
  33. echo "ZeroTier One is not installed in $zthome."
  34. exit 5
  35. fi
  36. pid=0
  37. if [ -f "$zthome/zerotier-one.pid" ]; then
  38. pid=`cat $zthome/zerotier-one.pid`
  39. fi
  40. running=0
  41. if [ "$pid" -gt 0 ]; then
  42. exepath=`readlink /proc/$pid/exe 2>/dev/null | grep zerotier-one`
  43. if [ -n "$exepath" ]; then
  44. running=1
  45. fi
  46. fi
  47. case "$1" in
  48. start)
  49. if [ $running -gt 0 ]; then
  50. echo "ZeroTier One already running."
  51. exit 0
  52. fi
  53. echo "Starting ZeroTier One..."
  54. zerotier-one -d
  55. ;;
  56. stop)
  57. if [ $running -gt 0 ]; then
  58. echo "Stopping ZeroTier One..."
  59. kill -TERM $pid
  60. sleep 0.25
  61. if [ -f "$zthome/zerotier-one.pid" ]; then
  62. sleep 0.5
  63. fi
  64. if [ -f "$zthome/zerotier-one.pid" ]; then
  65. sleep 1
  66. fi
  67. if [ -f "$zthome/zerotier-one.pid" ]; then
  68. kill -KILL $pid >>/dev/null 2>&1
  69. rm -f "$zthome/zerotier-one.pid"
  70. fi
  71. else
  72. echo "ZeroTier One is not running."
  73. fi
  74. ;;
  75. restart|reload|force-reload|condrestart|try-restart)
  76. echo "Restarting ZeroTier One..."
  77. if [ $running -gt 0 ]; then
  78. kill -TERM $pid >>/dev/null 2>&1
  79. fi
  80. sleep 0.25
  81. if [ -f "$zthome/zerotier-one.pid" ]; then
  82. sleep 0.5
  83. fi
  84. if [ -f "$zthome/zerotier-one.pid" ]; then
  85. sleep 1
  86. fi
  87. if [ -f "$zthome/zerotier-one.pid" ]; then
  88. kill -KILL $pid >>/dev/null 2>&1
  89. rm -f "$zthome/zerotier-one.pid"
  90. fi
  91. zerotier-one -d
  92. ;;
  93. status)
  94. if [ $running -gt 0 ]; then
  95. exit 0
  96. else
  97. exit 3
  98. fi
  99. ;;
  100. *)
  101. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
  102. exit 2
  103. esac
  104. exit 0