diff options
Diffstat (limited to 'community/stunnel/stunnel.initd')
-rw-r--r-- | community/stunnel/stunnel.initd | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/community/stunnel/stunnel.initd b/community/stunnel/stunnel.initd new file mode 100644 index 0000000000..6b8ab0335b --- /dev/null +++ b/community/stunnel/stunnel.initd @@ -0,0 +1,55 @@ +#!/sbin/openrc-run + +instance_name="${SVCNAME#*.}" +instance_name="${instance_name:-stunnel}" +config_file="${STUNNEL_CONFIGFILE:-/etc/stunnel/$instance_name.conf}" + +extra_started_commands="reload" + +command="/usr/bin/stunnel" +command_args="$config_file $STUNNEL_OPTIONS" +pidfile="/run/stunnel/$instance_name.pid" # default value + +required_files="$config_file" + + +depend() { + need net + before logger +} + +start_pre() { + pidfile=$(config_get "pid" "$pidfile") + + local chroot_dir=$(config_get "chroot") + [ -z "$chroot_dir" ] || start_stop_daemon_args="--chroot $chroot_dir" + + local user=$(config_get "setuid" "stunnel") + local group=$(config_get "setgid" "stunnel") + + checkpath -d -m 0775 -o root:$group /run/stunnel + + if [ ! "$(dirname "$pidfile")" -ef "/run" ]; then + checkpath -d -m 0755 -o $user:$group "$(dirname "$pidfile")" + fi +} + +stop_pre() { + pidfile=$(config_get "pid" "$pidfile") +} + +reload() { + pidfile=$(config_get "pid" "$pidfile") + + ebegin "Reloading $SVCNAME" + start-stop-daemon --signal HUP --pidfile "$pidfile" --name stunnel + eend $? +} + +config_get() { + local key="$1" + local default="${2:-}" + + local val="$(sed -En "s|^$key\s*=\s*(.*)\s*$|\1|p" "$config_file")" + echo "${val:-$default}" +} |