[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 1.8.32.3 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)
User=asterisk

> 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

Restart=on-failure

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
/usr/lib/systemd/system/asterisk.service


Here it is:

[Unit]
Description=Asterisk PBX
Documentation=man:asterisk(8)
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/usr/sbin/asterisk -g -f -U asterisk
ExecReload=/usr/sbin/asterisk -rx 'core reload'
Restart=on-failure
RestartSec=1
WorkingDirectory=/var/lib/asterisk

# 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
#[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.
#ExecStopPost=/path/to/script

#Nice=0
#UMask=0002
#LimitCORE=infinity
#LimitNOFILE=

# 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:
#TTYPath=/dev/tty9
#StandardInput=tty
#StandardOutput=tty
#StandardError=tty

# 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

[Install]
WantedBy=multi-user.target

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



More information about the asterisk-users mailing list