FreePBX / issue-tracker

The unified FreePBX issue tracker.
https://www.freepbx.org
GNU General Public License v3.0
8 stars 1 forks source link

[improvement]: Allow customization of Asterisk start/stop commands #461

Open JoseGoncalves opened 2 days ago

JoseGoncalves commented 2 days ago

FreePBX Version

FreePBX 17

Improvement Description

If someone builds/packs it's own Asterisk, or uses some pre-built Asterisk packages (like the ones provided by Debian), it will most probably have a systemd service file that he can use to start/stop Asterisk.

In those situations, it will be a nice addition if someone that starts/stops Asterisk via fwconsole start/stop/restart commands will downwards cause the invocation of systemctl start/stop/restart asterisk.service commands.

I've successfully tested using systemctl to start/stop Asterisk in my system with these patches to FreePBX libraries:

--- /var/www/html/admin/libraries/Console/Stop.class.php.original   2024-09-23 13:46:33.000000000 +0100
+++ /var/www/html/admin/libraries/Console/Stop.class.php    2024-09-28 09:46:59.499995385 +0100
@@ -231,7 +231,7 @@
                $sastbin = '/usr/bin/env killall safe_asterisk > /dev/null 2>&1';
                exec($sastbin);
            case "gracefully":
-               $astbin = '/usr/bin/env asterisk -rx "core stop ' . $method .'" &>/dev/null &';
+               $astbin = '/usr/bin/env systemctl stop asterisk.service &>/dev/null &';
                shell_exec($astbin);
            break;
        }
--- /var/www/html/admin/libraries/Console/Start.class.php.original  2024-09-23 13:46:33.000000000 +0100
+++ /var/www/html/admin/libraries/Console/Start.class.php   2024-09-28 09:46:46.144479080 +0100
@@ -169,7 +169,7 @@

    private function startAsterisk($output){
        $output->writeln(_('Starting Asterisk...'));
-       $astbin = '/usr/bin/env safe_asterisk -U '.\FreePBX::Config()->get('AMPASTERISKUSER').' -G '.\FreePBX::Config()->get('AMPASTERISKGROUP').' > /dev/null 2>&1 &';
+       $astbin = '/usr/bin/env systemctl start asterisk.service > /dev/null 2>&1 &';
        $process = Process::fromShellCommandline($astbin);
        $env = $this->getDefaultEnv();
        if(empty($env['TERM'] ?? '')) {

My suggestion would be to add a config variable to /etc/freepbx.conf that would control which commands are used to start/stop Asterisk gracefully.

By default, the old behaviour of stopping with asterisk -rx "core stop gracefully" and starting with safe_asterisk would be used.

When that new config variable was set to a value that would cause the usage of the new start/stop commands, systemctl would be used to start/stop Asterisk.