zerotier-one 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 [ "$UID" -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. if [ "`readlink -nf /proc/$pid/exe`" = "$zthome/zerotier-one" ]; then
  43. running=1
  44. else
  45. rm -f "$zthome/zerotier-one.pid"
  46. fi
  47. fi
  48. case "$1" in
  49. start)
  50. if [ $running -gt 0 ]; then
  51. echo "ZeroTier One already running."
  52. exit 0
  53. fi
  54. echo "Starting ZeroTier One..."
  55. nohup zerotier-one >>/dev/null 2>&1 &
  56. disown %1
  57. exit 0
  58. ;;
  59. stop)
  60. if [ $running -gt 0 ]; then
  61. echo "Stopping ZeroTier One..."
  62. kill -TERM $pid
  63. else
  64. echo "ZeroTier One is not running."
  65. fi
  66. ;;
  67. restart|reload|force-reload|condrestart|try-restart)
  68. echo "Restarting ZeroTier One..."
  69. if [ $running -gt 0 ]; then
  70. kill -TERM $pid
  71. fi
  72. while [ -f "$zthome/zerotier-one.pid" ]; do sleep 1; done
  73. nohup zerotier-one >>/dev/null 2>&1 &
  74. disown %1
  75. ;;
  76. status)
  77. if [ $running -gt 0 ]; then
  78. exit 0
  79. else
  80. exit 3
  81. fi
  82. ;;
  83. *)
  84. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
  85. exit 2
  86. esac
  87. exit 0