Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JoseGoncalves opened this issue Sep 28, 2024 · 0 comments
Open
Labels
improvement improvement triage Triage

Comments

@JoseGoncalves
Copy link

JoseGoncalves commented Sep 28, 2024

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.

@JoseGoncalves JoseGoncalves added improvement improvement triage Triage labels Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement improvement triage Triage
Projects
None yet
Development

No branches or pull requests

1 participant