diff --git a/recipes/net/strongswan.yaml b/recipes/net/strongswan.yaml index 03b2864b..dd1de533 100644 --- a/recipes/net/strongswan.yaml +++ b/recipes/net/strongswan.yaml @@ -1,4 +1,4 @@ -inherit: [autotools] +inherit: [autotools, init] metaEnvironment: PKG_VERSION: "6.0.0" @@ -30,6 +30,11 @@ buildScript: | --enable-botan=yes \ --enable-forecast=yes + # add init script + if initIsAnySysvinit; then + install -D -m 0755 $<@strongswan/S41strongswan.sh@> install/etc/init.d/S41strongswan.sh + fi + packageScript: | autotoolsPackageTgt diff --git a/recipes/net/strongswan/S41strongswan.sh b/recipes/net/strongswan/S41strongswan.sh new file mode 100755 index 00000000..aabca7a9 --- /dev/null +++ b/recipes/net/strongswan/S41strongswan.sh @@ -0,0 +1,58 @@ +#!/bin/sh +### BEGIN INIT INFO +# Short-Description: Start strongSwan VPN service +# Description: Start strongSwan and charon with swanctl configuration and delay. +### END INIT INFO + +DAEMON=/usr/libexec/ipsec/charon +SWANCTL=/usr/sbin/swanctl +NAME=strongswan +PIDFILE=/var/run/$NAME.pid +DELAY=10 # Delay in seconds + +#optional +# . /lib/lsb/init-functions + +do_start() { + log_daemon_msg "Starting $NAME service" + start-stop-daemon --start --quiet --background --pidfile $PIDFILE --exec $DAEMON || return 2 + + log_daemon_msg "Applying delay of $DELAY seconds" + sleep $DELAY + + log_daemon_msg "Loading swanctl configurations" + $SWANCTL --load-all || return 2 + + log_daemon_msg "Starting VPN connections" + $SWANCTL --initiate || return 2 + + log_end_msg 0 +} + +do_stop() { + log_daemon_msg "Stopping $NAME service" + start-stop-daemon --stop --quiet --pidfile $PIDFILE || return 2 + log_end_msg 0 +} + +case "$1" in + start) + do_start + ;; + stop) + do_stop + ;; + restart|force-reload) + do_stop + do_start + ;; + status) + status_of_proc -p $PIDFILE $DAEMON && exit 0 || exit $? + ;; + *) + echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|status}" + exit 1 + ;; +esac + +exit 0