Hi I’ve been having the same slow shutdown issue as has been descirbed both here:
and here:
For clarity, I’m running FreePBX 17 on a VM (ESXi 8.3). My freepbx system was installed using the ISO provided by Sangoma.
As was pointed out by @utelit in the second link above, it appears that the problem seems to be more associated with how the freepbx service is started at boot vs how it actually shuts down. The rationale for this conclusion stems from the fact that so long as you restart freepbx at some time after the system boots, it will shut down normally. But, if you never restart it and simply try to shutdown (or reboot) the system, asterisk will hang until systemd hits its timeout and ultimately sends the sigkill signal some 2+ minutes later.
Further, it also appears that the hangup has something to do with mariadb. If, after booting up, I simply execute:
systemctl stop mariadb && shutdown
I can get the system to shut down in ~10 seconds.
To the best that I can tell, the problem seems to stem from the freepbx systemd service requiring that mariadb be running before it starts and also requiring that it be stopped before it stops. This goes against the default sequencing of systemd (e.g. That which starts earlier, stops later).
At any rate, I was able to create an override systemd drop-in file that makes things work as desired. See below.
The following commands need to be run as root, so prepend with ‘sudo’ or get to a root prompt.
- Create override drop-in systemd file
systemctl edit freepbx
- With the file open, add the following lines near the top. The file will tell you below and above which lines you need to place the new lines. BE SURE TO PUT THEM WHERE THE FILE INDICATES.
[Service]
ExecStartPre=/usr/bin/systemctl start mariadb
ExecStop=
ExecStop=/bin/sh -c '/usr/bin/kill -TERM $(/usr/bin/systemctl show --property MainPID --value mariadb)'
ExecStop=/usr/sbin/fwconsole stop
- Save the file and then reload systemd
systemctl daemon-reload
For those who are curious as to what this change is doing, essentially…
- ExecStop= clears the ExecStop command in the default service file. Without this, systemd will still try to stop freepbx before mariadb.
- The second ExecStop command stops mariadb and the third one stops freepbx.
- The ExecStartPre= command is now needed because without it, you cannot simply restart freepbx. In its absence, mariadb would be shutdown when freepbx shuts down, but it needs to be running when freepbx trys to start and there would be nothing telling it to do so.
At any rate, after doing this my system shut down in < 10 seconds vs 2.5+ minutes.
