[asterisk-users] Proper way to start Asterisk on CentOS 7? (Carlos Chavez)

Tzafrir Cohen tzafrir.cohen at xorcom.com
Mon May 9 03:29:41 CDT 2016

On Mon, May 09, 2016 at 08:46:36AM +0200, Stefan Viljoen wrote:
> Hi Carlos
> I have experienced something similar starting Asterisk on Centos 7
> on commodity / whitebox hardware.
> The problem was that Asterisk was starting "too quickly" in the systemd
> startup sequence, before the required services it needs to run were up and
> ready.
> I eventually came up with this systemd script to start it, and this now
> starts Asterisk on all our our new Centos 7-using deployments.
> Maybe you can try it out...? This starts our Asterisk 1.8 instances without
> problems on Centos 7 on boot:
> --
> [Unit]
> Description=Asterisk
> After=network.target
> After=network-online.target
> After=startup.service

> After=mysql.service
> Wants=mysql.service

IIRC, mysql is socket activated, and hence services don't need to have
any explicit dependency on it Remove those two.

> [Service]
> Type=idle

Huh? Stick the the default: Type=basic. No need to mention this one.

> User=root
> Group=root

Those two are superfluous. And anyway, are wrong. Asterisk is a
network-facing daemon, and as such should run with it

# (Be sure to create that one)

> ExecStart=/usr/sbin/asterisk -f
> ExecStop=/usr/sbin/asterisk -rx 'core stop now'
> ExecReload=/usr/sbin/asterisk -rx 'core reload'

Right. But see my note below about Restart.

> TimeoutSec=300

Not sure what this is for.

> LimitCORE=infinity
> LimitNOFILE=8096
> Restart=always


With your current configuration:

  asterisk -rx 'core stop now'

becomes a restart.

> RestartSec=4

I used a bit less.

> [Install]
> WantedBy=multi-user.target
> --
> I place this in /etc/systemd/system as "asterisk.service" and then install
> it via
> systemctl enable asterisk.service

Fine. I placed mine as part of a package, and hence it is

Here it is:

Description=Asterisk PBX

ExecStart=/usr/sbin/asterisk -g -f -U asterisk
ExecReload=/usr/sbin/asterisk -rx 'core reload'

# Extra settings:
# If you want to set them, you can generate the file
# /etc/systemd/system/asterisk.service that has the following lines
# (without the comments)
#include /lib/systemd/system/asterisk.service
# and following those two lines add directives or override existing
# directives. Some extra directives that may be useful:

# You can run a script to clean up after asterisk. An example script is
# included in contrib/scripts/asterisk_cleanup.


# safe_asterisk runs Asterisk in a virtual console. This allows easy
# access to the asterisk command-line without logging it. on the other
# hand, it allows anyone with physical access to the console full access
# to Asterisk. To enable this console, unrem the following lines and add
# '-c' to the ExecStart line above:

# For more information on what these parameters mean see:
# http://0pointer.de/public/systemd-man/systemd.service.html
# http://0pointer.de/public/systemd-man/systemd.exec.html


               Tzafrir Cohen
icq#16849755              jabber:tzafrir.cohen at xorcom.com
+972-50-7952406           mailto:tzafrir.cohen at xorcom.com

More information about the asterisk-users mailing list