diff -Nur --no-dereference smeserver-freepbx-13.old/createlinks smeserver-freepbx-13/createlinks --- smeserver-freepbx-13.old/createlinks 2022-03-24 23:13:37.415000000 -0400 +++ smeserver-freepbx-13/createlinks 2022-03-25 00:14:58.799000000 -0400 @@ -4,23 +4,23 @@ # Start and stop links -service_link_enhanced("freepbx", "S98", "7"); -service_link_enhanced("freepbx", "K10", "6"); -service_link_enhanced("freepbx", "K10", "0"); -service_link_enhanced("freepbx", "K10", "1"); - -service_link_enhanced("httpd-fpbx", "S86", "7"); -service_link_enhanced("httpd-fpbx", "K15", "6"); -service_link_enhanced("httpd-fpbx", "K15", "0"); -service_link_enhanced("httpd-fpbx", "K15", "1"); - -service_link_enhanced("dahdi", "S09", "7"); -service_link_enhanced("dahdi", "K16", "6"); -service_link_enhanced("dahdi", "K16", "0"); -service_link_enhanced("dahdi", "K16", "1"); +#service_link_enhanced("freepbx", "S98", "7"); +#service_link_enhanced("freepbx", "K10", "6"); +#service_link_enhanced("freepbx", "K10", "0"); +#service_link_enhanced("freepbx", "K10", "1"); + +#service_link_enhanced("httpd-fpbx", "S86", "7"); +#service_link_enhanced("httpd-fpbx", "K15", "6"); +#service_link_enhanced("httpd-fpbx", "K15", "0"); +#service_link_enhanced("httpd-fpbx", "K15", "1"); + +#service_link_enhanced("dahdi", "S09", "7"); +#service_link_enhanced("dahdi", "K16", "6"); +#service_link_enhanced("dahdi", "K16", "0"); +#service_link_enhanced("dahdi", "K16", "1"); -safe_symlink("../daemontools" , 'root/etc/rc.d/init.d/supervise/httpd-fpbx'); -safe_symlink("/var/service/httpd-fpbx" , 'root/service/httpd-fpbx'); +#safe_symlink("../daemontools" , 'root/etc/rc.d/init.d/supervise/httpd-fpbx'); +#safe_symlink("/var/service/httpd-fpbx" , 'root/service/httpd-fpbx'); # Panel links @@ -48,17 +48,42 @@ safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/mysql.init"); safe_symlink("sigusr1", "root/etc/e-smith/events/$event/services2adjust/httpd-e-smith"); safe_symlink("sigusr1", "root/etc/e-smith/events/$event/services2adjust/httpd-fpbx"); +safe_symlink("reload-or-restart", "root/etc/e-smith/events/$event/services2adjust/php74-php-fpm"); + safe_symlink("sigusr1", "root/etc/e-smith/events/logrotate/services2adjust/httpd-fpbx"); safe_symlink("sigusr1", "root/etc/e-smith/events/conf-userpanel/services2adjust/httpd-fpbx"); # Create empty files -safe_touch("root/etc/e-smith/events/logrotate/logfiles2timestamp/var/log/httpd/fpbx_access_log"); -safe_touch("root/etc/e-smith/events/logrotate/logfiles2timestamp/var/log/httpd/fpbx_error_log"); -safe_touch("root/var/service/httpd-fpbx/down"); +#safe_touch("root/etc/e-smith/events/logrotate/logfiles2timestamp/var/log/httpd/fpbx_access_log"); +#safe_touch("root/etc/e-smith/events/logrotate/logfiles2timestamp/var/log/httpd/fpbx_error_log"); +#safe_touch("root/var/service/httpd-fpbx/down"); # Create empty directories system("/bin/mkdir -p root/var/service/httpd-fpbx/supervise"); system("/bin/mkdir -p root/var/service/httpd-fpbx/log/supervise"); system("/bin/mkdir -p root/var/log/httpd-fpbx"); + +## systemd install/update +my $event = 'smeserver-freepbx-update'; +templates2events("/etc/asterisk/asterisk.conf", $event); +templates2events("/etc/asterisk/cdr_mysql.conf", $event); +templates2events("/etc/asterisk/manager.conf", $event); +templates2events("/etc/logrotate.d/asterisk", $event); +templates2events("/etc/httpd/conf/httpd.conf", $event); +templates2events("/etc/httpd/fpbx-conf/httpd.conf", $event); +templates2events("/etc/e-smith/sql/init/30freepbx_mysql_create_database", $event); +event_link("freepbx-checkinstall", $event, "10"); +event_link("freepbx-checkinstall-backup", $event, "11"); +event_link("freepbx-amportal.conf", $event, "91"); +event_link("freepbx-clean-crontab", $event, "40"); + +safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/mysql.init"); +safe_symlink("sigusr1", "root/etc/e-smith/events/$event/services2adjust/httpd-e-smith"); +safe_symlink("sigusr1", "root/etc/e-smith/events/$event/services2adjust/httpd-fpbx"); +safe_symlink("reload-or-restart", "root/etc/e-smith/events/$event/services2adjust/php74-php-fpm"); +#action needed in case we have a systemd unit +event_link("systemd-default", $event, "88"); +event_link("systemd-reload", $event, "89"); + diff -Nur --no-dereference smeserver-freepbx-13.old/root/etc/e-smith/events/actions/freepbx-checkinstall smeserver-freepbx-13/root/etc/e-smith/events/actions/freepbx-checkinstall --- smeserver-freepbx-13.old/root/etc/e-smith/events/actions/freepbx-checkinstall 2022-03-24 23:13:37.431000000 -0400 +++ smeserver-freepbx-13/root/etc/e-smith/events/actions/freepbx-checkinstall 2022-03-25 00:44:34.355000000 -0400 @@ -44,7 +44,11 @@ ./start_asterisk start >> /root/freepbx_install.log 2>&1 echo "" >> /root/freepbx_install.log echo "Installing FreePBX..." >> /root/freepbx_install.log - echo "a" | ./install --webroot="/opt/freepbx" --dbengine="mysql" --dbname="freepbxdb" --dbuser="freepbxuser" --dbpass="$DBPASS" -n >> /root/freepbx_install.log 2>&1 + echo "a" | /usr/bin/php74 ./install --webroot="/opt/freepbx" \ + --dbengine="mysql" --dbname="freepbxdb" --dbuser="freepbxuser" --dbpass="$DBPASS" -n \ + --cdrdbname="$CDRDBNAME" --astmoddir=/usr/lib64/asterisk/modules/ \ + --astagidir=/usr/share/asterisk/agi-bin/ --ampsbin=/usr/local/bin --ampcgibin=/opt/freepbx/cgi-bin \ + >> /root/freepbx_install.log 2>&1 else echo "error: /usr/share/freepbx/sources/freepbx/ doesn't exists" exit 1 diff -Nur --no-dereference smeserver-freepbx-13.old/root/etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/20Modules smeserver-freepbx-13/root/etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/20Modules --- smeserver-freepbx-13.old/root/etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/20Modules 2016-06-13 08:03:08.000000000 -0400 +++ smeserver-freepbx-13/root/etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/20Modules 2022-03-24 23:58:31.900000000 -0400 @@ -50,25 +50,7 @@ $OUT .= "LoadModule ${_}_module modules/mod_${_}.so\n"; } -if (exists $php{status} and $php{status} eq "enabled"){ - my $modphp = '4'; - if ( -r "/usr/lib/httpd/modules/libphp5.so" || -r "/usr/lib64/httpd/modules/libphp5.so" ){ - $modphp = '5'; - } - $OUT .= "LoadModule php".$modphp."_module modules/libphp".$modphp.".so\n"; -} - -$OUT .= < - AddIcon /icons/php4.gif .php3 .php4 .php .phtml - AddIcon /icons/phps.gif .phps - - - - AddIcon /icons/php5.gif .php3 .php4 .php5 .php .phtml - AddIcon /icons/phps.gif .phps - +# we do not use php module anymore, but php-fpm PidFile /var/run/httpd-fpbx.pid UseCanonicalName off diff -Nur --no-dereference smeserver-freepbx-13.old/root/etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/90FreePBX20Root smeserver-freepbx-13/root/etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/90FreePBX20Root --- smeserver-freepbx-13.old/root/etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/90FreePBX20Root 2016-06-13 08:03:08.000000000 -0400 +++ smeserver-freepbx-13/root/etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/90FreePBX20Root 2022-03-25 00:01:25.372000000 -0400 @@ -2,10 +2,19 @@ AddType application/x-httpd-php .php Options +followSymlinks + +{ + my $key = "freepbx"; + my $pool_name = lc $key; + my $version = 74; + $OUT .=" + + SetHandler \"proxy:unix:/var/run/php-fpm/php${version}-${pool_name}.sock|fcgi://localhost\" + \n"; +} AllowOverride All order deny,allow deny from all allow from 127.0.0.1 - php_admin_value session.save_path /var/lib/php/fpbx-session diff -Nur --no-dereference smeserver-freepbx-13.old/root/etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/90FreePBX30Admin smeserver-freepbx-13/root/etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/90FreePBX30Admin --- smeserver-freepbx-13.old/root/etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/90FreePBX30Admin 2022-03-24 23:13:37.426000000 -0400 +++ smeserver-freepbx-13/root/etc/e-smith/templates/etc/httpd/fpbx-conf/httpd.conf/90FreePBX30Admin 2022-03-25 00:04:30.523000000 -0400 @@ -1,12 +1,6 @@ Options +followSymlinks - php_admin_flag allow_url_fopen On - php_admin_value memory_limit 256M - php_admin_value upload_max_filesize 100M - php_admin_value post_max_size 100M - php_admin_flag file_upload On - php_admin_flag magic_quotes_gpc Off diff -Nur --no-dereference smeserver-freepbx-13.old/root/etc/e-smith/templates/etc/logrotate.d/asterisk/All smeserver-freepbx-13/root/etc/e-smith/templates/etc/logrotate.d/asterisk/All --- smeserver-freepbx-13.old/root/etc/e-smith/templates/etc/logrotate.d/asterisk/All 2016-06-13 08:03:08.000000000 -0400 +++ smeserver-freepbx-13/root/etc/e-smith/templates/etc/logrotate.d/asterisk/All 2022-03-25 00:20:25.749000000 -0400 @@ -1,9 +1,26 @@ -/var/log/asterisk/messages /var/log/asterisk/freepbx.log /var/log/asterisk/event_log /var/log/asterisk/queue_log /var/log/asterisk/full /var/log/asterisk/warnings /var/log/asterisk/misdn.log \{ +/var/log/asterisk/messages +/var/log/asterisk/event_log +/var/log/asterisk/queue_log +/var/log/asterisk/full +/var/log/asterisk/security +/var/log/asterisk/freepbx.log +/var/log/asterisk/freepbx_security.log +/var/log/asterisk/ucp_err.log +/var/log/asterisk/ucp_out.log +/var/log/asterisk/cdr-csv/Master.csv +/var/log/asterisk/warnings +/var/log/asterisk/misdn.log +\{ missingok notifempty compress + compressoptions -T0 + compresscmd /usr/bin/xz + compressext .xz + uncompresscmd /usr/bin/unxz daily - rotate 60 + rotate 365 + su asterisk asterisk create 0640 asterisk asterisk sharedscripts postrotate diff -Nur --no-dereference smeserver-freepbx-13.old/root/etc/e-smith/templates/etc/php-fpm.d/www.conf/16freepbx smeserver-freepbx-13/root/etc/e-smith/templates/etc/php-fpm.d/www.conf/16freepbx --- smeserver-freepbx-13.old/root/etc/e-smith/templates/etc/php-fpm.d/www.conf/16freepbx 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-freepbx-13/root/etc/e-smith/templates/etc/php-fpm.d/www.conf/16freepbx 2022-03-25 00:05:11.932000000 -0400 @@ -0,0 +1,69 @@ +{ + +if ($PHP_VERSION eq '74'){ + if (($freepbx{'status'} || 'disabled') eq 'enabled'){ + my $max_upload_size = ($freepbx{MaxUploadSize} || '100M'); + $max_upload_size .= 'M' if ($max_upload_size =~ m/^\d+$/); + my $memory_limit = ($freepbx{MemoryLimit} || '512M'); + $memory_limit .= 'M' if ($memory_limit =~ m/^\d+$/); + my $open_basedir= $freepbx{PHPBaseDir} || ''; + $open_basedir = "/usr/share/freepbx:/var/lib/freepbx:/var/log/freepbx.log:/var/lib/php/freepbx:/home/e-smith/files/freepbx:/dev/urandom:/proc/meminfo:$open_basedir"; + my $id = 'freepbx'; + my $max_children = $freepbx{'PHPmaxChildren'} || 15; + my $min_spare_servers = $freepbx{'PHPminServers'} || 3; + my $start_servers = $freepbx{'PHPstartServers'} || 3; + my $max_spare_servers = $freepbx{'PHPmaxServers'} || 6; + my $max_requests = $freepbx{'PHPmaxRequests'} || 5000; + $min_spare_servers = ( $min_spare_servers > $max_spare_servers ) ? printf("%.0f",$max_spare_servers/2) : $min_spare_servers; + $start_servers = ( $start_servers > $max_spare_servers ) ? printf("%.0f", $max_spare_servers /2 + $min_spare_servers/2 ) : $start_servers; + + + $OUT .=<<_EOF; + +[freepbx] + +listen.owner = root +listen.group = www +listen.mode = 0660 +listen = /var/run/php-fpm/php$PHP_VERSION-$id.sock +user = asterisk +group = asterisk +catch_workers_output = yes + +pm = dynamic +pm.max_children = $max_children +pm.start_servers = $start_servers +pm.min_spare_servers = $min_spare_servers +pm.max_spare_servers = $max_spare_servers +pm.max_requests = $max_requests +request_terminate_timeout = 60m + +php_flag[display_errors] = off +php_admin_flag[log_errors] = on +php_admin_value[error_log] = syslog +php_admin_value[memory_limit] = $memory_limit +php_admin_value[session.save_path] = /var/lib/php/$id/sessions +php_admin_value[upload_tmp_dir] = /var/lib/php/$id/tmp +php_admin_value[sys_temp_dir] = /var/lib/php/$id/tmp +php_admin_value[post_max_size] = $max_upload_size +php_admin_value[upload_max_filesize] = $max_upload_size +php_admin_value[max_execution_time] = 900 +php_admin_value[max_input_time] = 900 +php_admin_flag[allow_url_include] = off +php_admin_flag[allow_url_fopen] = on +php_admin_flag[file_uploads] = on +php_admin_flag[session.cookie_httponly] = on + +; Needed so that the #!/usr/bin/env php shebang will point to the correct PHP version +env[PATH] = /opt/remi/php{{ fpbx_php_version }}/root/usr/bin:/opt/remi/php{{ fpbx_php_version }}/root/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin +;env[http_proxy] = {{ system_proxy }} +;env[https_proxy] = {{ system_proxy }} +;env[no_proxy] = +_EOF + + } + else{ + $OUT .= '; Nextcloud is disabled'; + } +} +} diff -Nur --no-dereference smeserver-freepbx-13.old/root/etc/rc.d/init.d/freepbx smeserver-freepbx-13/root/etc/rc.d/init.d/freepbx --- smeserver-freepbx-13.old/root/etc/rc.d/init.d/freepbx 2008-08-05 17:07:12.000000000 -0400 +++ smeserver-freepbx-13/root/etc/rc.d/init.d/freepbx 1969-12-31 19:00:00.000000000 -0500 @@ -1,85 +0,0 @@ -#! /bin/sh -# chkconfig: 98 10 - -if [ -f /etc/init.d/functions ] ; then - . /etc/init.d/functions -elif [ -f /etc/rc.d/init.d/functions ] ; then - . /etc/rc.d/init.d/functions -else - exit 0 -fi - - - - -# make sure config file exists -if [ ! -e "/etc/amportal.conf" ]; then - echo "" - echo "/etc/amportal.conf does not exist!" - echo "Have you installed the AMP configuration?" - exit 1 -fi -. /etc/amportal.conf - -if [ -x ${AMPBIN}/freepbx_engine ]; then - FPBXENGINE=${AMPBIN}/freepbx_engine -elif [ -x ${ASTVARLIBDIR}/bin/freepbx_engine ]; then - FPBXENGINE=${ASTVARLIBDIR}/bin/freepbx_engine -elif [ -x /var/lib/asterisk/bin/freepbx_engine ]; then - FPBXENGINE=/var/lib/asterisk/bin/freepbx_engine -else - echo "FATAL: can not find freepbx_engine to start Asterisk" - exit 1 -fi - -FPBXSTATUS=$(/sbin/e-smith/db configuration getprop freepbx status) - -case "$1" in - start) - $FPBXENGINE start > /dev/null 2>&1 - echo -n "Starting FreePBX: " - RETVAL=$? - ;; - stop) - $FPBXENGINE stop > /dev/null 2>&1 - echo -n "Stoping FreePBX: " - RETVAL=$? - ;; - restart) - $FPBXENGINE restart > /dev/null 2>&1 - echo -n "Restarting FreePBX: " - RETVAL=$? - ;; - reload) - /usr/sbin/asterisk -rx 'reload' > /dev/null 2>&1 - echo -n "Reloading FreePBX: " - RETVAL=$? - ;; - kill) - $FPBXENGINE kill > /dev/null 2>&1 - echo -n "Killing FreePBX: " - RETVAL=$? - ;; - adjust) - if [ $FPBXSTATUS == 'enabled' ]; then - $FPBXENGINE restart > /dev/null 2>&1 - else - $FPBXENGINE stop > /dev/null 2>&1 - fi - echo -n "Adjusting FreePBX: " - RETVAL=$? - ;; - *) - echo "Usage: $0 {start|stop|restart|reload|adjust|kill}" - exit 1 -esac - -if [ $RETVAL -eq 0 ]; then - echo_success -else - echo_failure -fi -echo - -exit $RETVAL - diff -Nur --no-dereference smeserver-freepbx-13.old/root/usr/lib/systemd/system/asterisk.conf.d/50-koozali.conf smeserver-freepbx-13/root/usr/lib/systemd/system/asterisk.conf.d/50-koozali.conf --- smeserver-freepbx-13.old/root/usr/lib/systemd/system/asterisk.conf.d/50-koozali.conf 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-freepbx-13/root/usr/lib/systemd/system/asterisk.conf.d/50-koozali.conf 2022-03-24 23:34:56.871000000 -0400 @@ -0,0 +1,4 @@ +[Service] +# we do not want asterisk to run as a service, freepbx will handle it +ExecStart= +ExecStart=/dev/null diff -Nur --no-dereference smeserver-freepbx-13.old/root/usr/lib/systemd/system/freepbx.service smeserver-freepbx-13/root/usr/lib/systemd/system/freepbx.service --- smeserver-freepbx-13.old/root/usr/lib/systemd/system/freepbx.service 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-freepbx-13/root/usr/lib/systemd/system/freepbx.service 2022-03-24 23:17:16.044000000 -0400 @@ -0,0 +1,19 @@ +[Unit] +Description=FreePBX VoIP Server +Requires=mariadb.service + +[Service] +Type=forking + +ExecStartPre=/sbin/e-smith/service-status freepbx + +ExecStart=/usr/local/bin/fwconsole start -q +ExecStop=/usr/local/bin/fwconsole stop -q +ExecReload=/usr/local/bin/fwconsole reload -q +SyslogIdentifier=FreePBX +Restart=on-failure +StartLimitInterval=0 +RestartSec=30 + +[Install] +WantedBy=multi-user.target sme-server.target diff -Nur --no-dereference smeserver-freepbx-13.old/root/usr/lib/systemd/system/httpd-fpbx.service smeserver-freepbx-13/root/usr/lib/systemd/system/httpd-fpbx.service --- smeserver-freepbx-13.old/root/usr/lib/systemd/system/httpd-fpbx.service 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-freepbx-13/root/usr/lib/systemd/system/httpd-fpbx.service 2022-03-24 23:40:24.092000000 -0400 @@ -0,0 +1,21 @@ +[Unit] +Description=The Koozali SME Server FreePBX web service +After=network.service remote-fs.target +Documentation=man:httpd(8) +Documentation=man:apachectl(8) + +[Service] +Type=notify +EnvironmentFile=/etc/sysconfig/httpd +ExecStartPre=/sbin/e-smith/service-status httpd-fpbx +ExecStartPre=/sbin/e-smith/expand-template /etc/httpd/fpbx-conf/httpd.conf +ExecStart=/usr/sbin/httpd -f /etc/httpd/fpbx-conf/httpd.conf -DFOREGROUND +ExecReload=/usr/sbin/httpd -f /etc/httpd/fpbx-conf/httpd.conf -k graceful +ExecStop=/bin/kill -WINCH ${MAINPID} +KillSignal=SIGCONT +PrivateTmp=true + + +[Install] +WantedBy=sme-server.target + diff -Nur --no-dereference smeserver-freepbx-13.old/root/usr/local/bin/safe_asterisk smeserver-freepbx-13/root/usr/local/bin/safe_asterisk --- smeserver-freepbx-13.old/root/usr/local/bin/safe_asterisk 1969-12-31 19:00:00.000000000 -0500 +++ smeserver-freepbx-13/root/usr/local/bin/safe_asterisk 2022-03-24 23:26:33.185000000 -0400 @@ -0,0 +1,228 @@ +#!/bin/sh + +ASTETCDIR="/etc/asterisk" +ASTSBINDIR="/usr/sbin" +ASTVARRUNDIR="/var/run/asterisk" +ASTVARLOGDIR="/var/log/asterisk" + +CLIARGS="$*" # Grab any args passed to safe_asterisk +TTY=9 # TTY (if you want one) for Asterisk to run on +CONSOLE=yes # Whether or not you want a console +#NOTIFY=root@localhost # Who to notify about crashes +#EXEC=/path/to/somescript # Run this command if Asterisk crashes +#LOGFILE="${ASTVARLOGDIR}/safe_asterisk.log" # Where to place the normal logfile (disabled if blank) +#SYSLOG=local0 # Which syslog facility to use (disabled if blank) +MACHINE=`hostname` # To specify which machine has crashed when getting the mail +DUMPDROP="${DUMPDROP:-/tmp}" +RUNDIR="${RUNDIR:-/tmp}" +SLEEPSECS=4 +ASTPIDFILE="${ASTVARRUNDIR}/asterisk.pid" + +# comment this line out to have this script _not_ kill all mpg123 processes when +# asterisk exits +KILLALLMPG123=1 + +# run asterisk with this priority +PRIORITY=0 + +# set system filemax on supported OSes if this variable is set +# SYSMAXFILES=262144 + +# Asterisk allows full permissions by default, so set a umask, if you want +# restricted permissions. +#UMASK=022 + +# set max files open with ulimit. On linux systems, this will be automatically +# set to the system's maximum files open devided by two, if not set here. +# MAXFILES=32768 + +message() { + if test -n "$TTY" && test "$TTY" != "no"; then + echo "$1" >/dev/${TTY} + fi + if test -n "$SYSLOG"; then + logger -p "${SYSLOG}.warn" -t safe_asterisk[$$] "$1" + fi + if test -n "$LOGFILE"; then + echo "safe_asterisk[$$]: $1" >>"$LOGFILE" + fi +} + +# Check if Asterisk is already running. If it is, then bug out, because +# starting safe_asterisk when Asterisk is running is very bad. +VERSION=`"${ASTSBINDIR}/asterisk" -nrx 'core show version' 2>/dev/null` +if test "`echo $VERSION | cut -c 1-8`" = "Asterisk"; then + message "Asterisk is already running. $0 will exit now." + exit 1 +fi + +# since we're going to change priority and open files limits, we need to be +# root. if running asterisk as other users, pass that to asterisk on the command +# line. +# if we're not root, fall back to standard everything. +if test `id -u` != 0; then + echo "Oops. I'm not root. Falling back to standard prio and file max." >&2 + echo "This is NOT suitable for large systems." >&2 + PRIORITY=0 + message "safe_asterisk was started by `id -n` (uid `id -u`)." +else + if `uname -s | grep Linux >/dev/null 2>&1`; then + # maximum number of open files is set to the system maximum + # divided by two if MAXFILES is not set. + if test -z "$MAXFILES"; then + # just check if file-max is readable + if test -r /proc/sys/fs/file-max; then + MAXFILES=$((`cat /proc/sys/fs/file-max` / 2)) + # don't exceed upper limit of 2^20 for open + # files on systems where file-max is > 2^21 + if test $MAXFILES -gt 1048576; then + MAXFILES=1048576 + fi + fi + fi + SYSCTL_MAXFILES="fs.file-max" + elif `uname -s | grep Darwin /dev/null 2>&1`; then + SYSCTL_MAXFILES="kern.maxfiles" + fi + + + if test -n "$SYSMAXFILES"; then + if test -n "$SYSCTL_MAXFILES"; then + sysctl -w $SYSCTL_MAXFILES=$SYSMAXFILES + fi + fi + + # set the process's filemax to whatever set above + ulimit -n $MAXFILES + + if test ! -d "${ASTVARRUNDIR}"; then + mkdir -p "${ASTVARRUNDIR}" + chmod 770 "${ASTVARRUNDIR}" + fi + +fi + +if test -n "$UMASK"; then + umask $UMASK +fi + +# +# Let Asterisk dump core +# +ulimit -c unlimited + +# +# Don't fork when running "safely" +# +ASTARGS="" +if test -n "$TTY" && test "$TTY" != "no"; then + if test -c /dev/tty${TTY}; then + TTY=tty${TTY} + elif test -c /dev/vc/${TTY}; then + TTY=vc/${TTY} + elif test "$TTY" = "9"; then # ignore default if it was untouched + # If there is no /dev/tty9 and not /dev/vc/9 we don't + # necessarily want to die at this point. Pretend that + # TTY wasn't set. + TTY= + else + message "Cannot find specified TTY (${TTY})" + exit 1 + fi + if test -n "$TTY"; then + ASTARGS="${ASTARGS} -vvvg" + if test "$CONSOLE" != "no"; then + ASTARGS="${ASTARGS} -c" + fi + fi +fi + +if test ! -d "${RUNDIR}"; then + message "${RUNDIR} does not exist, creating" + if ! mkdir -p "${RUNDIR}"; then + message "Unable to create ${RUNDIR}" + exit 1 + fi +fi + +if test ! -w "${DUMPDROP}"; then + message "Cannot write to ${DUMPDROP}" + exit 1 +fi + +# +# Don't die if stdout/stderr can't be written to +# +trap '' PIPE + +# +# Run scripts to set any environment variables or do any other system-specific setup needed +# + +if test -d "${ASTETCDIR}/startup.d"; then + for script in "${ASTETCDIR}/startup.d/"*.sh; do + if test -r "${script}"; then + . "${script}" + fi + done +fi + +run_asterisk() +{ + while :; do + if test -n "$TTY" && test "$TTY" != "no"; then + cd "${RUNDIR}" + stty sane /dev/${TTY} 2>&1 /dev/null 2>&1