openvpnd 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. #
  3. # /etc/rc.d/openvpn: start/stop openvpn daemon
  4. #
  5. CONFDIR=/etc/openvpn
  6. RUNDIR=/var/run
  7. # optional arguments to openvpn
  8. OPTARGS="--fast-io"
  9. usage() {
  10. echo "Usage: $0 [start|stop|restart] <config-name>"
  11. exit 0
  12. }
  13. # require a config name to be specified
  14. if [ -z "$2" ]
  15. then
  16. usage
  17. fi
  18. CONF=${CONFDIR}/${2}.conf
  19. PID=${RUNDIR}/openvpn.${2}.pid
  20. # check for the existence of the specified config
  21. if [ ! -f ${CONF} ]
  22. then
  23. echo "Can't find config file ${CONF}! Exiting."
  24. exit 1
  25. fi
  26. case $1 in
  27. start)
  28. # check for an existing PID; this tunnel may already be running
  29. if [ -f ${PID} ]
  30. then
  31. echo "VPN '${2}' appears to be running already. If not, remove the stale PID file '${PID}'. Exiting."
  32. exit 2
  33. fi
  34. # start the specified VPN config
  35. echo "Starting VPN '${2}'..."
  36. /usr/sbin/openvpn --config ${CONF} --writepid ${PID} --daemon ovpn-${2} ${OPTARGS}
  37. ;;
  38. stop)
  39. # check for an existing PID; this tunnel should already be running
  40. if [ ! -f ${PID} ]
  41. then
  42. echo "VPN '${2}' doesn't appear to be running. Exiting."
  43. exit 3
  44. fi
  45. # stop the specified VPN config
  46. echo "Stopping VPN '${2}'..."
  47. kill `cat ${PID}`
  48. rm -f ${PID}
  49. ;;
  50. restart)
  51. ${0} stop ${2}; sleep 3; ${0} start ${2}
  52. ;;
  53. *)
  54. usage
  55. ;;
  56. esac
  57. # End of file