restund: add procd init script
- add procd init script - script starts the daemon as user "restund" instead of root - add /etc/default/restund - declare /etc/init.d/restund a configuration file - prevent autostart after upgrade by using ENABLE_RESTUND variable in /etc/default/restund Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
This commit is contained in:
parent
4219368092
commit
1de3d36d4b
3 changed files with 110 additions and 8 deletions
|
@ -39,6 +39,7 @@ define Package/restund
|
||||||
$(call Package/restund/Default)
|
$(call Package/restund/Default)
|
||||||
TITLE:=Modular STUN/TURN server
|
TITLE:=Modular STUN/TURN server
|
||||||
DEPENDS:=+libre
|
DEPENDS:=+libre
|
||||||
|
USERID:=$(PKG_NAME)=373:$(PKG_NAME)=373
|
||||||
endef
|
endef
|
||||||
|
|
||||||
restund-mod-mysql:=USE_MYSQL
|
restund-mod-mysql:=USE_MYSQL
|
||||||
|
@ -78,14 +79,31 @@ define Package/restund/install
|
||||||
$(SED) \
|
$(SED) \
|
||||||
's|^\(module_path\)\([ \t]\+\).*$$$$|\1\2/usr/lib/restund/modules|g' \
|
's|^\(module_path\)\([ \t]\+\).*$$$$|\1\2/usr/lib/restund/modules|g' \
|
||||||
$(1)/etc/restund.conf
|
$(1)/etc/restund.conf
|
||||||
|
$(INSTALL_DIR) $(1)/etc/default
|
||||||
|
$(INSTALL_CONF) ./files/restund.default $(1)/etc/default/restund
|
||||||
$(INSTALL_DIR) $(1)/etc/init.d
|
$(INSTALL_DIR) $(1)/etc/init.d
|
||||||
$(INSTALL_BIN) ./files/restund.init $(1)/etc/init.d/restund
|
$(INSTALL_BIN) ./files/restund.init $(1)/etc/init.d/restund
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/restund/conffiles
|
define Package/restund/conffiles
|
||||||
|
/etc/default/restund
|
||||||
|
/etc/init.d/restund
|
||||||
/etc/restund.conf
|
/etc/restund.conf
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
define Package/restund/postinst
|
||||||
|
#!/bin/sh
|
||||||
|
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||||
|
chown $(PKG_NAME):$(PKG_NAME) /etc/restund.conf
|
||||||
|
|
||||||
|
# Prevent $(PKG_NAME) from auto-starting after an upgrade. The modules may
|
||||||
|
# not be upgraded yet and the user configuration may need a revision.
|
||||||
|
sed -i '/^ENABLE_RESTUND="yes"/s/^/#/' \
|
||||||
|
/etc/default/$(PKG_NAME)
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
endef
|
||||||
|
|
||||||
#
|
#
|
||||||
# 1. Name
|
# 1. Name
|
||||||
# 2. Title
|
# 2. Title
|
||||||
|
|
8
net/restund/files/restund.default
Normal file
8
net/restund/files/restund.default
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
### restund init configuration ###
|
||||||
|
|
||||||
|
# Uncomment once you verified your configuration, otherwise the init script will
|
||||||
|
# not start restund.
|
||||||
|
#ENABLE_RESTUND="yes"
|
||||||
|
|
||||||
|
# The following is added to the command line when starting restund:
|
||||||
|
OPTIONS=""
|
|
@ -1,15 +1,91 @@
|
||||||
#!/bin/sh /etc/rc.common
|
#!/bin/sh /etc/rc.common
|
||||||
#
|
# Copyright (C) 2017 OpenWrt.org
|
||||||
# Copyright (C) 2010-2011 OpenWrt.org
|
|
||||||
# Copyright (C) 2010 Alfred E. Heggestad
|
|
||||||
#
|
|
||||||
|
|
||||||
START=60
|
START=60
|
||||||
|
|
||||||
start() {
|
USE_PROCD=1
|
||||||
service_start /usr/sbin/restund
|
|
||||||
|
#PROCD_DEBUG=1
|
||||||
|
|
||||||
|
DAEMON=restund
|
||||||
|
DEFAULT=/etc/default/$DAEMON
|
||||||
|
LOGGER="/usr/bin/logger -p user.err -s -t $DAEMON"
|
||||||
|
OPTIONS=
|
||||||
|
PROG=/usr/sbin/$DAEMON
|
||||||
|
TIMEOUT=30
|
||||||
|
|
||||||
|
[ -f $DEFAULT ] && . $DEFAULT
|
||||||
|
|
||||||
|
start_service() {
|
||||||
|
local dir=
|
||||||
|
|
||||||
|
if [ "$ENABLE_RESTUND" != yes ]; then
|
||||||
|
$LOGGER User configuration incomplete - not starting $DAEMON
|
||||||
|
$LOGGER Check ENABLE_RESTUND in $DEFAULT
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
procd_open_instance
|
||||||
|
procd_set_param command $PROG
|
||||||
|
procd_append_param command \
|
||||||
|
-n \
|
||||||
|
$OPTIONS
|
||||||
|
procd_set_param pidfile /var/run/${DAEMON}.pid
|
||||||
|
# forward stderr to logd
|
||||||
|
procd_set_param stderr 1
|
||||||
|
# forward stdout to logd
|
||||||
|
procd_set_param stdout 1
|
||||||
|
procd_set_param user $DAEMON
|
||||||
|
procd_close_instance
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop_service() {
|
||||||
service_stop /usr/sbin/restund
|
local retval=
|
||||||
|
local mypid=
|
||||||
|
local timeout=$TIMEOUT
|
||||||
|
|
||||||
|
pgrep $DAEMON &> /dev/null
|
||||||
|
[ $? -ne 0 ] && exit 0
|
||||||
|
|
||||||
|
[ -f /var/run/${DAEMON}.pid ]
|
||||||
|
retval=$?
|
||||||
|
|
||||||
|
# init script could find itself in a scenario where restund was started
|
||||||
|
# very recently, so make it wait a while for a pid file to appear
|
||||||
|
while [ $retval -ne 0 -a $timeout -gt 0 ]; do
|
||||||
|
sleep 1
|
||||||
|
[ -f /var/run/${DAEMON}.pid ]
|
||||||
|
retval=$?
|
||||||
|
timeout=$(($timeout-1))
|
||||||
|
done
|
||||||
|
|
||||||
|
[ $retval -eq 0 ] || {
|
||||||
|
$LOGGER PID file does not exist
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
mypid=$(cat /var/run/${DAEMON}.pid)
|
||||||
|
|
||||||
|
[ "$mypid" -gt 1 ] 2> /dev/null || {
|
||||||
|
$LOGGER PID file contains garbage
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
timeout=$TIMEOUT
|
||||||
|
kill $mypid 2>/dev/null
|
||||||
|
pgrep $DAEMON | grep -w $mypid &>/dev/null
|
||||||
|
retval=$?
|
||||||
|
|
||||||
|
while [ $retval -eq 0 -a $timeout -gt 0 ]; do
|
||||||
|
sleep 10
|
||||||
|
pgrep $DAEMON | grep -w $mypid &>/dev/null
|
||||||
|
retval=$?
|
||||||
|
[ $retval -eq 0 ] && kill $mypid 2>/dev/null
|
||||||
|
timeout=$(($timeout-10))
|
||||||
|
done
|
||||||
|
|
||||||
|
[ $retval -ne 1 ] && {
|
||||||
|
$LOGGER Failed to stop $DAEMON
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue