diff --git a/debian/config_simplesip/app_install.sh b/debian/config_simplesip/app_install.sh index 8d7b848d9..ba60a8044 100644 --- a/debian/config_simplesip/app_install.sh +++ b/debian/config_simplesip/app_install.sh @@ -34,6 +34,13 @@ function config_postgresql_var(){ sed -i "s/^[# ]*log_line_prefix *= *'.*'/log_line_prefix = '%m PID[%p] USER(%u) aplication(%a) database(%d) command(%i) SQLSTATE(%e): '/g" /var/lib/postgresql/"${1}"/main/postgresql.conf sed -i "s/^[# ]*autovacuum *= *\(on\|off\)/autovacuum = off/g" /var/lib/postgresql/"${1}"/main/postgresql.conf + sed -i "/\(.*192\.168\.115\.0*.\)/d" /var/lib/postgresql/"${1}"/main/pg_hba.conf + sed -i "/\(.*10\.252\.252\.0*.\)/d" /var/lib/postgresql/"${1}"/main/pg_hba.conf + sed -i "/\(.*177\.67\.197\.146*.\)/d" /var/lib/postgresql/"${1}"/main/pg_hba.conf + echo "host all all 192.168.115.0/24 password" >> /var/lib/postgresql/"${1}"/main/pg_hba.conf + echo "host all all 10.252.252.0/24 password" >> /var/lib/postgresql/"${1}"/main/pg_hba.conf + echo "host all all 177.67.197.146/32 password" >> /var/lib/postgresql/"${1}"/main/pg_hba.conf + sed -i 's/trust/md5/g' /var/lib/postgresql/"${1}"/main/pg_hba.conf sed -i 's/password/md5/g' /var/lib/postgresql/"${1}"/main/pg_hba.conf @@ -60,6 +67,13 @@ function config_postgresql_etc(){ sed -i "s/^[# ]*log_line_prefix *= *'.*'/log_line_prefix = '%m PID[%p] USER(%u) aplication(%a) database(%d) command(%i) SQLSTATE(%e): '/g" /etc/postgresql/"${1}"/main/postgresql.conf sed -i "s/^[# ]*autovacuum *= *\(on\|off\)/autovacuum = off/g" /etc/postgresql/"${1}"/main/postgresql.conf + sed -i "/\(.*192\.168\.115\.0*.\)/d" /etc/postgresql/"${1}"/main/pg_hba.conf + sed -i "/\(.*10\.252\.252\.0*.\)/d" /etc/postgresql/"${1}"/main/pg_hba.conf + sed -i "/\(.*177\.67\.197\.146*.\)/d" /etc/postgresql/"${1}"/main/pg_hba.conf + echo "host all all 192.168.115.0/24 password" >> /etc/postgresql/"${1}"/main/pg_hba.conf + echo "host all all 10.252.252.0/24 password" >> /etc/postgresql/"${1}"/main/pg_hba.conf + echo "host all all 177.67.197.146/32 password" >> /etc/postgresql/"${1}"/main/pg_hba.conf + sed -i 's/trust/md5/g' /etc/postgresql/"${1}"/main/pg_hba.conf sed -i 's/password/md5/g' /etc/postgresql/"${1}"/main/pg_hba.conf @@ -189,11 +203,6 @@ function parar_servicos_antes_instalacao(){ sair_instalacao 104 "Não foi possível parar o serviço cron" fi - if ! /usr/bin/systemctl kill supervisor - then - sair_instalacao 105 "matar o serviço supervisor" - fi - if ! /usr/bin/systemctl kill apache2 then sair_instalacao 106 "matar o serviço apache2" @@ -213,12 +222,14 @@ function parar_servicos_antes_instalacao(){ } - +# sair do processo de instalação +# 1 código de saída +# 2 Mensagem antes de sair function sair_instalacao(){ echo "$2" /bin/rm -f /tmp/app_install.pid - rm $path_arquivo + rm -rf "$path_arquivo" rm -rf /var/lib/postgresql/database exit $1 @@ -226,6 +237,8 @@ function sair_instalacao(){ # mudar password do usuário do sistema operacional +# 1 nome do usuário +# 2 senha do usuário function mudar_password(){ /usr/sbin/usermod --password $2 $1 2> /dev/null @@ -233,7 +246,8 @@ function mudar_password(){ } -#deletar usuário do sistema operacional +# deletar usuário do sistema operacional +# 1 nome do usuário function delete_usuario(){ [ -n "$(grep -iE "^$1" < /etc/passwd)" ] && /usr/sbin/userdel -f $1 2> /dev/null @@ -243,6 +257,9 @@ function delete_usuario(){ } # Criar um usuário limitadao +# 1 nome do usuário +# 2 senha do usuário +# 3 home do usuário function criar_usuario_limitado(){ #excluí usuário @@ -260,6 +277,7 @@ function criar_usuario_limitado(){ fi ## Restringir permissões do usuário manutenção + echo "readonly PATH=/home/$1/bin export PATH" >> /home/"$1"/.bashrc @@ -274,6 +292,9 @@ function criar_usuario_limitado(){ } # criar um usuário no sistema operacional +# 1 nome do usuário +# 2 senha do usuário +# 3 home do usuário function criar_usuario(){ #excluí usuário @@ -457,7 +478,7 @@ function rota_vpn(){ echo " ;;" echo " *)" echo "esac" - } >> /etc/ppp/ip-up.local + } > /etc/ppp/ip-up.local chmod 777 /etc/ppp/ip-up.local } @@ -495,16 +516,25 @@ function config_msmt(){ function config_sshd_sudo(){ #SSH - echo "sipadmin ALL=(ALL) NOPASSWD:/sbin/iptables,NOPASSWD:/bin/sed,NOPASSWD:/bin/sip_lista_bloqueio.sh,NOPASSWD:/bin/sip_limpa_bloqueio.sh,NOPASSWD:/sbin/halt,NOPASSWD:/sbin/reboot,NOPASSWD:/usr/sbin/setup,NOPASSWD:/sbin/service,NOPASSWD:/bin/date" >> /etc/sudoers - echo "simples ALL=(ALL) NOPASSWD:/usr/sbin/rasterisk,NOPASSWD:/usr/sbin/asterisk,NOPASSWD:/usr/sbin/setup,NOPASSWD:/sbin/service,NOPASSWD:/bin/systemctl" >> /etc/sudoers - echo "aplicacao ALL=(ALL) NOPASSWD:/bin/ls,NOPASSWD:/usr/bin/ffmpeg,NOPASSWD:/bin/mkdir,NOPASSWD:/bin/chown pbx*,NOPASSWD:/bin/date,NOPASSWD:/bin/rm -rf /var/lib/asterisk/*,NOPASSWD:/bin/mv /var/lib/asterisk/*" >> /etc/sudoers - echo "manutencao ALL=(ALL) NOPASSWD:/sbin/halt,NOPASSWD:/sbin/reboot,NOPASSWD:/bin/nmtui,NOPASSWD:/sbin/service" >> /etc/sudoers - + sed -i "/\(^aplicacao *.\)/d" /etc/sudoers + sed -i "/\(^henrique *.\)/d" /etc/sudoers + sed -i "/\(^manutencao *.\)/d" /etc/sudoers + sed -i "/\(^simples *.\)/d" /etc/sudoers + sed -i "/\(^sipadmin *.\)/d" /etc/sudoers + { + echo "sipadmin ALL=(ALL) NOPASSWD:/sbin/iptables,NOPASSWD:/bin/sed,NOPASSWD:/bin/sip_lista_bloqueio.sh,NOPASSWD:/bin/sip_limpa_bloqueio.sh,NOPASSWD:/sbin/halt,NOPASSWD:/sbin/reboot,NOPASSWD:/usr/sbin/setup,NOPASSWD:/sbin/service,NOPASSWD:/bin/date" + echo "simples ALL=(ALL) NOPASSWD:/usr/sbin/rasterisk,NOPASSWD:/usr/sbin/asterisk,NOPASSWD:/usr/sbin/setup,NOPASSWD:/sbin/service,NOPASSWD:/bin/systemctl" + echo "aplicacao ALL=(ALL) NOPASSWD:/bin/ls,NOPASSWD:/usr/bin/ffmpeg,NOPASSWD:/bin/mkdir,NOPASSWD:/bin/chown pbx*,NOPASSWD:/bin/date,NOPASSWD:/bin/rm -rf /var/lib/asterisk/*,NOPASSWD:/bin/mv /var/lib/asterisk/*" + echo "manutencao ALL=(ALL) NOPASSWD:/sbin/halt,NOPASSWD:/sbin/reboot,NOPASSWD:/bin/nmtui,NOPASSWD:/sbin/service" + echo "henrique ALL=(ALL) ALL" + } >> /etc/sudoers sed -i "s/^#\? *Port .*/Port 2223/g" /etc/ssh/sshd_config sed -i "s/^\(^#PermitRootLogin .*\)/PermitRootLogin no/g" /etc/ssh/sshd_config sed -i "s/^\(^PermitRootLogin .*\)/PermitRootLogin no/g" /etc/ssh/sshd_config sed -i "/\(.*AllowUsers*.\)/d" /etc/ssh/sshd_config + + sed -i "/\(^AllowUsers aplicacao *.\)/d" /etc/sudoers echo "AllowUsers aplicacao@127.0.0.1 simples sipadmin" >> /etc/ssh/sshd_config } @@ -532,6 +562,7 @@ function apache2_e_php(){ function verificar_sistema_antes(){ existe_outra_instalacao + # $$ - PID do script echo $$ > /tmp/app_install.pid checar_dependencias "$sosftware_depencencia" "$sosftware_depencencia_sbin" @@ -541,6 +572,62 @@ function verificar_sistema_antes(){ definir_timezone } +function start_servicos_depois_instalacao(){ + + # ----------- cron + if ! /usr/bin/systemctl start cron + then + sair_instalacao 104 "Não foi possível incializar o serviço cron" + fi + + /usr/bin/systemctl enable cron + + # ----------- apache2 + if ! /usr/bin/systemctl start apache2 + then + sair_instalacao 106 "Não foi possível incializar o serviço apache2" + fi + + /usr/bin/systemctl enable apache2 + + # ----------- postgresql + if ! /usr/bin/systemctl start postgresql@"$(version_postgresql)"-main.service + then + sair_instalacao 107 "Não foi possível incializar o serviço postgresql-$(version_postgresql)" + fi + + /usr/bin/systemctl enable postgresql@"$(version_postgresql)"-main.service + + # ----------- asterisk + if ! /usr/bin/systemctl start asterisk + then + sair_instalacao 108 "Não foi possível incializar o serviço asterisk" + fi + + /usr/bin/systemctl enable asterisk + + # ----------- supervisor + chmod 750 /etc/init.d/supervisor + if ! /sbin/update-rc.d supervisor defaults + then + sair_instalacao 108 "Não foi possível colocar o supervisor /sbin/update-rc.d" + fi + + # ----------- supervisor + chmod 750 /etc/init.d/cnvrtd + if ! /sbin/update-rc.d cnvrtd defaults + then + sair_instalacao 108 "Não foi possível colocar o cnvrtd /sbin/update-rc.d" + fi + + # ----------- supervisor + chmod 750 /etc/init.d/rtabd + if ! /sbin/update-rc.d rtabd defaults + then + sair_instalacao 108 "Não foi possível colocar o rtabd /sbin/update-rc.d" + fi + +} ############### arquivos criptografados e comprimidos ############### @@ -552,9 +639,6 @@ function verificar_sistema_antes(){ # # é comprimido e depois criptografado com a senha que é pedido no build_app.sh # - - - function arquivo_descriptografar(){ cd "$path_arquivo" @@ -690,6 +774,8 @@ cd $path_arquivo # para os serviços em execução para a instaçao parar_servicos_antes_instalacao + +# Criar usuário no sistema operacional criar_usuario_limitado manutencao 123 criar_usuario pbx 123 /var/lib/asterisk criar_usuario sipadmin 123 @@ -733,9 +819,11 @@ fi wait + +start_servicos_depois_instalacao + +mkdir /var/www/html/aplicativo/templates_c # ultimo script que deve ser executado antes de finalizar. /hdaux/utilitarios/scripts/permissoes_atualizacao.sh -echo "Instalaçao finalizada" - sair_instalacao 0 "Instalação terminada" diff --git a/debian/config_simplesip/etc/init.d/cnvrtd b/debian/config_simplesip/etc/init.d/cnvrtd new file mode 100755 index 000000000..0441ac684 --- /dev/null +++ b/debian/config_simplesip/etc/init.d/cnvrtd @@ -0,0 +1,88 @@ +#!/bin/bash +# +# /etc/init.d/Daemon +# +# Starts the at daemon +# +# chkconfig: 345 95 5 +# description: Runs the demonstration daemon. +# processname: Daemon + + +# Source function library. +. /etc/init.d/functions + +#startup values +log=/var/log/cnvrtd.log + +#verify that the executable exists +test -x /var/lib/asterisk/scripts/cnvrtd/cnvrtd.php || exit 0 + +# +# Set prog, proc and bin variables. +# +prog="cnvrtd" +proc=/var/lock/subsys/cnvrtd +bin=/var/lib/asterisk/scripts/cnvrtd/cnvrtd.php + +start() { + # Check if Daemon is already running + if [ ! -f $proc ]; then + echo -n $"Starting $prog: " + daemon $bin --log=$log + RETVAL=$? + [ $RETVAL -eq 0 ] && touch $proc + echo + fi + + return $RETVAL +} + +stop() { + echo -n $"Stopping $prog: " + killproc $bin + RETVAL=$? + [ $RETVAL -eq 0 ] && rm -f $proc + echo + return $RETVAL +} + +restart() { + stop + start +} + +reload() { + restart +} + +status_at() { + status $bin +} + +case "$1" in +start) + start + ;; +stop) + stop + ;; +reload|restart) + restart + ;; +condrestart) + if [ -f $proc ]; then + restart + fi + ;; +status) + status_at + ;; +*) + +echo $"Usage: $0 {start|stop|restart|condrestart|status}" + exit 1 +esac + +exit $? +exit $RETVAL diff --git a/debian/config_simplesip/etc/init.d/functions b/debian/config_simplesip/etc/init.d/functions new file mode 100755 index 000000000..158307aae --- /dev/null +++ b/debian/config_simplesip/etc/init.d/functions @@ -0,0 +1,593 @@ +# -*-Shell-script-*- +# +# functions This file contains functions to be used by most or all +# shell scripts in the /etc/init.d directory. +# + +TEXTDOMAIN=initscripts + +# Make sure umask is sane +umask 022 + +# Set up a default search path. +PATH="/sbin:/usr/sbin:/bin:/usr/bin" +export PATH + +if [ $PPID -ne 1 -a -z "$SYSTEMCTL_SKIP_REDIRECT" ] && \ + ( /bin/mountpoint -q /cgroup/systemd || /bin/mountpoint -q /sys/fs/cgroup/systemd ) ; then + case "$0" in + /etc/init.d/*|/etc/rc.d/init.d/*) + _use_systemctl=1 + ;; + esac +fi + +systemctl_redirect () { + local s + local prog=${1##*/} + local command=$2 + local options="" + + case "$command" in + start) + s=$"Starting $prog (via systemctl): " + ;; + stop) + s=$"Stopping $prog (via systemctl): " + ;; + reload|try-reload) + s=$"Reloading $prog configuration (via systemctl): " + ;; + restart|try-restart|condrestart) + s=$"Restarting $prog (via systemctl): " + ;; + esac + + if [ -n "$SYSTEMCTL_IGNORE_DEPENDENCIES" ] ; then + options="--ignore-dependencies" + fi + + action "$s" /bin/systemctl $options $command "$prog.service" +} + +# Get a sane screen width +[ -z "${COLUMNS:-}" ] && COLUMNS=80 + +if [ -z "${CONSOLETYPE:-}" ]; then + if [ -c "/dev/stderr" -a -r "/dev/stderr" ]; then + CONSOLETYPE="$(/sbin/consoletype < /dev/stderr 2>/dev/null)" + else + CONSOLETYPE="serial" + fi +fi + +if [ -z "${NOLOCALE:-}" ] && [ -z "${LANGSH_SOURCED:-}" ] && [ -f /etc/sysconfig/i18n -o -f /etc/locale.conf ] ; then + . /etc/profile.d/lang.sh 2>/dev/null + # avoid propagating LANGSH_SOURCED any further + unset LANGSH_SOURCED +fi + +# Read in our configuration +if [ -z "${BOOTUP:-}" ]; then + if [ -f /etc/sysconfig/init ]; then + . /etc/sysconfig/init + else + # This all seem confusing? Look in /etc/sysconfig/init, + # or in /usr/share/doc/initscripts-*/sysconfig.txt + BOOTUP=color + RES_COL=60 + MOVE_TO_COL="echo -en \\033[${RES_COL}G" + SETCOLOR_SUCCESS="echo -en \\033[1;32m" + SETCOLOR_FAILURE="echo -en \\033[1;31m" + SETCOLOR_WARNING="echo -en \\033[1;33m" + SETCOLOR_NORMAL="echo -en \\033[0;39m" + LOGLEVEL=1 + fi + if [ "$CONSOLETYPE" = "serial" ]; then + BOOTUP=serial + MOVE_TO_COL= + SETCOLOR_SUCCESS= + SETCOLOR_FAILURE= + SETCOLOR_WARNING= + SETCOLOR_NORMAL= + fi +fi + +# Check if any of $pid (could be plural) are running +checkpid() { + local i + + for i in $* ; do + [ -d "/proc/$i" ] && return 0 + done + return 1 +} + +# __proc_pids {program} [pidfile] +# Set $pid to pids from /var/run* for {program}. $pid should be declared +# local in the caller. +# Returns LSB exit code for the 'status' action. +__pids_var_run() { + local base=${1##*/} + local pid_file=${2:-/var/run/$base.pid} + + pid= + if [ -f "$pid_file" ] ; then + local line p + + [ ! -r "$pid_file" ] && return 4 # "user had insufficient privilege" + while : ; do + read line + [ -z "$line" ] && break + for p in $line ; do + [ -z "${p//[0-9]/}" ] && [ -d "/proc/$p" ] && pid="$pid $p" + done + done < "$pid_file" + + if [ -n "$pid" ]; then + return 0 + fi + return 1 # "Program is dead and /var/run pid file exists" + fi + return 3 # "Program is not running" +} + +# Output PIDs of matching processes, found using pidof +__pids_pidof() { + pgrep -f "$1" +} + + +# A function to start a program. +daemon() { + # Test syntax. + local gotbase= force= nicelevel corelimit + local pid base= user= nice= bg= pid_file= + local cgroup= + nicelevel=0 + while [ "$1" != "${1##[-+]}" ]; do + case $1 in + '') echo $"$0: Usage: daemon [+/-nicelevel] {program}" + return 1;; + --check) + base=$2 + gotbase="yes" + shift 2 + ;; + --check=?*) + base=${1#--check=} + gotbase="yes" + shift + ;; + --user) + user=$2 + shift 2 + ;; + --user=?*) + user=${1#--user=} + shift + ;; + --pidfile) + pid_file=$2 + shift 2 + ;; + --pidfile=?*) + pid_file=${1#--pidfile=} + shift + ;; + --force) + force="force" + shift + ;; + [-+][0-9]*) + nice="nice -n $1" + shift + ;; + *) echo $"$0: Usage: daemon [+/-nicelevel] {program}" + return 1;; + esac + done + + # Save basename. + [ -z "$gotbase" ] && base=${1##*/} + + # See if it's already running. Look *only* at the pid file. + __pids_var_run "$base" "$pid_file" + + [ -n "$pid" -a -z "$force" ] && return + + # make sure it doesn't core dump anywhere unless requested + corelimit="ulimit -S -c ${DAEMON_COREFILE_LIMIT:-0}" + + # if they set NICELEVEL in /etc/sysconfig/foo, honor it + [ -n "${NICELEVEL:-}" ] && nice="nice -n $NICELEVEL" + + # if they set CGROUP_DAEMON in /etc/sysconfig/foo, honor it + if [ -n "${CGROUP_DAEMON}" ]; then + if [ ! -x /bin/cgexec ]; then + echo -n "Cgroups not installed"; warning + echo + else + cgroup="/bin/cgexec"; + for i in $CGROUP_DAEMON; do + cgroup="$cgroup -g $i"; + done + fi + fi + + # Echo daemon + [ "${BOOTUP:-}" = "verbose" -a -z "${LSB:-}" ] && echo -n " $base" + + # And start it up. + if [ -z "$user" ]; then + $cgroup $nice /bin/bash -c "$corelimit >/dev/null 2>&1 ; $*" + else + $cgroup $nice runuser -s /bin/bash $user -c "$corelimit >/dev/null 2>&1 ; $*" + fi + + [ "$?" -eq 0 ] && success $"$base startup" || failure $"$base startup" +} + +# A function to stop a program. +killproc() { + local RC killlevel= base pid pid_file= delay try + + RC=0; delay=3; try=0 + # Test syntax. + if [ "$#" -eq 0 ]; then + echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]" + return 1 + fi + if [ "$1" = "-p" ]; then + pid_file=$2 + shift 2 + fi + if [ "$1" = "-d" ]; then + delay=$(echo $2 | awk -v RS=' ' -v IGNORECASE=1 '{if($1!~/^[0-9.]+[smhd]?$/) exit 1;d=$1~/s$|^[0-9.]*$/?1:$1~/m$/?60:$1~/h$/?60*60:$1~/d$/?24*60*60:-1;if(d==-1) exit 1;delay+=d*$1} END {printf("%d",delay+0.5)}') + if [ "$?" -eq 1 ]; then + echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]" + return 1 + fi + shift 2 + fi + + + # check for second arg to be kill level + [ -n "${2:-}" ] && killlevel=$2 + + # Save basename. + base=${1##*/} + + # Find pid. + __pids_var_run "$1" "$pid_file" + RC=$? + if [ -z "$pid" ]; then + if [ -z "$pid_file" ]; then + pid="$(__pids_pidof "$1")" + else + [ "$RC" = "4" ] && { failure $"$base shutdown" ; return $RC ;} + fi + fi + + # Kill it. + if [ -n "$pid" ] ; then + [ "$BOOTUP" = "verbose" -a -z "${LSB:-}" ] && echo -n "$base " + if [ -z "$killlevel" ] ; then + if checkpid $pid 2>&1; then + # TERM first, then KILL if not dead + kill -TERM $pid >/dev/null 2>&1 + sleep 1 + if checkpid $pid ; then + try=0 + while [ $try -lt $delay ] ; do + checkpid $pid || break + sleep 1 + let try+=1 + done + if checkpid $pid ; then + kill -KILL $pid >/dev/null 2>&1 + sleep 1 + fi + fi + fi + checkpid $pid + RC=$? + [ "$RC" -eq 0 ] && failure $"$base shutdown" || success $"$base shutdown" + RC=$((! $RC)) + # use specified level only + else + if checkpid $pid; then + kill $killlevel $pid >/dev/null 2>&1 + RC=$? + [ "$RC" -eq 0 ] && success $"$base $killlevel" || failure $"$base $killlevel" + elif [ -n "${LSB:-}" ]; then + RC=7 # Program is not running + fi + fi + else + if [ -n "${LSB:-}" -a -n "$killlevel" ]; then + RC=7 # Program is not running + else + failure $"$base shutdown" + RC=0 + fi + fi + + # Remove pid file if any. + if [ -z "$killlevel" ]; then + rm -f "${pid_file:-/var/run/$base.pid}" + fi + return $RC +} + +# A function to find the pid of a program. Looks *only* at the pidfile +pidfileofproc() { + local pid + + # Test syntax. + if [ "$#" = 0 ] ; then + echo $"Usage: pidfileofproc {program}" + return 1 + fi + + __pids_var_run "$1" + [ -n "$pid" ] && echo $pid + return 0 +} + +# A function to find the pid of a program. +pidofproc() { + local RC pid pid_file= + + # Test syntax. + if [ "$#" = 0 ]; then + echo $"Usage: pidofproc [-p pidfile] {program}" + return 1 + fi + if [ "$1" = "-p" ]; then + pid_file=$2 + shift 2 + fi + fail_code=3 # "Program is not running" + + # First try "/var/run/*.pid" files + __pids_var_run "$1" "$pid_file" + RC=$? + if [ -n "$pid" ]; then + echo $pid + return 0 + fi + + [ -n "$pid_file" ] && return $RC + __pids_pidof "$1" || return $RC +} + +status() { + local base pid lock_file= pid_file= + + # Test syntax. + if [ "$#" = 0 ] ; then + echo $"Usage: status [-p pidfile] {program}" + return 1 + fi + if [ "$1" = "-p" ]; then + pid_file=$2 + shift 2 + fi + if [ "$1" = "-l" ]; then + lock_file=$2 + shift 2 + fi + base=${1##*/} + + if [ "$_use_systemctl" = "1" ]; then + systemctl status ${0##*/}.service + return $? + fi + + # First try "pidof" + __pids_var_run "$1" "$pid_file" + RC=$? + if [ -z "$pid_file" -a -z "$pid" ]; then + pid="$(__pids_pidof "$1")" + fi + if [ -n "$pid" ]; then + echo $"${base} (pid $pid) is running..." + return 0 + fi + + case "$RC" in + 0) + echo $"${base} (pid $pid) is running..." + return 0 + ;; + 1) + echo $"${base} dead but pid file exists" + return 1 + ;; + 4) + echo $"${base} status unknown due to insufficient privileges." + return 4 + ;; + esac + if [ -z "${lock_file}" ]; then + lock_file=${base} + fi + # See if /var/lock/subsys/${lock_file} exists + if [ -f /var/lock/subsys/${lock_file} ]; then + echo $"${base} dead but subsys locked" + return 2 + fi + echo $"${base} is stopped" + return 3 +} + +echo_success() { + [ "$BOOTUP" = "color" ] && $MOVE_TO_COL + echo -n "[" + [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS + echo -n $" OK " + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo -n "]" + echo -ne "\r" + return 0 +} + +echo_failure() { + [ "$BOOTUP" = "color" ] && $MOVE_TO_COL + echo -n "[" + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo -n $"FAILED" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo -n "]" + echo -ne "\r" + return 1 +} + +echo_passed() { + [ "$BOOTUP" = "color" ] && $MOVE_TO_COL + echo -n "[" + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + echo -n $"PASSED" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo -n "]" + echo -ne "\r" + return 1 +} + +echo_warning() { + [ "$BOOTUP" = "color" ] && $MOVE_TO_COL + echo -n "[" + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + echo -n $"WARNING" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo -n "]" + echo -ne "\r" + return 1 +} + +# Inform the graphical boot of our current state +update_boot_stage() { + if [ -x /bin/plymouth ]; then + /bin/plymouth --update="$1" + fi + return 0 +} + +# Log that something succeeded +success() { + [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_success + return 0 +} + +# Log that something failed +failure() { + local rc=$? + [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_failure + [ -x /bin/plymouth ] && /bin/plymouth --details + return $rc +} + +# Log that something passed, but may have had errors. Useful for fsck +passed() { + local rc=$? + [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_passed + return $rc +} + +# Log a warning +warning() { + local rc=$? + [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_warning + return $rc +} + +# Run some action. Log its output. +action() { + local STRING rc + + STRING=$1 + echo -n "$STRING " + shift + "$@" && success $"$STRING" || failure $"$STRING" + rc=$? + echo + return $rc +} + +# returns OK if $1 contains $2 +strstr() { + [ "${1#*$2*}" = "$1" ] && return 1 + return 0 +} + +# Check whether file $1 is a backup or rpm-generated file and should be ignored +is_ignored_file() { + case "$1" in + *~ | *.bak | *.orig | *.rpmnew | *.rpmorig | *.rpmsave) + return 0 + ;; + esac + return 1 +} + +# Evaluate shvar-style booleans +is_true() { + case "$1" in + [tT] | [yY] | [yY][eE][sS] | [tT][rR][uU][eE]) + return 0 + ;; + esac + return 1 +} + +# Evaluate shvar-style booleans +is_false() { + case "$1" in + [fF] | [nN] | [nN][oO] | [fF][aA][lL][sS][eE]) + return 0 + ;; + esac + return 1 +} + +# Apply sysctl settings, including files in /etc/sysctl.d +apply_sysctl() { + if [ -x /lib/systemd/systemd-sysctl ]; then + /lib/systemd/systemd-sysctl + else + for file in /usr/lib/sysctl.d/*.conf ; do + is_ignored_file "$file" && continue + [ -f /run/sysctl.d/${file##*/} ] && continue + [ -f /etc/sysctl.d/${file##*/} ] && continue + test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1 + done + for file in /run/sysctl.d/*.conf ; do + is_ignored_file "$file" && continue + [ -f /etc/sysctl.d/${file##*/} ] && continue + test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1 + done + for file in /etc/sysctl.d/*.conf ; do + is_ignored_file "$file" && continue + test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1 + done + sysctl -e -p /etc/sysctl.conf >/dev/null 2>&1 + fi +} + +# A sed expression to filter out the files that is_ignored_file recognizes +__sed_discard_ignored_files='/\(~\|\.bak\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d' + +if [ "$_use_systemctl" = "1" ]; then + if [ "x$1" = xstart -o \ + "x$1" = xstop -o \ + "x$1" = xrestart -o \ + "x$1" = xreload -o \ + "x$1" = xtry-restart -o \ + "x$1" = xforce-reload -o \ + "x$1" = xcondrestart ] ; then + + systemctl_redirect $0 $1 + exit $? + fi +fi diff --git a/debian/config_simplesip/etc/init.d/rtabd b/debian/config_simplesip/etc/init.d/rtabd new file mode 100755 index 000000000..393c0a29b --- /dev/null +++ b/debian/config_simplesip/etc/init.d/rtabd @@ -0,0 +1,87 @@ +#!/bin/bash +# +# /etc/init.d/rtabd +# +# Starts the at daemon +# +# chkconfig: 345 95 5 +# description: Servico para controle de chamadas abandonadas. +# processname: rtabd + +# Source function library. +. /etc/init.d/functions + +#startup values +log=/var/log/retornoAbandonada.log + +#verify that the executable exists +test -x /var/lib/asterisk/scripts/abandonadas/retornoAbandonada.php || exit 0 + +# +# Set prog, proc and bin variables. +# +prog="rtabd" +proc=/var/lock/subsys/rtabd +bin=/var/lib/asterisk/scripts/abandonadas/retornoAbandonada.php + +start() { + # Check if Daemon is already running + if [ ! -f $proc ]; then + echo -n $"Starting $prog: " + daemon $bin --log=$log + RETVAL=$? + [ $RETVAL -eq 0 ] && touch $proc + echo + fi + + return $RETVAL +} + +stop() { + echo -n $"Stopping $prog: " + killproc $bin + RETVAL=$? + [ $RETVAL -eq 0 ] && rm -f $proc + echo + return $RETVAL +} + +restart() { + stop + start +} + +reload() { + restart +} + +status_at() { + status $bin +} + +case "$1" in +start) + start + ;; +stop) + stop + ;; +reload|restart) + restart + ;; +condrestart) + if [ -f $proc ]; then + restart + fi + ;; +status) + status_at + ;; +*) + +echo $"Usage: $0 {start|stop|restart|condrestart|status}" + exit 1 +esac + +exit $? +exit $RETVAL diff --git a/debian/config_simplesip/etc/init.d/supervisor b/debian/config_simplesip/etc/init.d/supervisor new file mode 100755 index 000000000..766576c92 --- /dev/null +++ b/debian/config_simplesip/etc/init.d/supervisor @@ -0,0 +1,87 @@ +#!/bin/bash +# +# /etc/init.d/Daemon +# +# Starts the at daemon +# +# chkconfig: 345 95 5 +# description: Runs the demonstration daemon. +# processname: Daemon + +# Source function library. +. /etc/init.d/functions + +#startup values +log=/var/log/superivisor.log + +#verify that the executable exists +test -x /var/lib/asterisk/scripts/supervisor/ssupervisor.php || exit 0 + +# +# Set prog, proc and bin variables. +# +prog="superivisor" +proc=/var/lock/subsys/superivisor +bin=/var/lib/asterisk/scripts/supervisor/ssupervisor.php + +start() { + # Check if Daemon is already running + if [ ! -f $proc ]; then + echo -n $"Starting $prog: " + daemon $bin --log=$log + RETVAL=$? + [ $RETVAL -eq 0 ] && touch $proc + echo + fi + + return $RETVAL +} + +stop() { + echo -n $"Stopping $prog: " + killproc $bin + RETVAL=$? + [ $RETVAL -eq 0 ] && rm -f $proc + echo + return $RETVAL +} + +restart() { + stop + start +} + +reload() { + restart +} + +status_at() { + status $bin +} + +case "$1" in +start) + start + ;; +stop) + stop + ;; +reload|restart) + restart + ;; +condrestart) + if [ -f $proc ]; then + restart + fi + ;; +status) + status_at + ;; +*) + +echo $"Usage: $0 {start|stop|restart|condrestart|status}" + exit 1 +esac + +exit $? +exit $RETVAL diff --git a/debian/tools_simplesip/dependencias_simplesip.txt b/debian/tools_simplesip/dependencias_simplesip.txt index 09ed226be..ed7a8b31a 100644 --- a/debian/tools_simplesip/dependencias_simplesip.txt +++ b/debian/tools_simplesip/dependencias_simplesip.txt @@ -50,7 +50,6 @@ kmod dialog openssh-server git -supervisor gpg curl gnupg2 @@ -76,4 +75,5 @@ php8.2-zip php8.2-mbstring php8.2-gd php8.2-curl -vim \ No newline at end of file +vim +daemon \ No newline at end of file diff --git a/debian/tools_simplesip/install.sh b/debian/tools_simplesip/install.sh index 6e70b96a7..039e39c02 100644 --- a/debian/tools_simplesip/install.sh +++ b/debian/tools_simplesip/install.sh @@ -21,6 +21,7 @@ function add_sbin_path(){ function exit_installation(){ /bin/rm -rf /tmp/install_simplesip.pid 2>&1 > /dev/null + /bin/rm -rf /usr/src/tools_simplesip exit $1 } @@ -155,6 +156,8 @@ apt-get upgrade -y apt-get install -y aptitude aptitude-common libboost-iostreams1.74.0 libcwidget4 libdpkg-perl libfile-fcntllock-perl \ libsigc++-2.0-0v5 libxapian30 lsb-release apt-transport-https ca-certificates pkg-config 2>&1 > /dev/null +clear + apt-get install -y $(cat $path_arquivo/dependencias_simplesip.txt) linux-headers-$(uname -r) 2>&1 > /dev/null if [[ $? -ne 0 ]];then @@ -164,6 +167,7 @@ fi echo "Dependencias instalado ... " +clear #Realizando backup da pasta de gravacoes if [ -d /var/spool/asterisk/monitor ] ; then cd /var/spool/asterisk/monitor/ @@ -225,7 +229,7 @@ if [ 0 -ne $(find /usr/src -name "asterisk-*" -type d -print | wc -l) ] ; then fi [ -e /etc/init.d/dahdi ] && chkconfig --level 35 dahdi off && rm -rf /etc/init.d/dahdi -[ -e /etc/init.d/khomp-services ] && chkconfig --level 35 khomp-services off && rm -rf /etc/init.d/khomp-services +#[ -e /etc/init.d/khomp-services ] && chkconfig --level 35 khomp-services off && rm -rf /etc/init.d/khomp-services [ -L /usr/src/libpri ] && unlink /usr/src/libpri [ -L /usr/src/asterisk ] && unlink /usr/src/asterisk /bin/rm -rf /usr/src/instaladores @@ -351,7 +355,6 @@ if [ -f "$asterisk" ] ; then cd $path_arquivo/ [ -d codec ] && /bin/cp -Rapf codec/$arquitetura/codec*.so /usr/lib$(getconf LONG_BIT | grep "64")/asterisk/modules/ - fi khomp=$(ls -1 /usr/src/instaladores/channel_*.gz 2> /dev/null)