diff --git a/asterisk/conf/asterisk.conf b/asterisk/conf/asterisk.conf new file mode 100644 index 0000000..ba482bd --- /dev/null +++ b/asterisk/conf/asterisk.conf @@ -0,0 +1,24 @@ +; +; /etc/asterisk/asterisk.conf +; +; Directories are standard. +[directories](!) +astcachedir => /var/cache/asterisk +astetcdir => /etc/asterisk +astmoddir => /usr/lib/asterisk/modules +astvarlibdir => /var/lib/asterisk +astdbdir => /var/lib/asterisk +astkeydir => /var/lib/asterisk +astdatadir => /var/lib/asterisk +astagidir => /var/lib/asterisk/agi-bin +astspooldir => /var/spool/asterisk +astrundir => /var/run/asterisk +astlogdir => /var/log/asterisk +astsbindir => /usr/sbin + +; We'll run asterisk under its own user and group. +runuser = asterisk +rungroup = asterisk + +; Main language. +defaultlanguage = en_GB diff --git a/asterisk/conf/logger.conf b/asterisk/conf/logger.conf new file mode 100644 index 0000000..87dc355 --- /dev/null +++ b/asterisk/conf/logger.conf @@ -0,0 +1,9 @@ +; +; /etc/asterisk/logger.conf +; +[general] +; Default console output. +console => notice,warning,error + +; full human-readable logging please! +full.log => [plain]notice,warning,error,debug,verbose,dtmf,fax diff --git a/asterisk/conf/modules.conf b/asterisk/conf/modules.conf new file mode 100644 index 0000000..1e49347 --- /dev/null +++ b/asterisk/conf/modules.conf @@ -0,0 +1,14 @@ +; +; /etc/asterisk/modules.conf +; +; This is the same as the sample but without the text. +[modules] +autoload=yes + +noload = chan_alsa.so +noload = res_hep.so +noload = res_hep_pjsip.so +noload = res_hep_rtcp.so +noload = chan_sip.so +noload = app_voicemail_imap.so +noload = app_voicemail_odbc.so diff --git a/asterisk/samples/conf/asterisk.conf.sample b/asterisk/samples/conf/asterisk.conf.sample new file mode 100644 index 0000000..0d0d2a0 --- /dev/null +++ b/asterisk/samples/conf/asterisk.conf.sample @@ -0,0 +1,137 @@ +[directories](!) +astcachedir => /var/cache/asterisk +astetcdir => /etc/asterisk +astmoddir => /usr/lib/asterisk/modules +astvarlibdir => /var/lib/asterisk +astdbdir => /var/lib/asterisk +astkeydir => /var/lib/asterisk +astdatadir => /var/lib/asterisk +astagidir => /var/lib/asterisk/agi-bin +astspooldir => /var/spool/asterisk +astrundir => /var/run/asterisk +astlogdir => /var/log/asterisk +astsbindir => /usr/sbin + +[options] +;verbose = 3 +;debug = 3 +;trace = 0 ; Set the trace level. +;refdebug = yes ; Enable reference count debug logging. +;alwaysfork = yes ; Same as -F at startup. +;nofork = yes ; Same as -f at startup. +;quiet = yes ; Same as -q at startup. +;timestamp = yes ; Same as -T at startup. +;execincludes = yes ; Support #exec in config files. +;console = yes ; Run as console (same as -c at startup). +;highpriority = yes ; Run realtime priority (same as -p at + ; startup). +;initcrypto = yes ; Initialize crypto keys (same as -i at + ; startup). +;nocolor = yes ; Disable console colors. +;dontwarn = yes ; Disable some warnings. +;dumpcore = yes ; Dump core on crash (same as -g at startup). +;languageprefix = yes ; Use the new sound prefix path syntax. +;systemname = my_system_name ; Prefix uniqueid with a system name for + ; Global uniqueness issues. +;autosystemname = yes ; Automatically set systemname to hostname, + ; uses 'localhost' on failure, or systemname if + ; set. +;mindtmfduration = 80 ; Set minimum DTMF duration in ms (default 80 ms) + ; If we get shorter DTMF messages, these will be + ; changed to the minimum duration +;maxcalls = 10 ; Maximum amount of calls allowed. +;maxload = 0.9 ; Asterisk stops accepting new calls if the + ; load average exceed this limit. +;maxfiles = 1000 ; Maximum amount of openfiles. +;minmemfree = 1 ; In MBs, Asterisk stops accepting new calls if + ; the amount of free memory falls below this + ; watermark. +;cache_media_frames = yes ; Cache media frames for performance + ; Disable this option to help track down media frame + ; mismanagement when using valgrind or MALLOC_DEBUG. + ; The cache gets in the way of determining if the + ; frame is used after being freed and who freed it. + ; NOTE: This option has no effect when Asterisk is + ; compiled with the LOW_MEMORY compile time option + ; enabled because the cache code does not exist. + ; Default yes +;cache_record_files = yes ; Cache recorded sound files to another + ; directory during recording. +;record_cache_dir = /tmp ; Specify cache directory (used in conjunction + ; with cache_record_files). +;transmit_silence = yes ; Transmit silence while a channel is in a + ; waiting state, a recording only state, or + ; when DTMF is being generated. Note that the + ; silence internally is generated in raw signed + ; linear format. This means that it must be + ; transcoded into the native format of the + ; channel before it can be sent to the device. + ; It is for this reason that this is optional, + ; as it may result in requiring a temporary + ; codec translation path for a channel that may + ; not otherwise require one. +;transcode_via_sln = yes ; Build transcode paths via SLINEAR, instead of + ; directly. +;runuser = asterisk ; The user to run as. +;rungroup = asterisk ; The group to run as. +;lightbackground = yes ; If your terminal is set for a light-colored + ; background. +;forceblackbackground = yes ; Force the background of the terminal to be + ; black, in order for terminal colors to show + ; up properly. +;defaultlanguage = en ; Default language +documentation_language = en_US ; Set the language you want documentation + ; displayed in. Value is in the same format as + ; locale names. +;hideconnect = yes ; Hide messages displayed when a remote console + ; connects and disconnects. +;lockconfdir = no ; Protect the directory containing the + ; configuration files (/etc/asterisk) with a + ; lock. +;stdexten = gosub ; How to invoke the extensions.conf stdexten. + ; macro - Invoke the stdexten using a macro as + ; done by legacy Asterisk versions. + ; gosub - Invoke the stdexten using a gosub as + ; documented in extensions.conf.sample. + ; Default gosub. +;live_dangerously = no ; Enable the execution of 'dangerous' dialplan + ; functions and configuration file access from + ; external sources (AMI, etc.) These functions + ; (such as SHELL) are considered dangerous + ; because they can allow privilege escalation. + ; Configuration files are considered dangerous + ; if they exist outside of the Asterisk + ; configuration directory. + ; Default no +;entityid=00:11:22:33:44:55 ; Entity ID. + ; This is in the form of a MAC address. + ; It should be universally unique. + ; It must be unique between servers communicating + ; with a protocol that uses this value. + ; This is currently is used by DUNDi and + ; Exchanging Device and Mailbox State + ; using protocols: XMPP, Corosync and PJSIP. +;rtp_use_dynamic = yes ; When set to "yes" RTP dynamic payload types + ; are assigned dynamically per RTP instance vs. + ; allowing Asterisk to globally initialize them + ; to pre-designated numbers (defaults to "yes"). +;rtp_pt_dynamic = 35 ; Normally the Dynamic RTP Payload Type numbers + ; are 96-127, which allow just 32 formats. The + ; starting point 35 enables the range 35-63 and + ; allows 29 additional formats. When you use + ; more than 32 formats in the dynamic range and + ; calls are not accepted by a remote + ; implementation, please report this and go + ; back to value 96. +;hide_messaging_ami_events = no; This option, if enabled, will + ; suppress all of the Message/ast_msg_queue channel's + ; housekeeping AMI and ARI channel events. This can + ; reduce the load on the manager and ARI applications + ; when the Digium Phone Module for Asterisk is in use. + +; Changing the following lines may compromise your security. +;[files] +;astctlpermissions = 0660 +;astctlowner = root +;astctlgroup = apache +;astctl = asterisk.ctl diff --git a/asterisk/samples/conf/logger.conf.sample b/asterisk/samples/conf/logger.conf.sample new file mode 100644 index 0000000..d046708 --- /dev/null +++ b/asterisk/samples/conf/logger.conf.sample @@ -0,0 +1,186 @@ +; +; Logging Configuration +; +; In this file, you configure logging to files or to +; the syslog system. +; +; "logger reload" at the CLI will reload configuration +; of the logging system. + +[general] +; +; Customize the display of debug message time stamps +; this example is the ISO 8601 date format (yyyy-mm-dd HH:MM:SS) +; +; see strftime(3) Linux manual for format specifiers. Note that there is also +; a fractional second parameter which may be used in this field. Use %1q +; for tenths, %2q for hundredths, etc. +; +;dateformat=%F %T ; ISO 8601 date format +;dateformat=%F %T.%3q ; with milliseconds +; +; +; This makes Asterisk write callids to log messages +; (defaults to yes) +;use_callids = no +; +; This appends the hostname to the name of the log files. +;appendhostname = yes +; +; This determines whether or not we log queue events to a file +; (defaults to yes). +;queue_log = no +; +; Determines whether the queue_log always goes to a file, even +; when a realtime backend is present (defaults to no). +;queue_log_to_file = yes +; +; Set the queue_log filename +; (defaults to queue_log) +;queue_log_name = queue_log +; +; When using realtime for the queue log, use GMT for the timestamp +; instead of localtime. The default of this option is 'no'. +;queue_log_realtime_use_gmt = yes +; +; Log rotation strategy: +; none: Do not perform any logrotation at all. You should make +; very sure to set up some external logrotate mechanism +; as the asterisk logs can get very large, very quickly. +; sequential: Rename archived logs in order, such that the newest +; has the highest sequence number [default]. When +; exec_after_rotate is set, ${filename} will specify +; the new archived logfile. +; rotate: Rotate all the old files, such that the oldest has the +; highest sequence number [this is the expected behavior +; for Unix administrators]. When exec_after_rotate is +; set, ${filename} will specify the original root filename. +; timestamp: Rename the logfiles using a timestamp instead of a +; sequence number when "logger rotate" is executed. +; When exec_after_rotate is set, ${filename} will +; specify the new archived logfile. +;rotatestrategy = rotate +; +; Run a system command after rotating the files. This is mainly +; useful for rotatestrategy=rotate. The example allows the last +; two archive files to remain uncompressed, but after that point, +; they are compressed on disk. +; +; exec_after_rotate=gzip -9 ${filename}.2 +; +; +; For each file, specify what to log. +; +; For console logging, you set options at start of +; Asterisk with -v for verbose and -d for debug +; See 'asterisk -h' for more information. +; +; Directory for log files is configures in asterisk.conf +; option astlogdir +; +; All log messages go to a queue serviced by a single thread +; which does all the IO. This setting controls how big that +; queue can get (and therefore how much memory is allocated) +; before new messages are discarded. +; The default is 1000 +;logger_queue_limit = 250 +; +; Any custom logging levels you may want to use, which can then +; be sent to logging channels. The maximum number of custom +; levels is 16, but not all of these may be available if modules +; in Asterisk define their own. +;custom_levels = foobar,important,compliance +; +[logfiles] +; +; Format is: +; +; logger_name => [formatter]levels +; +; The name of the logger dictates not only the name of the logging +; channel, but also its type. Valid types are: +; - 'console' - The root console of Asterisk +; - 'syslog' - Linux syslog, with facilities specified afterwards with +; a period delimiter, e.g., 'syslog.local0' +; - 'filename' - The name of the log file to create. This is the default +; for log channels. +; +; Filenames can either be relative to the standard Asterisk log directory +; (see 'astlogdir' in asterisk.conf), or absolute paths that begin with +; '/'. +; +; An optional formatter can be specified prior to the log levels sent +; to the log channel. The formatter is defined immediately preceeding the +; levels, and is enclosed in square brackets. Valid formatters are: +; - [default] - The default formatter, this outputs log messages using a +; human readable format. +; - [plain] - The plain formatter, this outputs log messages using a +; human readable format with the addition of function name +; and line number. No color escape codes are ever printed +; nor are verbose messages treated specially. +; - [json] - Log the output in JSON. Note that JSON formatted log entries, +; if specified for a logger type of 'console', will be formatted +; per the 'default' formatter for log messages of type VERBOSE. +; This is due to the remote consoles interpreting verbosity +; outside of the logging subsystem. +; +; Log levels include the following, and are specified in a comma delineated +; list: +; debug +; trace +; notice +; warning +; error +; verbose() +; dtmf +; fax +; security +; +; +; Verbose takes an optional argument, in the form of an integer level. The +; verbose level can be set per logfile. Verbose messages with higher levels +; will not be logged to the file. If the verbose level is not specified, it +; will log verbose messages following the current level of the root console. +; +; Debug has multiple levels like verbose. However, it is a system wide setting +; and cannot be specified per logfile. You specify the debug level elsewhere +; such as the CLI 'core set debug 3', starting Asterisk with '-ddd', or in +; asterisk.conf 'debug=3'. +; +; Special level name "*" means all levels, even dynamic levels registered +; by modules after the logger has been initialized (this means that loading +; and unloading modules that create/remove dynamic logger levels will result +; in these levels being included on filenames that have a level name of "*", +; without any need to perform a 'logger reload' or similar operation). +; Note that there is no value in specifying both "*" and specific level names +; for a filename; the "*" level means all levels. The only exception is if +; you need to specify a specific verbose level. e.g, "verbose(3),*". +; +; We highly recommend that you DO NOT turn on debug mode if you are simply +; running a production system. Debug mode turns on a LOT of extra messages, +; most of which you are unlikely to understand without an understanding of +; the underlying code. Do NOT report debug messages as code issues, unless +; you have a specific issue that you are attempting to debug. They are +; messages for just that -- debugging -- and do not rise to the level of +; something that merit your attention as an Asterisk administrator. Both +; debug and trace messages are also very verbose and can and do fill up +; logfiles quickly. This is another reason not to have debug or trace +; modes on a production system unless you are in the process of debugging +; a specific issue. +; +;debug.log => error,warning,notice,verbose,debug +;trace.log => trace +;security.log => security +console => notice,warning,error +;console => notice,warning,error,debug +messages.log => notice,warning,error +;full.log => notice,warning,error,debug,verbose,dtmf,fax +; +;full-json.log => [json]debug,verbose,notice,warning,error,dtmf,fax +; +;syslog keyword : This special keyword logs to syslog facility +; +;syslog.local0 => notice,warning,error +; +; A log level defined in 'custom_levels' above +;important.log = important diff --git a/asterisk/samples/conf/modules.conf.sample b/asterisk/samples/conf/modules.conf.sample new file mode 100644 index 0000000..2ab16d1 --- /dev/null +++ b/asterisk/samples/conf/modules.conf.sample @@ -0,0 +1,55 @@ +; +; Asterisk configuration file +; +; Module Loader configuration file +; + +[modules] +autoload=yes +; +; Any modules that need to be loaded before the Asterisk core has been +; initialized (just after the logger initialization) can be loaded +; using 'preload'. 'preload' forces a module and the modules it +; is known to depend upon to be loaded earlier than they normally get +; loaded. +; +; NOTE: There is no good reason left to use 'preload' anymore. It was +; historically required to preload realtime driver modules so you could +; map Asterisk core configuration files to Realtime storage. +; This is no longer needed. +; +;preload = your_special_module.so +; +; If you want Asterisk to fail if a module does not load, then use +; the "require" keyword. Asterisk will exit with a status code of 2 +; if a required module does not load. +; +;require = chan_pjsip.so +; +; If you want you can combine with preload +; preload-require = your_special_module.so +; +;load = res_musiconhold.so +; +; Load one of: alsa, or console (portaudio). +; By default, load chan_console only (automatically). +; +noload = chan_alsa.so +;noload = chan_console.so +; +; Do not load res_hep and kin unless you are using HEP monitoring +; in your network. +; +noload = res_hep.so +noload = res_hep_pjsip.so +noload = res_hep_rtcp.so +; +; Do not load chan_sip by default, it may conflict with res_pjsip. +noload = chan_sip.so +; +; Load one of the voicemail modules as they are mutually exclusive. +; By default, load app_voicemail only (automatically). +; +;noload = app_voicemail.so +noload = app_voicemail_imap.so +noload = app_voicemail_odbc.so diff --git a/asterisk/scripts/asterisk-permissions.sh b/asterisk/scripts/asterisk-permissions.sh new file mode 100644 index 0000000..b586654 --- /dev/null +++ b/asterisk/scripts/asterisk-permissions.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Run this script with "(sudo) bash ". + +# Exit on error. +#set -e +# Debug +set -eux + +useradd --system --user-group -d /var/lib/asterisk/ -M asterisk +chown root:asterisk -v /var/log/asterisk/ /var/spool/asterisk/ /var/lib/asterisk /etc/asterisk +chown asterisk:asterisk -vR /var/log/asterisk/* /var/spool/asterisk/* /var/lib/asterisk/* +chmod 770 -v /var/log/asterisk/ /var/spool/asterisk/ /var/lib/asterisk /etc/asterisk diff --git a/asterisk/systemd/asterisk.service b/asterisk/systemd/asterisk.service new file mode 100644 index 0000000..e05cd96 --- /dev/null +++ b/asterisk/systemd/asterisk.service @@ -0,0 +1,37 @@ +# /etc/systemd/system/asterisk.service + +# "Borrowed" from https://g1fef.co.uk/asterisk-systemd-startup-script/ + +[Unit] +Description=Asterisk PBX and telephony daemon. +Wants=network.target +After=network.target + +[Service] +Type=simple +User=asterisk +Group=asterisk +RuntimeDirectory=asterisk +Environment=HOME=/var/lib/asterisk +WorkingDirectory=/var/lib/asterisk + +ExecStart=/usr/sbin/asterisk -f -C /etc/asterisk/asterisk.conf +ExecStop=/usr/sbin/asterisk -rx 'core stop now' +ExecReload=/usr/sbin/asterisk -rx 'core reload' + +# safe_asterisk emulation +Restart=always +RestartSec=10 + +#Nice=0 +#UMask=0002 +LimitCORE=infinity +#LimitNOFILE= + +# Prevent duplication of logs with color codes to /var/log/messages +#StandardOutput=null + +PrivateTmp=true + +[Install] +WantedBy=multi-user.target