Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion recipes/net/strongswan.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
inherit: [autotools]
inherit: [autotools, init]

metaEnvironment:
PKG_VERSION: "6.0.0"
Expand Down Expand Up @@ -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

Expand Down
58 changes: 58 additions & 0 deletions recipes/net/strongswan/S41strongswan.sh
Original file line number Diff line number Diff line change
@@ -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