~singpolyma/asterisk

1133eb1b6c28b0a2aabda8257f8d4afdab0c5b97 — Tzafrir Cohen 4 years ago aaf0401
A systemd service

Last-Update: 2016-04-02

Do away with safe_asterisk. But try very hard to let live_ast work with
it.

Gbp-Pq: Name systemd.patch
4 files changed, 107 insertions(+), 0 deletions(-)

M Makefile
A contrib/asterisk.service
A contrib/scripts/asterisk_cleanup
M contrib/scripts/live_ast
M Makefile => Makefile +2 -0
@@ 909,6 909,8 @@ install-logrotate:
	rm -f contrib/scripts/asterisk.logrotate.tmp

config:
	$(INSTALL) -d $(DESTDIR)/lib/systemd/system
	./build_tools/install_subst -d contrib/asterisk.service $(DESTDIR)/lib/systemd/system/asterisk.service
	@if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \
		./build_tools/install_subst contrib/init.d/rc.redhat.asterisk  "$(DESTDIR)/etc/rc.d/init.d/asterisk"; \
		if [ ! -f "$(DESTDIR)/etc/sysconfig/asterisk" ] ; then \

A contrib/asterisk.service => contrib/asterisk.service +49 -0
@@ 0,0 1,49 @@
[Unit]
Description=Asterisk PBX
Documentation=man:asterisk(8)
Wants=network-online.target
After=network-online.target

[Service]
Type=notify
ExecStart=__ASTERISK_SBIN_DIR__/asterisk -g -f -p -U asterisk
ExecReload=__ASTERISK_SBIN_DIR__/asterisk -rx 'core reload'
Restart=on-failure
RestartSec=1
WorkingDirectory=__ASTERISK_VARLIB_DIR__

# Extra settings:
# If you want to set them, you can add them to a file in the directory
# /lib/systemd/system/asterisk.service.d/ with the extension .conf.
# Example content:
#[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

A contrib/scripts/asterisk_cleanup => contrib/scripts/asterisk_cleanup +18 -0
@@ 0,0 1,18 @@
#!/bin/sh

# asterisk_cleanup: A script intended to optionally be run when Asterisk
# has exited. This example script is used to move core files.

VARLIBDIR=${VARLIBDIR:/var/lib/asterisk}
RUNDIR=${VARRUNDIR:/var/run/asterisk}
DUMPDROP=${DUMPDROP:-/var/spool/asterisk/cores}
ASTPIDFILE=${ASTVARRUNDIR}/asterisk.pid
PID=`cat ${ASTPIDFILE}`
DATE=`date "+%Y-%m-%dT%H:%M:%S%z"`
if test -f ${RUNDIR}/core.${PID} ; then
	mkdir -p "${DUMPDROP}"
	mv ${RUNDIR}/core.${PID} ${DUMPDROP}/core.`hostname`-$DATE &
elif test -f ${RUNDIR}/core ; then
	mkdir -p "${DUMPDROP}"
	mv ${RUNDIR}/core ${DUMPDROP}/core.`hostname`-$DATE &
fi

M contrib/scripts/live_ast => contrib/scripts/live_ast +38 -0
@@ 175,6 175,43 @@ gen_live_conf() {
  | sed  -e '/^#* \(Begin\|End\) Samples/d' >"$LIVE_CONF"
}

# (re?)generate a unit file that could be installed on the system to use
# this copy of Asterisk.
gen_ast_live_service() {
  local service_file="$BASE_DIR/asterisk-live.service"
  local included_dir='lib'
  local included_dir_remmed='etc'
  if [ -f /etc/systemd/system/asterisk.service ]; then
    included_dir='etc'
    included_dir_remmed='lib'
  fi
  local varlibdir=`awk '/astvarlibdir/ {print $3}' "$AST_CONF" | head -n1`
  cat <<EOF >"$service_file"
# This file is based on your existing asterisk systemd service unit, and
# overrides some fields. If you have an overriding unit in /etc, you
# need to include it, rather than the one in /lib:
.include /$included_dir/systemd/system/asterisk.service
#.include /$included_dir_remmed/systemd/system/asterisk.service

# This file is not installed. If you want to use it, you need to copy it
# to /etc/systemd/system and run 'systemctl daemon-reload'. You'll then
# need to be able to start this manually (note that it will not be
# enabled and thus the standard bash completion will not complete it).
# If you have multiple live asterisk instances you want to run on the
# same system, be sure to give each one a unique name.

[Unit]
Description = Asterisk PBX (Live Asterisk)

# Note: if you changed the parameters passed in the command-line (ExecStart)
# be sure to copy them over here as well.
[Service]
ExecStart = $BASE_DIR/asterisk g -f -p -U asterisk
ExecReload = $BASE_DIR/asterisk -rx 'core reload'
WorkingDirectory = $varlibdir
EOF
}

# (re?)generate the ./live/asterisk wrapper script
gen_live_asterisk() {
  cat <<EOF >"$BASE_DIR/asterisk"


@@ 244,6 281,7 @@ EOF
  chmod +x "$BASE_DIR/asterisk"
  # Generate a sample config file for live_ast itself:
  gen_live_conf
  gen_ast_live_service
  ;;
conf-file)
  # Just regenerate live.conf from the sample if it does not already exist: