packages/net/pptpd/files/pptpd.init
Rafał Miłecki b24601c128 pptpd: run service in foreground for procd compatibility
To have service working nicely with procd it should be running in the
foreground. Otherwise it's not possible to e.g. stop it with the init.d
script. Luckily for us pptpd has a simple switch that allows it.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Fixes: 15e7f611af ("pptpd: convert init script to procd")
2017-02-23 10:21:43 +01:00

72 lines
1.5 KiB
Bash

#!/bin/sh /etc/rc.common
# Copyright (C) 2015 OpenWrt.org
START=60
USE_PROCD=1
BIN=/usr/sbin/pptpd
CONFIG=/var/etc/pptpd.conf
CHAP_SECRETS=/var/etc/chap-secrets
OPTIONS_PPTP=/var/etc/options.pptpd
validate_login_section() {
uci_validate_section pptpd login "${1}" \
'username:string' \
'password:string'
}
validate_pptpd_section() {
uci_validate_section pptpd service "${1}" \
'enabled:uinteger' \
'localip:string' \
'remoteip:string' \
'mppe:list(string):required no40 no56 stateless' \
'logwtmp:uinteger'
}
setup_login() {
validate_login_section "${1}" || {
echo "validation failed"
return 1
}
[ -n "${username}" ] || return 0
[ -n "${password}" ] || return 0
echo "${username} pptp-server ${password} *" >> $CHAP_SECRETS
}
setup_config() {
local enabled localip remoteip mppe
validate_pptpd_section "${1}" || {
echo "validation failed"
return 1
}
[ "$enabled" -eq 0 ] && return 1
mkdir -p /var/etc
cp /etc/pptpd.conf $CONFIG
cp /etc/ppp/options.pptpd $OPTIONS_PPTP
[ -n "$localip" ] && echo "localip $localip" >> $CONFIG
[ -n "$remoteip" ] && echo "remoteip $remoteip" >> $CONFIG
[ "$logwtmp" -eq 1 ] && echo "logwtmp" >> $CONFIG
echo "mppe $(echo $mppe | sed -e 's/\s/,/g')" >> $OPTIONS_PPTP
return 0
}
start_service() {
config_load pptpd
setup_config pptpd || return
config_foreach setup_login login
ln -sfn $CHAP_SECRETS /etc/ppp/chap-secrets
procd_open_instance
procd_set_param command $BIN -c $CONFIG --fg -o $OPTIONS_PPTP
procd_close_instance
}