Systemctl start asterisk is fail with 'timeout'

I installed asterisk 16.5.1 in CentOS 8 with mariadb 10.3.11
after installing complete, execute command “systemctl start asterisk”

[root@localhost system]# cat /usr/lib/systemd/system/asterisk.service
Description=Asterisk PBX and telephony daemon.

ExecStart=/usr/sbin/asterisk -mqf -C /etc/asterisk/asterisk.conf
ExecReload=/usr/sbin/asterisk -rx ‘core reload’

in log file, /var/log/message

Oct 2 16:38:23 localhost systemd[1]: Starting Asterisk PBX and telephony daemon…
Oct 2 16:39:54 localhost systemd[1]: asterisk.service: Start operation timed out. Terminating.
Oct 2 16:39:54 localhost systemd[1]: asterisk.service: Failed with result ‘timeout’.
Oct 2 16:39:54 localhost systemd[1]: Failed to start Asterisk PBX and telephony daemon…
Oct 2 16:39:58 localhost systemd[1]: asterisk.service: Service RestartSec=4s expired, scheduling restart.
Oct 2 16:39:58 localhost systemd[1]: asterisk.service: Scheduled restart job, restart counter is at 1.

but, If i ran command - “/usr/sbin/asterisk -C /etc/asterisk/asterisk.conf”, It works well
where do i find cause ?

In the logs created by the failing Asterisk.

If you compiled and installed from source, check <sourcedir>/include/asterisk/autoconfig.h around line 1055 and make sure that systemd support is enabled…

/* Define if your system has the SYSTEMD libraries. */
#define HAVE_SYSTEMD 1

If not, you may need to install the systemd-devel package then re-run ./configure and make.


Thanks for your reply!

I installed systemd-devel package and recompile asterisk 16.5.1 on CentOS 8.0

after compiling, i configured something like this…

sed -i ‘s/;runuser = asterisk/runuser = ippbx/g’ /etc/asterisk/asterisk.conf;
sed -i ‘s/;rungroup = asterisk/rungroup = ippbx/g’ /etc/asterisk/asterisk.conf

chown -Rc ippbx:ippbx /etc/asterisk;
chown -Rc ippbx:ippbx /var/log/asterisk;
chown -Rc ippbx:ippbx /var/run/asterisk;
chown -Rc ippbx:ippbx /var/lib/asterisk

and then configure auto start like this

cd /home/ippbx/PKG/5.Asterisk/asterisk-16.5.1
cp -f ./contrib/systemd/asterisk* /usr/lib/systemd/system/

and change asterisk user ( asterisk to ippbx )
sed -i ‘s/User=asterisk/User=ippbx/g’ /usr/lib/systemd/system/asterisk.service;
sed -i ‘s/Group=asterisk/Group=ippbx/g’ /usr/lib/systemd/system/asterisk.service

systemctl enable asterisk

finally I reboot system and check asterisk process…

[ippbx@localhost run] ps -ef | grep asterisk ippbx 894 1 0 11:36 ? 00:00:02 /usr/sbin/asterisk -mqf -C /etc/asterisk/asterisk.conf ippbx 1958 1841 0 11:48 pts/1 00:00:00 grep --color=auto asterisk [ippbx@localhost run]
[ippbx@localhost run] [ippbx@localhost run] systemctl status asterisk
● asterisk.service - Asterisk PBX and telephony daemon.
Loaded: loaded (/usr/lib/systemd/system/asterisk.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2019-10-07 11:36:35 KST; 12min ago
Main PID: 894 (asterisk)
Tasks: 68 (limit: 11183)
Memory: 154.5M
CGroup: /system.slice/asterisk.service
└─894 /usr/sbin/asterisk -mqf -C /etc/asterisk/asterisk.conf

BUT, I found issue
I CAN NOT found directory, /var/run/asterisk <-- ( as /etc/asterisk/asterisk.conf’s astrundir )
I recreate /var/run/asterisk like this

[root@localhost run]# pwd
[root@localhost run]# ll
합계 28
drwxr-xr-x 3 root root 60 10월 7 11:36 NetworkManager
-rw------- 1 root root 0 10월 7 11:36 agetty.reload
drwxr-xr-x 2 ippbx ippbx 40 10월 7 11:53 asterisk

and then, I reboot system.
But Asterisk run directory(/var/run/asterisk) was deleted. I can’t found
where did I check ?

Asterisk will try and create /var/run/asterisk if it doesn’t already exist but it can’t do that if it’s started as a non-root user, in your case “ippbx”. There are several ways to solve this…

  1. Remove the User and Group lines from the service file so Asterisk starts as root. This will allow it to create the /var/run/asterisk directory before it switches over to the user and group specified in asterisk.conf.

  2. Use ExecStartPre commands in the service file to create the directory and set its ownership to ippbx/ippbx.

  3. Create a file named /etc/tmpfiles.d/asterisk.conf with the following line in it then run
    sudo systemd-tmpfiles --create. The directory will then get created every time the system starts.

   d /var/run/asterisk 0755 ippbx ippbx

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