| 1 | Description: A systemd service |
| 2 | Do away with safe_asterisk, |
| 3 | but try very hard to let live_ast work with it. |
| 4 | Author: Tzafrir Cohen <[email protected]> |
| 5 | Last-Update: 2022-01-22 |
| 6 | --- |
| 7 | This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ |
| 8 | --- a/contrib/scripts/live_ast |
| 9 | +++ b/contrib/scripts/live_ast |
| 10 | @@ -175,6 +175,43 @@ |
| 11 | | sed -e '/^#* \(Begin\|End\) Samples/d' >"$LIVE_CONF" |
| 12 | } |
| 13 | |
| 14 | +# (re?)generate a unit file that could be installed on the system to use |
| 15 | +# this copy of Asterisk. |
| 16 | +gen_ast_live_service() { |
| 17 | + local service_file="$BASE_DIR/asterisk-live.service" |
| 18 | + local included_dir='lib' |
| 19 | + local included_dir_remmed='etc' |
| 20 | + if [ -f /etc/systemd/system/asterisk.service ]; then |
| 21 | + included_dir='etc' |
| 22 | + included_dir_remmed='lib' |
| 23 | + fi |
| 24 | + local varlibdir=`awk '/astvarlibdir/ {print $3}' "$AST_CONF" | head -n1` |
| 25 | + cat <<EOF >"$service_file" |
| 26 | +# This file is based on your existing asterisk systemd service unit, and |
| 27 | +# overrides some fields. If you have an overriding unit in /etc, you |
| 28 | +# need to include it, rather than the one in /lib: |
| 29 | +.include /$included_dir/systemd/system/asterisk.service |
| 30 | +#.include /$included_dir_remmed/systemd/system/asterisk.service |
| 31 | + |
| 32 | +# This file is not installed. If you want to use it, you need to copy it |
| 33 | +# to /etc/systemd/system and run 'systemctl daemon-reload'. You'll then |
| 34 | +# need to be able to start this manually (note that it will not be |
| 35 | +# enabled and thus the standard bash completion will not complete it). |
| 36 | +# If you have multiple live asterisk instances you want to run on the |
| 37 | +# same system, be sure to give each one a unique name. |
| 38 | + |
| 39 | +[Unit] |
| 40 | +Description = Asterisk PBX (Live Asterisk) |
| 41 | + |
| 42 | +# Note: if you changed the parameters passed in the command-line (ExecStart) |
| 43 | +# be sure to copy them over here as well. |
| 44 | +[Service] |
| 45 | +ExecStart = $BASE_DIR/asterisk g -f -p -U asterisk |
| 46 | +ExecReload = $BASE_DIR/asterisk -rx 'core reload' |
| 47 | +WorkingDirectory = $varlibdir |
| 48 | +EOF |
| 49 | +} |
| 50 | + |
| 51 | # (re?)generate the ./live/asterisk wrapper script |
| 52 | gen_live_asterisk() { |
| 53 | cat <<EOF >"$BASE_DIR/asterisk" |
| 54 | @@ -244,6 +281,7 @@ |
| 55 | chmod +x "$BASE_DIR/asterisk" |
| 56 | # Generate a sample config file for live_ast itself: |
| 57 | gen_live_conf |
| 58 | + gen_ast_live_service |
| 59 | ;; |
| 60 | conf-file) |
| 61 | # Just regenerate live.conf from the sample if it does not already exist: |
| 62 | --- /dev/null |
| 63 | +++ b/contrib/scripts/asterisk_cleanup |
| 64 | @@ -0,0 +1,18 @@ |
| 65 | +#!/bin/sh |
| 66 | + |
| 67 | +# asterisk_cleanup: A script intended to optionally be run when Asterisk |
| 68 | +# has exited. This example script is used to move core files. |
| 69 | + |
| 70 | +VARLIBDIR=${VARLIBDIR:/var/lib/asterisk} |
| 71 | +RUNDIR=${VARRUNDIR:/var/run/asterisk} |
| 72 | +DUMPDROP=${DUMPDROP:-/var/spool/asterisk/cores} |
| 73 | +ASTPIDFILE=${ASTVARRUNDIR}/asterisk.pid |
| 74 | +PID=`cat ${ASTPIDFILE}` |
| 75 | +DATE=`date "+%Y-%m-%dT%H:%M:%S%z"` |
| 76 | +if test -f ${RUNDIR}/core.${PID} ; then |
| 77 | + mkdir -p "${DUMPDROP}" |
| 78 | + mv ${RUNDIR}/core.${PID} ${DUMPDROP}/core.`hostname`-$DATE & |
| 79 | +elif test -f ${RUNDIR}/core ; then |
| 80 | + mkdir -p "${DUMPDROP}" |
| 81 | + mv ${RUNDIR}/core ${DUMPDROP}/core.`hostname`-$DATE & |
| 82 | +fi |
| 83 | --- /dev/null |
| 84 | +++ b/contrib/asterisk.service |
| 85 | @@ -0,0 +1,55 @@ |
| 86 | +[Unit] |
| 87 | +Description=Asterisk PBX |
| 88 | +Documentation=man:asterisk(8) |
| 89 | +Wants=network-online.target |
| 90 | +After=network-online.target |
| 91 | + |
| 92 | +[Service] |
| 93 | +Type=notify |
| 94 | +ExecStart=__ASTERISK_SBIN_DIR__/asterisk -g -f -p -U asterisk -G asterisk |
| 95 | +ExecReload=__ASTERISK_SBIN_DIR__/asterisk -rx 'core reload' |
| 96 | +Restart=on-failure |
| 97 | +RestartSec=1 |
| 98 | +WorkingDirectory=__ASTERISK_VARLIB_DIR__ |
| 99 | + |
| 100 | +# The following two lines are by default set to null so as to avoid |
| 101 | +# unnecessary console output to syslog. However, if you to, you can |
| 102 | +# further edit /etc/asterisk/logger.conf to log output to syslog. |
| 103 | +StandardOutput=null |
| 104 | +StandardError=null |
| 105 | + |
| 106 | +# Extra settings: |
| 107 | +# If you want to set them, you can add them to a file in the directory |
| 108 | +# /lib/systemd/system/asterisk.service.d/ with the extension .conf. |
| 109 | +# Example content: |
| 110 | +#[Service] |
| 111 | +# |
| 112 | +# and following those two lines add directives or override existing |
| 113 | +# directives. Some extra directives that may be useful: |
| 114 | + |
| 115 | +# You can run a script to clean up after asterisk. An example script is |
| 116 | +# included in contrib/scripts/asterisk_cleanup. |
| 117 | +#ExecStopPost=/path/to/script |
| 118 | + |
| 119 | +#Nice=0 |
| 120 | +#UMask=0002 |
| 121 | +#LimitCORE=infinity |
| 122 | +#LimitNOFILE= |
| 123 | + |
| 124 | +# safe_asterisk runs Asterisk in a virtual console. This allows easy |
| 125 | +# access to the asterisk command-line without logging it. on the other |
| 126 | +# hand, it allows anyone with physical access to the console full access |
| 127 | +# to Asterisk. To enable this console, unrem the following lines and add |
| 128 | +# '-c' to the ExecStart line above: |
| 129 | +#TTYPath=/dev/tty9 |
| 130 | +#StandardInput=tty |
| 131 | +#StandardOutput=tty |
| 132 | +#StandardError=tty |
| 133 | + |
| 134 | +# For more information on what these parameters mean see: |
| 135 | +# |
| 136 | +# http://0pointer.de/public/systemd-man/systemd.service.html |
| 137 | +# http://0pointer.de/public/systemd-man/systemd.exec.html |
| 138 | + |
| 139 | +[Install] |
| 140 | +WantedBy=multi-user.target |
| 141 | --- a/Makefile |
| 142 | +++ b/Makefile |
| 143 | @@ -927,6 +927,8 @@ |
| 144 | rm -f contrib/scripts/asterisk.logrotate.tmp |
| 145 | |
| 146 | config: |
| 147 | + $(INSTALL) -d $(DESTDIR)/lib/systemd/system |
| 148 | + ./build_tools/install_subst -d contrib/asterisk.service $(DESTDIR)/lib/systemd/system/asterisk.service |
| 149 | @if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \ |
| 150 | ./build_tools/install_subst contrib/init.d/rc.redhat.asterisk "$(DESTDIR)/etc/rc.d/init.d/asterisk"; \ |
| 151 | if [ ! -f "$(DESTDIR)/etc/sysconfig/asterisk" ] ; then \ |