baresip: Use UCI for basic service configuration 889/head
authorDaniel Danzberger <dd@embedd.com>
Mon, 18 Nov 2024 11:50:00 +0000 (12:50 +0100)
committerDaniel Danzberger <dd@embedd.com>
Mon, 6 Jan 2025 21:49:42 +0000 (22:49 +0100)
The baresip init script is changed to use UCI instead of the debian
style /etc/default basic service configuration.

A uci-defaults script is added to create a basic UCI config:
--
config baresip main
 option enable 0
 option options ''
--

With this change an issues is also resolved, on which the baresip
service doesn't start due to the baresip user not being the owner of
the /etc/baresip configuration directory.

Additionally a reload_config trigger is added for baresip.

Signed-off-by: Daniel Danzberger <dd@embedd.com>
net/baresip/Makefile
net/baresip/files/baresip.default [deleted file]
net/baresip/files/baresip.defaults [new file with mode: 0644]
net/baresip/files/baresip.init

index 00028839cec63dd2b874094b06000a83319245f9..66a0a4d5e5719c61d893f1a7f17e8e8141ff4117 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=baresip
 PKG_VERSION:=3.16.0
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=https://codeload.github.com/baresip/baresip/tar.gz/v$(PKG_VERSION)?
@@ -126,8 +126,8 @@ define Package/baresip/install
                        $(1)/usr/lib/baresip/modules \
                        $(1)/usr/share/baresip \
                        $(1)/etc/baresip \
-                       $(1)/etc/init.d \
-                       $(1)/etc/default
+                       $(1)/etc/uci-defaults \
+                       $(1)/etc/init.d
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/baresip $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/libbaresip.so* $(1)/usr/lib
        $(INSTALL_DATA) \
@@ -137,7 +137,7 @@ define Package/baresip/install
        $(SED) '/^#/!s/^/#/' $(PKG_BUILD_DIR)/docs/examples/accounts
        $(SED) '/^#module_path/s|^#||;s|/local||' $(PKG_BUILD_DIR)/docs/examples/config
        $(INSTALL_DATA) $(PKG_BUILD_DIR)/docs/examples/{accounts,config,contacts} $(1)/etc/baresip
-       $(INSTALL_CONF) ./files/baresip.default $(1)/etc/default/baresip
+       $(INSTALL_DATA) ./files/baresip.defaults $(1)/etc/uci-defaults/90-baresip
        $(INSTALL_BIN) ./files/baresip.init $(1)/etc/init.d/baresip
 endef
 
@@ -145,7 +145,6 @@ define Package/baresip/conffiles
 /etc/baresip/accounts
 /etc/baresip/config
 /etc/baresip/contacts
-/etc/default/baresip
 endef
 
 ##################
diff --git a/net/baresip/files/baresip.default b/net/baresip/files/baresip.default
deleted file mode 100644 (file)
index b251c80..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-### 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!
diff --git a/net/baresip/files/baresip.defaults b/net/baresip/files/baresip.defaults
new file mode 100644 (file)
index 0000000..7c1cd25
--- /dev/null
@@ -0,0 +1,12 @@
+CFGFILE=/etc/config/baresip
+
+if [ ! -f "$CFGFILE" ]; then
+       cat >$CFGFILE <<EOF
+config baresip main
+       option enable 0
+       option options ''
+EOF
+fi
+
+chown -R baresip:baresip /etc/baresip
+
index d48e5d60fcc42cac79b47386923004727705e772..4416e1e59ff4bb157abf2d1f798ac7c7173e21ca 100644 (file)
@@ -2,38 +2,27 @@
 # Copyright (C) 2017 OpenWrt.org
 
 START=92
-
 USE_PROCD=1
+PROG=/usr/bin/baresip
 
-#PROCD_DEBUG=1
-
-DAEMON=baresip
-DEFAULT=/etc/default/$DAEMON
-LOGGER="/usr/bin/logger -p user.err -s -t $DAEMON"
-OPTIONS=
-PROG=/usr/bin/$DAEMON
+start_service()
+{
+       local enable options
 
-[ -f $DEFAULT ] && . $DEFAULT
+       uci_validate_section baresip baresip main \
+               'enable:bool:0' \
+               'options:string'
 
-start_service() {
-  local dir=
+       [ "$enable" = "0" ] && return
 
-  if [ "$ENABLE_BARESIP" != yes ]; then
-    $LOGGER User configuration incomplete - not starting $DAEMON
-    $LOGGER Check ENABLE_BARESIP in $DEFAULT
-    return 1
-  fi
+       procd_open_instance
+       procd_set_param command $PROG -f /etc/baresip $options
+       procd_set_param user baresip
+       procd_set_param respawn
+       procd_close_instance
+}
 
-  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
+service_triggers()
+{
+       procd_add_reload_trigger baresip
 }