baresip: add procd init script
- add procd init script - script starts the daemon as user "baresip" instead of root - add /etc/default/baresip - add example configuration into /etc/baresip - add conffiles definition - prevent autostart after upgrade by using ENABLE_BARESIP variable in /etc/default/baresip Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
This commit is contained in:
parent
1de3d36d4b
commit
8860618e41
3 changed files with 123 additions and 7 deletions
|
@ -65,6 +65,7 @@ define Package/baresip
|
|||
$(call Package/baresip/Default)
|
||||
TITLE:=Portable and modular SIP User-Agent with A/V support
|
||||
DEPENDS:=+libre +librem
|
||||
USERID:=$(PKG_NAME)=374:$(PKG_NAME)=374
|
||||
MENU:=1
|
||||
endef
|
||||
|
||||
|
@ -120,10 +121,38 @@ define Package/baresip/install
|
|||
$(1)/usr/lib/baresip/modules
|
||||
$(INSTALL_DIR) $(1)/usr/share/baresip
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/share/baresip/* $(1)/usr/share/baresip
|
||||
$(INSTALL_DIR) $(1)/etc/baresip
|
||||
$(INSTALL_CONF) $(PKG_BUILD_DIR)/docs/examples/{accounts,config,contacts} $(1)/etc/baresip
|
||||
$(INSTALL_DIR) $(1)/etc/default
|
||||
$(INSTALL_CONF) ./files/baresip.default $(1)/etc/default/baresip
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/baresip.init $(1)/etc/init.d/baresip
|
||||
endef
|
||||
|
||||
define Package/baresip/conffiles
|
||||
/etc/baresip/accounts
|
||||
/etc/baresip/config
|
||||
/etc/baresip/contacts
|
||||
/etc/default/baresip
|
||||
/etc/init.d/baresip
|
||||
endef
|
||||
|
||||
define Package/baresip/postinst
|
||||
#!/bin/sh
|
||||
if [ -z "$${IPKG_INSTROOT}" ]; then
|
||||
chown $(PKG_NAME):$(PKG_NAME) \
|
||||
/etc/baresip/accounts \
|
||||
/etc/baresip/config \
|
||||
/etc/baresip/contacts
|
||||
|
||||
# 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_BARESIP="yes"/s/^/#/' \
|
||||
/etc/default/$(PKG_NAME)
|
||||
fi
|
||||
exit 0
|
||||
endef
|
||||
|
||||
##################
|
||||
# bareSIP modules
|
||||
# 1. Name
|
||||
|
|
10
net/baresip/files/baresip.default
Normal file
10
net/baresip/files/baresip.default
Normal file
|
@ -0,0 +1,10 @@
|
|||
### bareSIP init configuration ###
|
||||
|
||||
# Uncomment once you verified your configuration, otherwise the init script will
|
||||
# not start bareSIP.
|
||||
#ENABLE_BARESIP="yes"
|
||||
|
||||
# The following is added to the command line when starting bareSIP:
|
||||
OPTIONS=""
|
||||
|
||||
# The configuration for the daemon is done in /etc/baresip!
|
|
@ -1,14 +1,91 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2010-2011 OpenWrt.org
|
||||
# Copyright (C) 2010 Alfred E. Heggestad
|
||||
#
|
||||
# Copyright (C) 2017 OpenWrt.org
|
||||
|
||||
START=92
|
||||
|
||||
start() {
|
||||
service_start /usr/bin/baresip -d
|
||||
USE_PROCD=1
|
||||
|
||||
#PROCD_DEBUG=1
|
||||
|
||||
DAEMON=baresip
|
||||
DEFAULT=/etc/default/$DAEMON
|
||||
LOGGER="/usr/bin/logger -p user.err -s -t $DAEMON"
|
||||
OPTIONS=
|
||||
PROG=/usr/bin/$DAEMON
|
||||
TIMEOUT=30
|
||||
|
||||
[ -f $DEFAULT ] && . $DEFAULT
|
||||
|
||||
start_service() {
|
||||
local dir=
|
||||
|
||||
if [ "$ENABLE_BARESIP" != yes ]; then
|
||||
$LOGGER User configuration incomplete - not starting $DAEMON
|
||||
$LOGGER Check ENABLE_BARESIP in $DEFAULT
|
||||
exit 1
|
||||
fi
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command $PROG
|
||||
procd_append_param command \
|
||||
-f /etc/$DAEMON \
|
||||
$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() {
|
||||
service_stop /usr/bin/baresip
|
||||
stop_service() {
|
||||
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 baresip 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