AST_MAJOR_VERSION:=16
PKG_NAME:=asterisk$(AST_MAJOR_VERSION)
PKG_VERSION:=$(AST_MAJOR_VERSION).3.0
-PKG_RELEASE:=5
+PKG_RELEASE:=6
PKG_SOURCE:=asterisk-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://downloads.asterisk.org/pub/telephony/asterisk/releases
TITLE:=Complete open source PBX, v$(PKG_VERSION)
MENU:=1
DEPENDS:=$(CXX_DEPENDS) +jansson +libcap +libedit +libopenssl +libsqlite3 +libuuid +libxml2 +zlib
+ USERID:=asterisk=385:asterisk=385
endef
define Package/$(PKG_NAME)/description
/etc/asterisk/stasis.conf
/etc/asterisk/udptl.conf
/etc/asterisk/users.conf
-/etc/default/asterisk
+/etc/config/asterisk
/etc/init.d/asterisk
endef
$(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));)
$(INSTALL_DIR) $(1)/usr/share/asterisk/sounds/
- $(INSTALL_DIR) $(1)/etc/default
- $(INSTALL_DATA) ./files/asterisk.default $(1)/etc/default/asterisk
+ $(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/asterisk.init $(1)/etc/init.d/asterisk
+ $(INSTALL_CONF) ./files/asterisk.config $(1)/etc/config/asterisk
endef
define Package/$(PKG_NAME)-sounds
--- /dev/null
+
+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'
+
# Copyright (C) 2014 OpenWrt.org
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() {
- [ -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" \
- service_start $BIN_FILE $OPTIONS
-}
-stop() {
- SERVICE_PID_FILE="/var/run/asterisk/asterisk.pid" \
- service_stop $BIN_FILE
-}
+USE_PROCD=1
+
+#PROCD_DEBUG=1
+
+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
-reload() {
- SERVICE_PID_FILE="/var/run/asterisk/asterisk.pid" \
- service_reload $BIN_FILE
+ 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
}
+