openconnect.init.in-r4 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2015 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. VPN="${RC_SVCNAME#*.}"
  5. VPNDIR="/etc/openconnect/${VPN}"
  6. VPNLOG="/var/log/openconnect/${VPN}"
  7. VPNLOGFILE="${VPNLOG}/openconnect.log"
  8. VPNERRFILE="${VPNLOG}/openconnect.err"
  9. command="/usr/sbin/openconnect"
  10. name="OpenConnect: ${VPN}"
  11. pidfile="/run/openconnect/${VPN}.pid"
  12. stopsig="SIGINT"
  13. depend() {
  14. before netmount
  15. }
  16. checkconfig() {
  17. if [ $VPN = "openconnect" ]; then
  18. eerror "You cannot call openconnect directly. You must create a symbolic link to it with the vpn name:"
  19. eerror
  20. eerror "ln -s /etc/init.d/openconnect /etc/init.d/openconnect.vpn0"
  21. eerror
  22. eerror "And then call it instead:"
  23. eerror
  24. eerror "/etc/init.d/openconnect.vpn0 start"
  25. return 1
  26. fi
  27. }
  28. checktuntap() {
  29. if [ "$RC_UNAME" = "Linux" -a ! -e /dev/net/tun ] ; then
  30. if ! modprobe tun ; then
  31. eerror "TUN/TAP support is not available in this kernel"
  32. return 1
  33. fi
  34. fi
  35. }
  36. run_hook() {
  37. if [ -x "$1" ]; then
  38. "$@"
  39. fi
  40. }
  41. start_pre() {
  42. checkconfig || return
  43. checktuntap || return
  44. checkpath -d "${VPNLOG}" || return
  45. checkpath -d /run/openconnect || return
  46. run_hook "${VPNDIR}/preup.sh"
  47. }
  48. start() {
  49. local server vpnopts password
  50. eval server=\$server_${VPN}
  51. eval vpnopts=\$vpnopts_${VPN}
  52. eval password=\$password_${VPN}
  53. ebegin "Starting ${name}"
  54. start-stop-daemon --start --exec "${command}" -- \
  55. --background \
  56. --interface="${VPN}" \
  57. --pid-file="${pidfile}" \
  58. ${vpnopts} \
  59. "${server}" \
  60. >> "${VPNLOGFILE}" \
  61. 2>> "${VPNERRFILE}" \
  62. <<EOF
  63. ${password}
  64. EOF
  65. eend $?
  66. }
  67. start_post() {
  68. run_hook "${VPNDIR}/postup.sh"
  69. }
  70. stop_pre() {
  71. checkconfig || return
  72. run_hook "${VPNDIR}/predown.sh"
  73. }
  74. stop_post() {
  75. run_hook "${VPNDIR}/postdown.sh"
  76. }