asterisk-16.x: update init to procd (#421)
Converts the init script to procd. The user "asterisk" is added to the system. This user will be used by default. The init script no longer extracts its configuration from "/etc/default/asterisk". Instead the uci configuration "/etc/config/asterisk" is introduced. Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
This commit is contained in:
parent
803a6bb02f
commit
9b90b9ea78
4 changed files with 154 additions and 33 deletions
|
@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
|
||||||
AST_MAJOR_VERSION:=16
|
AST_MAJOR_VERSION:=16
|
||||||
PKG_NAME:=asterisk$(AST_MAJOR_VERSION)
|
PKG_NAME:=asterisk$(AST_MAJOR_VERSION)
|
||||||
PKG_VERSION:=$(AST_MAJOR_VERSION).3.0
|
PKG_VERSION:=$(AST_MAJOR_VERSION).3.0
|
||||||
PKG_RELEASE:=5
|
PKG_RELEASE:=6
|
||||||
|
|
||||||
PKG_SOURCE:=asterisk-$(PKG_VERSION).tar.gz
|
PKG_SOURCE:=asterisk-$(PKG_VERSION).tar.gz
|
||||||
PKG_SOURCE_URL:=https://downloads.asterisk.org/pub/telephony/asterisk/releases
|
PKG_SOURCE_URL:=https://downloads.asterisk.org/pub/telephony/asterisk/releases
|
||||||
|
@ -442,6 +442,7 @@ $(call Package/$(PKG_NAME)/Default)
|
||||||
TITLE:=Complete open source PBX, v$(PKG_VERSION)
|
TITLE:=Complete open source PBX, v$(PKG_VERSION)
|
||||||
MENU:=1
|
MENU:=1
|
||||||
DEPENDS:=$(CXX_DEPENDS) +jansson +libcap +libedit +libopenssl +libsqlite3 +libuuid +libxml2 +zlib
|
DEPENDS:=$(CXX_DEPENDS) +jansson +libcap +libedit +libopenssl +libsqlite3 +libuuid +libxml2 +zlib
|
||||||
|
USERID:=asterisk=385:asterisk=385
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/$(PKG_NAME)/description
|
define Package/$(PKG_NAME)/description
|
||||||
|
@ -470,7 +471,7 @@ define Package/$(PKG_NAME)/conffiles
|
||||||
/etc/asterisk/stasis.conf
|
/etc/asterisk/stasis.conf
|
||||||
/etc/asterisk/udptl.conf
|
/etc/asterisk/udptl.conf
|
||||||
/etc/asterisk/users.conf
|
/etc/asterisk/users.conf
|
||||||
/etc/default/asterisk
|
/etc/config/asterisk
|
||||||
/etc/init.d/asterisk
|
/etc/init.d/asterisk
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
@ -494,10 +495,10 @@ $(call Package/$(PKG_NAME)/install/sbin,$(1),astgenkey)
|
||||||
$(foreach m,$(AST_CFG_FILES),$(call Package/$(PKG_NAME)/install/conffile,$(1),$(m));)
|
$(foreach m,$(AST_CFG_FILES),$(call Package/$(PKG_NAME)/install/conffile,$(1),$(m));)
|
||||||
$(foreach m,$(AST_EMB_MODULES),$(call Package/$(PKG_NAME)/install/module,$(1),$(m));)
|
$(foreach m,$(AST_EMB_MODULES),$(call Package/$(PKG_NAME)/install/module,$(1),$(m));)
|
||||||
$(INSTALL_DIR) $(1)/usr/share/asterisk/sounds/
|
$(INSTALL_DIR) $(1)/usr/share/asterisk/sounds/
|
||||||
$(INSTALL_DIR) $(1)/etc/default
|
$(INSTALL_DIR) $(1)/etc/config
|
||||||
$(INSTALL_DATA) ./files/asterisk.default $(1)/etc/default/asterisk
|
|
||||||
$(INSTALL_DIR) $(1)/etc/init.d
|
$(INSTALL_DIR) $(1)/etc/init.d
|
||||||
$(INSTALL_BIN) ./files/asterisk.init $(1)/etc/init.d/asterisk
|
$(INSTALL_BIN) ./files/asterisk.init $(1)/etc/init.d/asterisk
|
||||||
|
$(INSTALL_CONF) ./files/asterisk.config $(1)/etc/config/asterisk
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/$(PKG_NAME)-sounds
|
define Package/$(PKG_NAME)-sounds
|
||||||
|
|
26
net/asterisk-16.x/files/asterisk.config
Normal file
26
net/asterisk-16.x/files/asterisk.config
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
config asterisk 'general'
|
||||||
|
option enabled '0'
|
||||||
|
# If you have problems running Asterisk as user "asterisk" we'd
|
||||||
|
# like to hear from you. Please raise an issue at:
|
||||||
|
# https://github.com/openwrt/telephony/issues
|
||||||
|
option user 'asterisk'
|
||||||
|
option group 'asterisk'
|
||||||
|
option log_stderr '1'
|
||||||
|
option log_stdout '1'
|
||||||
|
option options ''
|
||||||
|
|
||||||
|
config asterisk 'directories'
|
||||||
|
# The init script will only create below directories and update
|
||||||
|
# their permissions if they don't exist.
|
||||||
|
# Note: To change the default paths you need to update your
|
||||||
|
# "asterisk.conf" file.
|
||||||
|
option agidir '/usr/share/asterisk/agi-bin'
|
||||||
|
option datadir '/usr/share/asterisk'
|
||||||
|
option dbdir '/var/lib/asterisk/astdb'
|
||||||
|
option keydir '/usr/share/asterisk/keys'
|
||||||
|
option logdir '/var/log/asterisk'
|
||||||
|
option rundir '/var/run/asterisk'
|
||||||
|
option spooldir '/var/spool/asterisk'
|
||||||
|
option varlibdir '/var/lib/asterisk'
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
## startup options for /etc/init.d/asterisk
|
|
||||||
|
|
||||||
ENABLE_ASTERISK="yes"
|
|
||||||
OPTIONS=""
|
|
|
@ -2,32 +2,130 @@
|
||||||
# Copyright (C) 2014 OpenWrt.org
|
# Copyright (C) 2014 OpenWrt.org
|
||||||
|
|
||||||
START=99
|
START=99
|
||||||
APP=asterisk
|
|
||||||
OPTIONS=
|
|
||||||
DEST=
|
|
||||||
DEFAULT=$DEST/etc/default/$APP
|
|
||||||
BIN_FILE=$DEST/usr/sbin/$APP
|
|
||||||
PID_FILE=$DEST/var/run/$APP/$APP.pid
|
|
||||||
|
|
||||||
start() {
|
USE_PROCD=1
|
||||||
[ -f $DEFAULT ] && . $DEFAULT
|
|
||||||
[ -d $DEST/var/run/asterisk ] || mkdir -p $DEST/var/run/asterisk
|
|
||||||
[ -d $DEST/var/log/asterisk ] || mkdir -p $DEST/var/log/asterisk
|
|
||||||
[ -d $DEST/var/spool/asterisk ] || mkdir -p $DEST/var/spool/asterisk
|
|
||||||
[ -d $DEST/var/lib/asterisk ] || mkdir -p $DEST/var/lib/asterisk
|
|
||||||
[ -d $DEST/var/lib/asterisk/keys ] || mkdir -p $DEST/var/lib/asterisk/keys
|
|
||||||
[ -d $DEST/var/log/asterisk/cdr-csv ] || mkdir -p $DEST/var/log/asterisk/cdr-csv
|
|
||||||
|
|
||||||
SERVICE_PID_FILE="/var/run/asterisk/asterisk.pid" \
|
#PROCD_DEBUG=1
|
||||||
service_start $BIN_FILE $OPTIONS
|
|
||||||
|
NAME=asterisk
|
||||||
|
COMMAND=/usr/sbin/$NAME
|
||||||
|
|
||||||
|
LOGGER="/usr/bin/logger -p user.err -s -t $NAME --"
|
||||||
|
|
||||||
|
start_service() {
|
||||||
|
local enabled
|
||||||
|
|
||||||
|
local user
|
||||||
|
local group
|
||||||
|
|
||||||
|
local log_stderr
|
||||||
|
local log_stdout
|
||||||
|
|
||||||
|
local agidir
|
||||||
|
local cdrcsvdir
|
||||||
|
local datadir
|
||||||
|
local dbdir
|
||||||
|
local keydir
|
||||||
|
local logdir
|
||||||
|
local rundir
|
||||||
|
local spooldir
|
||||||
|
local varlibdir
|
||||||
|
|
||||||
|
local options
|
||||||
|
|
||||||
|
config_load $NAME
|
||||||
|
|
||||||
|
config_get_bool enabled general enabled 0
|
||||||
|
if [ $enabled -eq 0 ]; then
|
||||||
|
$LOGGER service not enabled in /etc/config/$NAME
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
config_get user general user $NAME
|
||||||
|
config_get group general group $NAME
|
||||||
|
|
||||||
|
user_exists "$user" || {
|
||||||
|
$LOGGER user \""$user"\" does not exist
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
group_exists "$group" || {
|
||||||
|
$LOGGER group \""$group"\" does not exist
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$user" = $NAME ]; then
|
||||||
|
if ! id -nG $NAME | grep -qwF dialout; then
|
||||||
|
group_exists dialout && group_add_user dialout $NAME
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
config_get_bool log_stderr general log_stderr 1
|
||||||
|
config_get_bool log_stdout general log_stdout 1
|
||||||
|
|
||||||
|
config_get agidir directories agidir /usr/share/$NAME/agi-bin
|
||||||
|
config_get datadir directories datadir /usr/share/$NAME
|
||||||
|
config_get dbdir directories dbdir /var/lib/$NAME/astdb
|
||||||
|
config_get keydir directories keydir /usr/share/$NAME/keys
|
||||||
|
config_get logdir directories logdir /var/log/$NAME
|
||||||
|
config_get rundir directories rundir /var/run/$NAME
|
||||||
|
config_get spooldir directories spooldir /var/spool/$NAME
|
||||||
|
config_get varlibdir directories varlibdir /var/lib/$NAME
|
||||||
|
|
||||||
|
config_get options general options
|
||||||
|
|
||||||
|
cdrcsvdir="${logdir}/cdr-csv"
|
||||||
|
|
||||||
|
# do not touch directories that already exist
|
||||||
|
# posix shell does not support arrays, hence using awk
|
||||||
|
awk \
|
||||||
|
-v user="$user" \
|
||||||
|
-v group="$group" \
|
||||||
|
-v a="$agidir" \
|
||||||
|
-v b="$cdrcsvdir" \
|
||||||
|
-v c="$datadir" \
|
||||||
|
-v d="$dbdir" \
|
||||||
|
-v e="$keydir" \
|
||||||
|
-v f="$logdir" \
|
||||||
|
-v g="$rundir" \
|
||||||
|
-v h="$spooldir" \
|
||||||
|
-v i="$varlibdir" \
|
||||||
|
'
|
||||||
|
BEGIN {
|
||||||
|
dir[0]=a
|
||||||
|
dir[1]=b
|
||||||
|
dir[2]=c
|
||||||
|
dir[3]=d
|
||||||
|
dir[4]=e
|
||||||
|
dir[5]=f
|
||||||
|
dir[6]=g
|
||||||
|
dir[7]=h
|
||||||
|
dir[8]=i
|
||||||
|
for (x in dir) {
|
||||||
|
if (system("test ! -e \"" dir[x] "\"" )) {
|
||||||
|
delete dir[x]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (x in dir) {
|
||||||
|
system("mkdir -p \"" dir[x] "\"" )
|
||||||
|
system("chmod 750 \"" dir[x] "\"" )
|
||||||
|
system("chown \"" user "\":\"" group "\" \"" dir[x] "\"" )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'
|
||||||
|
|
||||||
|
chown -R "$user":"$group" /etc/$NAME
|
||||||
|
|
||||||
|
procd_open_instance
|
||||||
|
procd_set_param command $COMMAND
|
||||||
|
procd_append_param command \
|
||||||
|
-G "$group" \
|
||||||
|
-U "$user" \
|
||||||
|
$options \
|
||||||
|
-f
|
||||||
|
# forward stderr to logd
|
||||||
|
procd_set_param stderr $log_stderr
|
||||||
|
# same for stdout
|
||||||
|
procd_set_param stdout $log_stdout
|
||||||
|
procd_close_instance
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
|
||||||
SERVICE_PID_FILE="/var/run/asterisk/asterisk.pid" \
|
|
||||||
service_stop $BIN_FILE
|
|
||||||
}
|
|
||||||
|
|
||||||
reload() {
|
|
||||||
SERVICE_PID_FILE="/var/run/asterisk/asterisk.pid" \
|
|
||||||
service_reload $BIN_FILE
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue