zerotier-one 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. if [ -n "`ls -l /proc/$pid/exe | grep -F zerotier-one`" ]; 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. else
  60. echo "ZeroTier One is not running."
  61. fi
  62. ;;
  63. restart|reload|force-reload|condrestart|try-restart)
  64. echo "Restarting ZeroTier One..."
  65. if [ $running -gt 0 ]; then
  66. kill -TERM $pid
  67. fi
  68. while [ -f "$zthome/zerotier-one.pid" ]; do sleep 1; done
  69. zerotier-one -d
  70. ;;
  71. status)
  72. if [ $running -gt 0 ]; then
  73. exit 0
  74. else
  75. exit 3
  76. fi
  77. ;;
  78. *)
  79. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
  80. exit 2
  81. esac
  82. exit 0