Страница 1 из 1
Asterisk 11 + Mariadb + Centos 7 - перезапуск
Добавлено: 15 июл 2021, 11:07
Wapo
Приветствую.
Начал на новом железе поднимать свою РАБОТАЮЩУЮ конфигурацию из * версии 11 (собрана из исходников с cdr_mysql).
Ось - Centos 7 х64, база Mariadb
Работает отлично, но...
При перестарте всего сервера астер стартует из rc.local НО появляется сообщение что он не может подключиться к базе!!!! Остальное все ок.
Вручную если перевыгрузить cdr_mysql - подключается норм, да и res_mysql также приходится передергивать.
Может какой-то тайм-аут надо вставлять дополнительно?
Кто нить сталкивался?
Re: Asterisk 11 + Mariadb + Centos 7 - перезапуск
Добавлено: 15 июл 2021, 11:13
Zavr2008
Вопрос пересобрано каким компилятором и с какими опциями, включены ли всякие SSE итп.
Вообще в последнее время опасаюсь так делать - проще и безопаснее через гипервизор.
Re: Asterisk 11 + Mariadb + Centos 7 - перезапуск
Добавлено: 15 июл 2021, 11:28
ded
В современных линуксах уже отказались от rc.local, и даже старый
chkconfig --list
ушёл в прошлое. Всё для стартапа рулится через systemd
systemctl (enable | disable | status | start | stop) mysql
systemctl (enable | disable | status | start | stop) asterisk
Re: Asterisk 11 + Mariadb + Centos 7 - перезапуск
Добавлено: 15 июл 2021, 11:28
gosha
service скрипт для systemd сделать для астериска и депендесами в нем mariadb поставить.
Re: Asterisk 11 + Mariadb + Centos 7 - перезапуск
Добавлено: 15 июл 2021, 11:37
ded
В готовых системах уже присутствуют
Код: Выделить всё
/etc/init.d/asterisk
#!/bin/sh
#
# asterisk start the asterisk PBX
# (c) Mark Purcell <msp@debian.org>
# (c) Tzafrir Cohen <tzafrir.cohen@xorcom.com>
# (c) Faidon Liambotis <paravoid@debian.org>
#
# This package is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
### BEGIN INIT INFO
# Provides: asterisk
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Should-Start: $syslog $network $named mysql postgresql dahdi
# Should-Stop: $syslog $network $named mysql postgresql
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Asterisk PBX
# Description: Controls the Asterisk PBX
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=asterisk
USER=$NAME
GROUP=$USER
DAEMON=/usr/sbin/$NAME
CANARY=/usr/sbin/astcanary
DESC="Asterisk PBX"
PIDFILE="/var/run/asterisk/asterisk.pid"
ASTSAFE_PIDFILE="/var/run/asterisk/asterisk_safe.pid"
UMASK=007 # by default
#MAXFILES=1024 # (the system default)
. /lib/lsb/init-functions
# by default: use real-time priority
PARAMS=""
CHDIR_PARM=""
AST_REALTIME="yes"
RUNASTERISK="yes"
AST_DUMPCORE="no"
AST_DUMPCORE_DIR="/var/spool/asterisk" # only used if AST_DUMPCORE != no
# core_pattern. See: http://lxr.linux.no/source/Documentation/sysctl/kernel.txt
#CORE_PATTERN=
if [ -r /etc/default/$NAME ]; then . /etc/default/$NAME; fi
if [ "$RUNASTERISK" != "yes" ];then
echo "Asterisk not yet configured. Edit /etc/default/asterisk first."
exit 0
fi
if [ "$AST_REALTIME" != "no" ]
then
PARAMS="$PARAMS -p"
fi
if [ "$AST_DUMPCORE" != "no" ]
then
PARAMS="$PARAMS -g"
if [ "$CORE_PATTERN" != '' ]
then
echo "$CORE_PATTERN" >/proc/sys/kernel/core_pattern
fi
if [ -d "$AST_DUMPCORE_DIR" ]
then
CHDIR_PARM="--chdir $AST_DUMPCORE_DIR"
fi
fi
if [ "x$USER" = "x" ]
then
echo "Error: empty USER name"
exit 1
fi
if [ `id -u "$USER"` = 0 ]
then
echo "Starting as root not supported."
exit 1
fi
PARAMS="$PARAMS -U $USER"
if [ "x$AST_DEBUG_PARAMS" = x ]
then
AST_DEBUG_PARAMS=-cvvvvvddddd
fi
if [ "$RUNASTSAFE" = "yes" ];then
# The value of WRAPPER_DAEMON in can be set in /etc/default/asterisk
WRAPPER_DAEMON=${WRAPPER_DAEMON:-/usr/sbin/safe_asterisk}
REALDAEMON="$WRAPPER_DAEMON"
else
REALDAEMON="$DAEMON"
fi
test -x $DAEMON || exit 0
for dir in /var/run/asterisk /var/log/asterisk /var/log/asterisk/cdr-csv /var/log/asterisk/cdr-custom; do
[ -d $dir ] || install -d -o $USER -g $GROUP $dir
[ -x /sbin/restorecon ] && /sbin/restorecon $dir
done
set -e
if [ "$UMASK" != '' ]
then
umask $UMASK
fi
# allow changing the per-process open files limit:
if [ "$MAXFILES" != '' ]
then
ulimit -n $MAXFILES
fi
status() {
status_of_proc -p "$PIDFILE" "$NAME" "$DESC" && return 0 || return $?
}
asterisk_rx() {
if ! status >/dev/null; then return 0; fi
# if $HOME is set, asterisk -rx writes a .asterisk_history there
(
unset HOME
$DAEMON -rx "$1"
)
}
case "$1" in
debug)
# we add too many special parameters that I don't want to skip
# accidentally. I'm afraid that skipping -U once may cause
# confusing results. I also want to maintain the user's choice
# of -p
echo "Debugging $DESC: "
$DAEMON $PARAMS $AST_DEBUG_PARAMS
exit 0
;;
start)
if status > /dev/null; then
echo "$DESC is already running. Use restart."
exit 0
fi
echo -n "Starting $DESC: "
if [ "$RUNASTSAFE" != "yes" ];then
# TODO: what if we cought the wrapper just as its asterisk
# was killed? status should check for the wrapper if we're in
# "safe mode"
if status > /dev/null; then
echo "$DESC is already running. Use restart."
exit 0
fi
start-stop-daemon --start --group $GROUP --pidfile "$PIDFILE" \
$CHDIR_PARM \
--exec $REALDAEMON -- $PARAMS > /dev/null
else
export ASTSAFE_FOREGROUND=1
start-stop-daemon --start --group $GROUP \
--background --make-pidfile \
$CHDIR_PARM --pidfile "$ASTSAFE_PIDFILE" \
--exec $REALDAEMON -- $PARAMS
fi
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: $NAME"
# Try gracefully.
# this may hang in some cases. Specifically, when the asterisk
# processes is stopped. No bother to worry about cleanup:
# it will either fail or die when asterisk dies.
( asterisk_rx 'core stop now' > /dev/null 2>&1 & ) &
if [ "$RUNASTSAFE" = "yes" ];then
start-stop-daemon --stop --quiet --oknodo \
--pidfile $ASTSAFE_PIDFILE
rm -f $ASTSAFE_PIDFILE
fi
start-stop-daemon --stop --quiet --oknodo --exec $DAEMON --pidfile=$PIDFILE
echo "."
;;
reload)
echo "Reloading $DESC configuration files."
asterisk_rx 'module reload'
;;
logger-reload)
asterisk_rx 'logger reload'
;;
extensions-reload|dialplan-reload)
echo "Reloading $DESC configuration files."
asterisk_rx 'dialplan reload'
;;
restart-convenient)
asterisk_rx 'core restart when convenient'
;;
restart|force-reload)
$0 stop
$0 start
;;
status)
status
exit $?
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|status|debug|logger-reload|extensions-reload|restart-convenient|force-reload}" >&2
exit 1
;;
esac
exit 0
Re: Asterisk 11 + Mariadb + Centos 7 - перезапуск
Добавлено: 15 июл 2021, 11:41
gosha
это sysv а не systemd
maria скорее всего идет с конфигом для systemD и если уж писать депендесы то лучше чтоб они в одном формате были. Но это тоже лучше чем rc.local
Re: Asterisk 11 + Mariadb + Centos 7 - перезапуск
Добавлено: 15 июл 2021, 11:45
ded
Вроде sysv совместима с systemd, во всяком случае в готовых дистрибутивах скрипты
systemctl (enable | disable | status | start | stop) mysql
systemctl (enable | disable | status | start | stop) asterisk
отрабатывают.
Код: Выделить всё
/etc/init.d/mysql
#!/bin/bash
#
### BEGIN INIT INFO
# Provides: mysql
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $network $named $time
# Should-Stop: $network $named $time
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop the mysql database server daemon
# Description: Controls the main MariaDB database server daemon "mysqld"
# and its wrapper script "mysqld_safe".
### END INIT INFO
#
set -e
set -u
${DEBIAN_SCRIPT_DEBUG:+ set -v -x}
test -x /usr/sbin/mysqld || exit 0
. /lib/lsb/init-functions
SELF=$(cd $(dirname $0); pwd -P)/$(basename $0)
CONF=/etc/mysql/my.cnf
MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
# priority can be overriden and "-s" adds output to stderr
ERR_LOGGER="logger -p daemon.err -t /etc/init.d/mysql -i"
# Safeguard (relative paths, core dumps..)
cd /
umask 077
# mysqladmin likes to read /root/.my.cnf. This is usually not what I want
# as many admins e.g. only store a password without a username there and
# so break my scripts.
export HOME=/etc/mysql/
## Fetch a particular option from mysql's invocation.
#
# Usage: void mysqld_get_param option
mysqld_get_param() {
/usr/sbin/mysqld --print-defaults \
| tr " " "\n" \
| grep -- "--$1" \
| tail -n 1 \
| cut -d= -f2
}
## Do some sanity checks before even trying to start mysqld.
sanity_checks() {
# check for config file
if [ ! -r /etc/mysql/my.cnf ]; then
log_warning_msg "$0: WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz"
echo "WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz" | $ERR_LOGGER
fi
# check for diskspace shortage
datadir=`mysqld_get_param datadir`
if LC_ALL=C BLOCKSIZE= df --portability $datadir/. | tail -n 1 | awk '{ exit ($4>4096) }'; then
log_failure_msg "$0: ERROR: The partition with $datadir is too full!"
echo "ERROR: The partition with $datadir is too full!" | $ERR_LOGGER
exit 1
fi
}
## Checks if there is a server running and if so if it is accessible.
#
# check_alive insists on a pingable server
# check_dead also fails if there is a lost mysqld in the process list
#
# Usage: boolean mysqld_status [check_alive|check_dead] [warn|nowarn]
mysqld_status () {
ping_output=`$MYADMIN ping 2>&1`; ping_alive=$(( ! $? ))
ps_alive=0
pidfile=`mysqld_get_param pid-file`
if [ -f "$pidfile" ] && ps `cat $pidfile` >/dev/null 2>&1; then ps_alive=1; fi
if [ "$1" = "check_alive" -a $ping_alive = 1 ] ||
[ "$1" = "check_dead" -a $ping_alive = 0 -a $ps_alive = 0 ]; then
return 0 # EXIT_SUCCESS
else
if [ "$2" = "warn" ]; then
echo -e "$ps_alive processes alive and '$MYADMIN ping' resulted in\n$ping_output\n" | $ERR_LOGGER -p daemon.debug
fi
return 1 # EXIT_FAILURE
fi
}
#
# main()
#
case "${1:-''}" in
'start')
sanity_checks;
# Start daemon
log_daemon_msg "Starting MariaDB database server" "mysqld"
if mysqld_status check_alive nowarn; then
log_progress_msg "already running"
log_end_msg 0
else
# Could be removed during boot
test -e /var/run/mysqld || install -m 755 -o mysql -g root -d /var/run/mysqld
# Start MariaDB!
/usr/bin/mysqld_safe "${@:2}" 2>&1 >/dev/null | $ERR_LOGGER &
# 6s was reported in #352070 to be too few when using ndbcluster
for i in $(seq 1 "${MYSQLD_STARTUP_TIMEOUT:-30}"); do
sleep 1
if mysqld_status check_alive nowarn ; then break; fi
log_progress_msg "."
done
if mysqld_status check_alive warn; then
log_end_msg 0
# Now start mysqlcheck or whatever the admin wants.
output=$(/etc/mysql/debian-start)
if [ -n "$output" ]; then
log_action_msg "$output"
fi
else
log_end_msg 1
log_failure_msg "Please take a look at the syslog"
fi
fi
;;
'stop')
# * As a passwordless mysqladmin (e.g. via ~/.my.cnf) must be possible
# at least for cron, we can rely on it here, too. (although we have
# to specify it explicit as e.g. sudo environments points to the normal
# users home and not /root)
log_daemon_msg "Stopping MariaDB database server" "mysqld"
if ! mysqld_status check_dead nowarn; then
set +e
shutdown_out=`$MYADMIN shutdown 2>&1`; r=$?
set -e
if [ "$r" -ne 0 ]; then
log_end_msg 1
[ "$VERBOSE" != "no" ] && log_failure_msg "Error: $shutdown_out"
log_daemon_msg "Killing MariaDB database server by signal" "mysqld"
killall -15 mysqld
server_down=
for i in `seq 1 600`; do
sleep 1
if mysqld_status check_dead nowarn; then server_down=1; break; fi
done
if test -z "$server_down"; then killall -9 mysqld; fi
fi
fi
if ! mysqld_status check_dead warn; then
log_end_msg 1
log_failure_msg "Please stop MariaDB manually and read /usr/share/doc/mariadb-server-10.0/README.Debian.gz!"
exit -1
else
log_end_msg 0
fi
;;
'restart')
set +e; $SELF stop; set -e
shift
$SELF start "${@}"
;;
'reload'|'force-reload')
log_daemon_msg "Reloading MariaDB database server" "mysqld"
$MYADMIN reload
log_end_msg 0
;;
'status')
if mysqld_status check_alive nowarn; then
log_action_msg "$($MYADMIN version)"
else
log_action_msg "MariaDB is stopped."
exit 3
fi
;;
*)
echo "Usage: $SELF start|stop|restart|reload|force-reload|status"
exit 1
;;
esac