Advertisement
Guest User

Upstart_openvpn-autostart.conf

a guest
Jul 25th, 2015
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.28 KB | None | 0 0
  1. author "Mariusz Kaczmarczyk <mariusz@post.waw.pl>"
  2. description "OpenVPN connections initiator - starts configured connections"
  3. version "1.2"
  4.  
  5. start on runlevel [2345]
  6.  
  7. respawn
  8.  
  9. normal exit 0
  10.  
  11. console output
  12.  
  13. # defaults
  14. env AUTOSTART=''
  15. env CONFIG_DIR='/etc/openvpn'
  16. env CONFIG_EXT='.conf'
  17. env CONN_NAMES=''
  18. env DEFAULTS_FILE='/etc/default/openvpn'
  19.  
  20. pre-start script
  21.     # load global defaults file
  22.     if [ -f "${DEFAULTS_FILE}" ]; then
  23.         . "${DEFAULTS_FILE}"
  24.     fi
  25.     # list available connections to be run
  26.     if [ "${AUTOSTART}" = '*' ]; then
  27.         # list all connection files from the directory
  28.         cd "${CONFIG_DIR}/"
  29.         for T_FILE in $(ls -1 *"${CONFIG_EXT}"); do
  30.             CONN_NAMES=${CONN_NAMES}\ "${T_FILE%${CONFIG_EXT}}"
  31.         done
  32.     else
  33.         # assign list of named connections
  34.         CONN_NAMES=${AUTOSTART}
  35.     fi
  36.     # emit starting event for listed connections
  37.     for T_CONN_NAME in $CONN_NAMES; do
  38.         initctl emit openvpn-init-connections CONN="${T_CONN_NAME}"
  39.     done
  40. end script
  41.  
  42. script
  43.     # wait indefinitely to make Upstart happy and make job wait for stop command
  44.     while true; do
  45.         exec /bin/sleep 2147483647d
  46.     done
  47. end script
  48.  
  49. pre-stop script
  50.     # this has to be in pre-stop phase, as should only be run on manual job stop and not on kill
  51.     initctl emit openvpn-stop-connections
  52. end script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement