Select an alternative configuration folder

Hi all and have a nice year :smiley: !

I try to find a way to make Asterisk configure from a given
configuration folder. Thus I will have to simply switch between
configuration folders.

Default is /etc/asterisk. So I will copy it in /etc/asterisk_test1
then I will make some modifications and I will want to select it on the
next start of Asterisk.

I tried asterisk -C /etc/asterisk_test1/asterisk.conf configured with
the directive astetcdir => /etc/asterisk_test, but this does not
working.

asterisk \
  -C /etc/asterisk_test1/asterisk.conf \
  -x "core show settings" \
| grep /etc/asterisk
#>  Configuration file:          /etc/asterisk/asterisk.conf
#>  Configuration directory:     /etc/asterisk

=> it seems to do not care the config file I put.

But if I understand the man, -C is dedicated to this role.

I tried too to directly modify /etc/init.d/asterisk without more success.

How to accomplish it ?

Thank you in advance.

lnj

You have not shown the asterisk.conf in question. It is a common issue that the

(!)

is not removed from it, resulting in it not applying.

Hi and thank you for your help :smiley: !

You are right the [directories] context was a template, but after removing it and restarting the system the problem is not solved.

I precise this is a fresh Asterisk v22 on Debian 12 install (in virtual environment Qemu/KVM) to learn.

To obtain the test config folder I had copied with cp -a /etc/asterisk /etc/asterisk_test1, to have the same rights.

Here is the reduced effective configuration (the full file is attached to this post (6.3 KB)) :

grep -ivE "^([[:space:]]*;|$)" /etc/asterisk_test1/asterisk.conf 
#> [directories]
#> astcachedir => /var/cache/asterisk
#> astetcdir => /etc/asterisk_test1
#> astmoddir => /usr/lib/asterisk/modules
#> astvarlibdir => /var/lib/asterisk
#> astdbdir => /var/lib/asterisk
#> astkeydir => /var/lib/asterisk
#> astdatadir => /var/lib/asterisk
#> astagidir => /var/lib/asterisk/agi-bin
#> astspooldir => /var/spool/asterisk
#> astrundir => /var/run/asterisk
#> astlogdir => /var/log/asterisk
#> astsbindir => /usr/sbin
#> [options]
#> runuser = asterisk		; The user to run as.
#> rungroup = asterisk		; The group to run as.
#> documentation_language = en_US	; Set the language you want documentation

Too there is no references to the default folder from the copied folder :

grep -r /etc/asterisk /etc/asterisk_test1/
#> /etc/asterisk_test1/asterisk.conf:astetcdir => /etc/asterisk_test1
#> /etc/asterisk_test1/asterisk.conf:				; configuration files (/etc/asterisk) with a
#> /etc/asterisk_test1/cli_aliases.conf:;#include "/etc/asterisk/aliases"
#> /etc/asterisk_test1/resolver_unbound.conf:;ta_file = /etc/asterisk/dnssec_keys ; Full path to a trusted anchors key file. These keys are

Too I observed if I set a nonexistent user/group (here foo/bar) when I execute the console the good configuration file is parsed as it is indicated the bar group not exists :

asterisk -C /etc/asterisk_test1/asterisk.conf -d
#> Seeding global EID '52:54:00:26:83:4e' from 'lan' using 'siocgifhwaddr'
#> Parsing /etc/asterisk_test1/asterisk.conf
#> No such group 'bar'!

I restored the asterisk group and I started an interactive console to notice the next step parsed the logger.conf which seems working but the core seems to not seeing the new configuration :

asterisk -C /etc/asterisk_test1/asterisk.conf -rd
#> Seeding global EID '52:54:00:26:83:4e' from 'lan' using 'siocgifhwaddr'
#> Parsing /etc/asterisk_test1/asterisk.conf
#> ...
#> Running as user 'foo'
#> Running under group 'asterisk'
#> Connected to Asterisk 22.1.1 currently running on asterisk-22 (pid = 672)
#> Parsing /etc/asterisk_test1/logger.conf
#> Core debug was OFF and is now 1.
# asterisk-22*CLI> core show settings
#> ...
#>   Configuration file:          /etc/asterisk/asterisk.conf
#> ...

What is going on ?

How is Asterisk being started? What is the actual complete output of ā€œcore show settingsā€ for Directories?

Starting it up myself I am unable to reproduce it.

By default, as a service :

systemctl is-enabled asterisk
#> asterisk.service is not a native service, redirecting to systemd-sysv-install.
#> Executing: /lib/systemd/systemd-sysv-install is-enabled asterisk
#> enabled
asterisk -x "core show settings"
#> ...
#> * Directories
#>   -------------
#>   Configuration file:          /etc/asterisk/asterisk.conf
#>   Configuration directory:     /etc/asterisk
#>   Module directory:            /usr/lib/asterisk/modules
#>   Spool directory:             /var/spool/asterisk
#>   Log directory:               /var/log/asterisk
#>   Run/Sockets directory:       /var/run/asterisk
#>   PID file:                    /var/run/asterisk/asterisk.pid
#>   VarLib directory:            /var/lib/asterisk
#>   Data directory:              /var/lib/asterisk
#>   ASTDB:                       /var/lib/asterisk/astdb
#>   IAX2 Keys directory:         /var/lib/asterisk/keys
#>   AGI Scripts directory:       /var/lib/asterisk/agi-bin
#>   Cache directory:             /var/cache/asterisk
#> ...

Ah ok, but I do not know what extra information to give you :frowning:


In digging further, I found a workaround (or an alternate solution) :

