Cannot Connect to Asterisk message on GUI

Hi.

I am setting up new FreePBX from scratch on CentOS7 platform, and trying to set it up to start during boot time.

I am following below URL to create systemd startup script;

https://wiki.freepbx.org/display/FOP/Example+systemd+startup+script+for+FreePBX

however, I get Cannot Connect to Asterisk message on top-right corner of GUI whenever I reboot the server.

# systemctl status freepbx
● freepbx.service - FreePBX VoIP Server
Loaded: loaded (/etc/systemd/system/freepbx.service; enabled; vendor preset: disabled)
Active: deactivating (final-sigterm) (Result: exit-code)
Process: 1708 ExecStart=/usr/sbin/fwconsole start (code=exited, status=1/FAILURE)
Main PID: 1708 (code=exited, status=1/FAILURE)
CGroup: /system.slice/freepbx.service
└─1808 /usr/sbin/asterisk -f -U asterisk -G asterisk -vvvg -c

When I run asterisk -r from command line, below is the dump,

$ asterisk -r
Unable to connect to remote asterisk (does /var/run/asterisk/asterisk.ctl exist?)

and confirmed no files are under /var/run/asterisk/ directory.

If I perform sudo su && fwconsole stop && fwconsole chown && fwconsole start then I can observe FreePBX properly. (Red warning message disappear from GUI)

Just wondering why the recommended script is not working.
Any advice would be appreciated!

Platform

  • CentOS7 (Kernel: Linux 3.10.0-862.3.2.el7.x86_64)
  • FreePBX: 14.0.3.6
  • Asterisk: 13.21.1

Please disregard, in my case, I needed to define User=root in /etc/systemd/system/freepbx.service file. Once I added the line, worked like a charm. :wink:

[Unit]
Description=FreePBX VoIP Server
After=mariadb.service

[Service]
Type=oneshot
User=root
RemainAfterExit=yes
ExecStart=/usr/sbin/fwconsole start
ExecStop=/usr/sbin/fwconsole stop

[Install]
WantedBy=multi-user.target

I’m pretty sure that your

User=root

will not work unless your webserver is also running as root and that6 is a VERY, VERY bad idea

FreePBX needs asterisk to run as the same user as your webserver as and ‘root’ will spawn endless complaints and inability to use the FreePBX interface.

If you don’t understand systemd and FreePBX, please don’t be ‘clever’

Hi Dicko,
Thanks for your comment. I actually tried User=asterisk but I’ll get an error as below. (I ran it again with User=asterisk) For some reason, my system tells You need to be root to run this command.
If I don’t explicitly define User, asterisk won’t start, and if I define User=root the problem disappear away.

# systemctl status -l freepbx
● freepbx.service - FreePBX VoIP Server
Loaded: loaded (/etc/systemd/system/freepbx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2018-06-28 06:16:57 CDT; 36s ago
Process: 1748 ExecStart=/usr/sbin/fwconsole start (code=exited, status=1/FAILURE)
Main PID: 1748 (code=exited, status=1/FAILURE)

Jun 28 06:16:56 pbx systemd[1]: Starting FreePBX VoIP Server…
Jun 28 06:16:57 pbx fwconsole[1748]: You need to be root to run this command
Jun 28 06:16:57 pbx systemd[1]: freepbx.service: main process exited, code=exited, status=1/FAILURE
Jun 28 06:16:57 pbx systemd[1]: Failed to start FreePBX VoIP Server.
Jun 28 06:16:57 pbx systemd[1]: Unit freepbx.service entered failed state.
Jun 28 06:16:57 pbx systemd[1]: freepbx.service failed.

Below is the systemctl status dump, it looks to me both asterisk and FreePBX are brought up safely.

# systemctl status -l freepbx
● freepbx.service - FreePBX VoIP Server
Loaded: loaded (/etc/systemd/system/freepbx.service; enabled; vendor preset: disabled)
Active: active (exited) since Thu 2018-06-28 06:37:43 CDT; 6min ago
Process: 1706 ExecStart=/usr/sbin/fwconsole start (code=exited, status=0/SUCCESS)
Main PID: 1706 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/freepbx.service
├─1809 /bin/sh /usr/sbin/safe_asterisk -U asterisk -G asterisk
├─1813 /usr/sbin/asterisk -f -U asterisk -G asterisk -vvvg -c
├─1904 PM2 v2.10.1: God Daemon (/opt/app/home/asterisk/.pm2)
└─1954 node /var/www/html/admin/modules/ucp/node/index.js

Jun 28 06:37:42 pbx runuser[1944]: pam_unix(runuser:session): session opened for user asterisk by (uid=0)
Jun 28 06:37:42 pbx runuser[1962]: pam_unix(runuser:session): session opened for user asterisk by (uid=0)
Jun 28 06:37:42 pbx runuser[1980]: pam_unix(runuser:session): session opened for user asterisk by (uid=0)
Jun 28 06:37:42 pbx runuser[1980]: pam_unix(runuser:session): session closed for user asterisk
Jun 28 06:37:42 pbx fwconsole[1706]: [>---------------------------] < 1 sec
Jun 28 06:37:42 pbx runuser[1990]: pam_unix(runuser:session): session opened for user asterisk by (uid=0)
Jun 28 06:37:42 pbx runuser[2000]: pam_unix(runuser:session): session opened for user asterisk by (uid=0)
Jun 28 06:37:43 pbx runuser[2000]: pam_unix(runuser:session): session closed for user asterisk
Jun 28 06:37:43 pbx fwconsole[1706]: Started UCP Node Server. PID is 1954
Jun 28 06:37:43 pbx systemd[1]: Started FreePBX VoIP Server.

Well, as long as it works,

I personally would not have called that file asterisk.service , technically it should be named freepbx.service

It is already named as freepbx.service :wink:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.