tincd-r2 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2014 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. extra_started_commands="reload"
  5. NETS="/etc/conf.d/tinc.networks"
  6. DAEMON="/usr/sbin/tincd"
  7. depend() {
  8. use logger dns
  9. need net
  10. }
  11. checkconfig() {
  12. if [ "${RC_SVCNAME}" = "tincd" ] ; then
  13. ALL_NETNAME="$(awk '/^ *NETWORK:/ { print $2 }' "${NETS}")"
  14. else
  15. ALL_NETNAME="${RC_SVCNAME#*.}"
  16. fi
  17. # warn this if still not found
  18. if [ -z "${ALL_NETNAME}" ] ; then
  19. eerror "No VPN networks configured in ${NETS}"
  20. return 1
  21. fi
  22. return 0
  23. }
  24. start() {
  25. ebegin "Starting tinc VPN networks"
  26. checkconfig || return 1
  27. for NETNAME in ${ALL_NETNAME}
  28. do
  29. CONFIG="/etc/tinc/${NETNAME}/tinc.conf"
  30. PIDFILE="/run/tinc.${NETNAME}.pid"
  31. if [ ! -f "${CONFIG}" ]; then
  32. eerror "Cannot start network ${NETNAME}."
  33. eerror "Please set up ${CONFIG} !"
  34. else
  35. ebegin "Starting tinc network ${NETNAME}"
  36. if [ "${SYSLOG}" = "yes" ]; then
  37. LOG=""
  38. else
  39. LOG="--logfile=/var/log/tinc.${NETNAME}.log"
  40. fi
  41. start-stop-daemon --start --exec "${DAEMON}" --pidfile "${PIDFILE}" -- --net="${NETNAME}" ${LOG} --pidfile "${PIDFILE}" --debug="${DEBUG_LEVEL}" ${EXTRA_OPTS}
  42. eend $?
  43. fi
  44. done
  45. }
  46. stop() {
  47. ebegin "Stopping tinc VPN networks"
  48. checkconfig || return 1
  49. for NETNAME in ${ALL_NETNAME}
  50. do
  51. PIDFILE="/run/tinc.${NETNAME}.pid"
  52. if [ -f "${PIDFILE}" ]; then
  53. ebegin "Stopping tinc network ${NETNAME}"
  54. start-stop-daemon --stop --pidfile "${PIDFILE}"
  55. eend $?
  56. fi
  57. done
  58. }
  59. reload() {
  60. ebegin "Reloading configuration for tinc VPN networks"
  61. checkconfig || return 1
  62. for NETNAME in ${ALL_NETNAME}
  63. do
  64. PIDFILE="/run/tinc.${NETNAME}.pid"
  65. if [ -f "${PIDFILE}" ]; then
  66. ebegin "Reloading tinc network ${NETNAME}"
  67. start-stop-daemon --signal HUP --pidfile ${PIDFILE}
  68. eend $?
  69. fi
  70. done
  71. }