grep -r /etc/asterisk /etc | grep -vE "^/etc/(asterisk|init.d)"
#> /etc/default/asterisk:#ALTCONF=/etc/asterisk/asterisk.conf

There is an alternate configuration variable then I tried it :

grep ALTCONF /etc/default/asterisk
#> #ALTCONF=/etc/asterisk/asterisk.conf
#> ALTCONF=/etc/asterisk_test1/asterisk.conf

systemctl restart asterisk ; systemctl status asterisk
#> ā— asterisk.service - LSB: Asterisk PBX
#>      Loaded: loaded (/etc/init.d/asterisk; generated)
#>      Active: active (running) since Tue 2025-01-28 16:33:37 CET; 13s ago
#>        Docs: man:systemd-sysv-generator(8)
#>     Process: 2490 ExecStart=/etc/init.d/asterisk start (code=exited, status=0/SUCCESS)
#>       Tasks: 80 (limit: 1107)
#>      Memory: 146.3M
#>         CPU: 2.763s
#>      CGroup: /system.slice/asterisk.service
#>              ā””ā”€2504 /usr/sbin/asterisk -U asterisk -G asterisk -C /etc/asterisk_test1/asterisk.conf
#> 
#> janv. 28 16:33:37 asterisk-22 systemd[1]: Starting asterisk.service - LSB: Asterisk PBX...
#> janv. 28 16:33:37 asterisk-22 asterisk[2490]: Starting Asterisk PBX: asterisk.
#> janv. 28 16:33:37 asterisk-22 systemd[1]: Started asterisk.service - LSB: Asterisk PBX.

# `-C /etc/asterisk_test1/asterisk.conf`, It smells good :) !

asterisk -x "core show settings" | grep /etc/asterisk
#>   Configuration file:          /etc/asterisk_test1/asterisk.conf
#>   Configuration directory:     /etc/asterisk_test1

# Good, good, good :D ...

grep -c 222 /etc/asterisk/pjsip.conf 
#> 0

grep -c 222 /etc/asterisk_test1/pjsip.conf 
#> 6

asterisk -x "pjsip list aors"
#> 
#>       Aor:  <Aor..............................................>  <MaxContact>
#> ==========================================================================================
#> 
#>       Aor:  222                                                100
#>       Aor:  333                                                100
#> 
#> Objects found: 2

# Yes :D ! I can call from 2 phones configured only in my alternate configuration

Finally the asterisk -C seems useless or broken ā€¦ and to be honest I do not understand in what providing an alternate configuration file (asterisk.conf) can modify the configuration of the running instance without explicitly restart it.

Have you an idea ?

It doesnā€™t modify the running daemon instance if using it as a console, it configures the Asterisk instance running for remote console so it knows where to look for certain things - specifically the Unix socket to connect to the specific running instance.

Not as clear as the capacity of my poor brain allows ā€¦ :frowning:

You say the role of the master configuration (-C) is not to give an alternate one, but only provide a few settings for a remote Asterisk instance ? That is right ?

Then my way to switch between configurations is it the good way to perform this ?

When Asterisk is started as a daemon providing -C will cause it to use that configuration for the running process.

When Asterisk is started as a remote console -C will cause that remote console to use the configuration for itself, to contact the appropriate Asterisk daemon.

I tried to stop Asterisk service and runnig it in a one-shot way.

systemctl stop asterisk ; systemctl is-active asterisk
#> inactive

asterisk -C /etc/asterisk_test1/asterisk.conf -cd
#> ...
#> Parsing /etc/asterisk_test1/asterisk.conf
#> Unable to access the running directory (Permission denied).  Changing to '/' for compatibility.
#> ...
#> Running as user 'asterisk'
#> Running under group 'asterisk'
#> Parsing /etc/asterisk/asterisk.conf
#> ...
# *CLI> core show settings
#> ...
#> * Directories
#>   -------------
#>   Configuration file:          /etc/asterisk_test1/asterisk.conf
#>   Configuration directory:     /etc/asterisk
#> ...

I do not know what to do with Unable to access the running directory. Which one directory is concerned ?

ls -l /etc | grep -E "d.+ asterisk"
#> drwxr-xr-x 2 asterisk asterisk  4096 28 janv. 15:38 asterisk
#> drwxr-xr-x 2 asterisk asterisk  4096 27 janv. 16:44 asterisk_init
#> drwxr-xr-x 2 asterisk asterisk  4096 28 janv. 17:44 asterisk_test1

I deduced from above all is good, then why this impossibility to access ?

Then we can see the first parsed file is the expected /etc/asterisk_test1/asterisk.conf but apparently it is overwritten by /etc/asterisk/asterisk.conf

Furthermore it is strange that the core sees the good configuration file (/etc/asterisk_test1/asterisk.conf) but not the good configuration directory (/etc/asterisk).

Is my one-shot way to start Asterisk with providing the configuration file is the good one ?

I use this workaround to switch between configurations :

ALTCONF=/etc/asterisk_test1/asterisk.conf ; \
asterisk_default=$( cat /etc/default/asterisk ) ; \
(
  echo -e "$asterisk_default\n" | grep -vE ^ALTCONF= ; 
  echo ALTCONF=$ALTCONF
) > /etc/default/asterisk ; \
systemctl restart asterisk

ALTCONF must contains the alternate configuration file which must defines the astetcdir directive in my case in the [directories] context :

cat /etc/asterisk_test1/asterisk.conf
#> [directories]
#> ...
#> astetcdir => /etc/asterisk_test1
#> ...

I do not want to close now because I want to know how to run Asterisk on demand with a given configuration ā€¦ If someone can clarify this :slight_smile: