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: 2 3 4 5
  13. # Default-Stop: 0 1 6
  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.
  22. #
  23. zthome=/var/lib/zerotier-one
  24. # Add $zthome to path so we can invoke zerotier-one naked, makes it look
  25. # better in a ps listing.
  26. export PATH=/bin:/usr/bin:/sbin:/usr/sbin:$zthome
  27. if [ "`id -u`" -ne 0 ]; then
  28. echo "Init script must be called as root."
  29. exit 4
  30. fi
  31. if [ ! -f "$zthome/zerotier-one" ]; then
  32. echo "ZeroTier One is not installed in $zthome."
  33. exit 5
  34. fi
  35. pid=0
  36. if [ -f "$zthome/zerotier-one.pid" ]; then
  37. pid=`cat $zthome/zerotier-one.pid`
  38. fi
  39. running=0
  40. if [ "$pid" -gt 0 ]; then
  41. exepath=`readlink /proc/$pid/exe 2>/dev/null | grep zerotier-one`
  42. if [ -n "$exepath" ]; then
  43. running=1
  44. fi
  45. fi
  46. case "$1" in
  47. start)
  48. if [ $running -gt 0 ]; then
  49. echo "ZeroTier One already running."
  50. exit 0
  51. fi
  52. echo "Starting ZeroTier One..."
  53. zerotier-one -d
  54. ;;
  55. stop)
  56. if [ $running -gt 0 ]; then
  57. echo "Stopping ZeroTier One..."
  58. kill -TERM $pid
  59. sleep 0.25
  60. if [ -f "$zthome/zerotier-one.pid" ]; then
  61. sleep 0.5
  62. fi
  63. if [ -f "$zthome/zerotier-one.pid" ]; then
  64. sleep 1
  65. fi
  66. if [ -f "$zthome/zerotier-one.pid" ]; then
  67. kill -KILL $pid >>/dev/null 2>&1
  68. rm -f "$zthome/zerotier-one.pid"
  69. fi
  70. else
  71. echo "ZeroTier One is not running."
  72. fi
  73. ;;
  74. restart|reload|force-reload|condrestart|try-restart)
  75. echo "Restarting ZeroTier One..."
  76. if [ $running -gt 0 ]; then
  77. kill -TERM $pid >>/dev/null 2>&1
  78. fi
  79. sleep 0.25
  80. if [ -f "$zthome/zerotier-one.pid" ]; then
  81. sleep 0.5
  82. fi
  83. if [ -f "$zthome/zerotier-one.pid" ]; then
  84. sleep 1
  85. fi
  86. if [ -f "$zthome/zerotier-one.pid" ]; then
  87. kill -KILL $pid >>/dev/null 2>&1
  88. rm -f "$zthome/zerotier-one.pid"
  89. fi
  90. zerotier-one -d
  91. ;;
  92. status)
  93. if [ $running -gt 0 ]; then
  94. exit 0
  95. else
  96. exit 3
  97. fi
  98. ;;
  99. *)
  100. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
  101. exit 2
  102. esac
  103. exit 0