From 20f8b47e6c439e6558f29685404cc15a80e2df5e Mon Sep 17 00:00:00 2001 From: rodgger Date: Fri, 22 Mar 2024 14:19:55 -0400 Subject: [PATCH] Docker para rodar o 0.1 do monitor --- version_0.1-monitor/README.md | 89 +++ version_0.1-monitor/docker-compose.yml | 62 ++ version_0.1-monitor/env_example | 22 + version_0.1-monitor/pabx/Dockerfile | 64 ++ .../pabx/build-asterisk_php.sh | 148 +++++ version_0.1-monitor/pabx/crontab.sh | 20 + version_0.1-monitor/pabx/docker-entrypoint.sh | 31 + .../apache2/sites-available/pabx_simples.conf | 78 +++ version_0.1-monitor/pabx/etc/init.d/cnvrtd | 88 +++ version_0.1-monitor/pabx/etc/init.d/functions | 593 ++++++++++++++++++ version_0.1-monitor/pabx/supervisord.conf | 25 + version_0.1-monitor/postgres-13/Dockerfile | 32 + version_0.1-monitor/postgres-13/README.md | 12 + version_0.1-monitor/postgres-13/base.sh | 22 + .../postgres-13/permission_pg_hba.sh | 5 + 15 files changed, 1291 insertions(+) create mode 100644 version_0.1-monitor/README.md create mode 100644 version_0.1-monitor/docker-compose.yml create mode 100644 version_0.1-monitor/env_example create mode 100755 version_0.1-monitor/pabx/Dockerfile create mode 100644 version_0.1-monitor/pabx/build-asterisk_php.sh create mode 100644 version_0.1-monitor/pabx/crontab.sh create mode 100755 version_0.1-monitor/pabx/docker-entrypoint.sh create mode 100644 version_0.1-monitor/pabx/etc/apache2/sites-available/pabx_simples.conf create mode 100755 version_0.1-monitor/pabx/etc/init.d/cnvrtd create mode 100755 version_0.1-monitor/pabx/etc/init.d/functions create mode 100755 version_0.1-monitor/pabx/supervisord.conf create mode 100644 version_0.1-monitor/postgres-13/Dockerfile create mode 100644 version_0.1-monitor/postgres-13/README.md create mode 100644 version_0.1-monitor/postgres-13/base.sh create mode 100644 version_0.1-monitor/postgres-13/permission_pg_hba.sh diff --git a/version_0.1-monitor/README.md b/version_0.1-monitor/README.md new file mode 100644 index 0000000..bd8782b --- /dev/null +++ b/version_0.1-monitor/README.md @@ -0,0 +1,89 @@ + + +# Configuração do PABX versão 1.8 no docker + +Inicie a aplicação PABX de maneira fácil e sincronizada. + +## Preparando o ambiente no Windows + +### Configurando o WSL + +- Certifique-se de que o WSL2 está instalado no Windows. Caso não esteja, siga a documentação para realizar a instalação: [Instalação do WSL2](https://learn.microsoft.com/pt-br/windows/wsl/install). + +Após a instalação do WSL2, instale uma distribuição Linux. + +* Recomendamos a utilização do Debian. Para isso, execute o seguinte comando no PowerShell: +```bash +wsl --install -d Debian +``` + +* Em seguida, digite o seguinte comando no PowerShell para entrar em uma instância do Debian: +```bash +wsl -d Debian +``` +### Desabilite o Firewall e o Defender do Windows +Para conseguir realizar o download de alguns repositórios. + + + +## Clonando o repositório + +* Clone o projeto: docker-pabx-app. +```bash +git clone http://192.168.115.233:3000/SimplesIP/docker-pabx-app.git +``` + +## Deploy + +* Entre no diretório que contém os arquivos de inicialização do container. +```bash +cd docker-pabx-app/debian +``` + +Crie uma cópia do arquivo 'env-example' com o nome de '.env'. +```bash +cp env-example .env +``` + +Defina as variáveis dentro do arquivo .env: +- pasta_do_projeto - a pasta onde se encontra o projeto PABX. +- pasta_do_postgresql11 - onde deverá sincronizar o banco de dados. +- postgresql_version - por agora, não deve mudar o valor. + +### Execute o container com o docker-compose: +```bash +sudo docker-compose up -d +``` +Esse comando tentará compilar e levantar container. + +## FAQ + + +* ### Para que serve o arquivo `.env` ? + +Serve para definir variáveis a serem usadas no compose. Leia o arquivo '.env-example' para mais informações. + +* ### Quais arquivos estão sicronizados ? + + Grande parte dos arquivos do projeto estão sincronizados, porém existe os arquivos que não estão sincronizados. Os arquivos não sincronizados serão apagados quando seu container for encerrado e reescritos pelos arquivos da imagem quando o container for iniciado. + + Não sincronizados: + - `/etc/init.d/cnvrtd` - sem sincronização no arquivo + + Sincronizados: + - `/var/lib/postgresql/data` - Sincronizado os arquivo do banco de dados + - `/var/www/html/aplicativo` - Sincronizado + - `/var/www/html/include` - sincronizado + - `/hdaux/utilitarios/scripts` - sincronizado + + Obs: + - `/projeto/base` será replicado no container postgres `/base` para poder puxar o banco de dados. + + +* ### Qual as portas ? + + - `8080` - apache (web) + - `5432` - postgresql + +* ### Se o pabx criar arquivos que não estão no projeto gitea? + Coloque em `.gitignore` e mande a correção. \ No newline at end of file diff --git a/version_0.1-monitor/docker-compose.yml b/version_0.1-monitor/docker-compose.yml new file mode 100644 index 0000000..793dc03 --- /dev/null +++ b/version_0.1-monitor/docker-compose.yml @@ -0,0 +1,62 @@ +version: '3.7' +networks: + working: + driver: bridge +services: + postgres: + build: + context: postgres-13 + args: + # definir o id do usuário para ter acesso ao volume + - ID_USER_VOLUME=${id_user} + container_name: v0.1-monitor-postgres13 + restart: always + environment: + # Obter as informacoes que o docker criara por default + - POSTGRES_USER=contacte + - POSTGRES_PASSWORD=ctepgSQL + - POSTGRES_DB=pbx + # Variavel de ambiente do container para manter setado usuario, banco de dados e senha + # Isso nao sera necessario definir em psql + - PGUSER=contacte + - PGPASSWORD=ctepgSQL + - PGDATABASE=pbx + ports: + - 5432:5432 + networks: + - working + volumes: + # copiar a pasta /projeto/base do pabx + - ${pasta_do_projeto}/projeto/base:/base + # copiar a pasta /var/lib/pgsql/data + - ${pasta_do_postgresql}:/var/lib/postgresql/data + aplicativo: + build: + context: pabx + args: + # usar para compilar dockerfile + # DB_HOST DB_PORT DB_BASE - necessário para colocar no crontab + # environment compose é para depois do dockerfile + - DB_HOST=postgres + - DB_PORT=5432 + - DB_BASE=pbx + - ID_USER_VOLUME=${id_user} + restart: always + container_name: v0.1-monitor + working_dir: /var/www/html/ + ports: + - 8080:80 + privileged: true + depends_on: + - postgres + networks: + - working + links: + - postgres + volumes: + - ${pasta_do_projeto}:/var/www/html/aplicativo + - ${pasta_do_projeto}/include:/var/www/html/include + - ${pasta_do_projeto}/asterisk/hdaux_utilitarios_scripts/:/hdaux/utilitarios/scripts +volumes: + storage: + db: diff --git a/version_0.1-monitor/env_example b/version_0.1-monitor/env_example new file mode 100644 index 0000000..57adad7 --- /dev/null +++ b/version_0.1-monitor/env_example @@ -0,0 +1,22 @@ + + +# Pasta aonde está o projeto pabx para ser sincronizado no container +# +# Exemplo: +#pasta_do_projeto=/home/user/source_pabx +#pasta_do_projeto=c://Usuario/User/source_pabx +pasta_do_projeto="" + + +# Pasta do host para sincronizar a pasta /var/lib/pgsql/data (versão 13) +# Isso será usada para manter o banco de dados caso queira levantar +# outra instância. +# +# Essa pasta pode ser enviado ao repositório caso queira compartilhar +# o banco +pasta_do_postgresql="" + + + + + diff --git a/version_0.1-monitor/pabx/Dockerfile b/version_0.1-monitor/pabx/Dockerfile new file mode 100755 index 0000000..83bd454 --- /dev/null +++ b/version_0.1-monitor/pabx/Dockerfile @@ -0,0 +1,64 @@ +FROM debian@sha256:7c207de2b70f674653a9195b171da17910c642c7ca8ebc40d94fc56906381d80 + +# Compose manda os valores para conectar ao banco de dados +# Esses valores são usado para crontab +# crontab não limpa variáveis de ambiente para chamar script +# Logo printenv | sed 's/^\(.*\)$/export \1/g' > /env_to_crontab.sh +# defini as variáveis que vão ser chamado em cada script crontab +ARG DB_HOST +ARG DB_PORT +ARG DB_BASE +ARG ID_USER_VOLUME + +ENV VERSION_SIMPLESIP v1.8 +ENV APACHE_RUN_USER pbx +ENV APACHE_RUN_GROUP pbx +ENV DB_HOST $DB_HOST +ENV DB_PORT $DB_PORT +ENV DB_BASE $DB_BASE + +RUN mkdir -p /var/lock/subsys/ + +# Instalação do asterisk e do PHP 8.2 e asterisk 13.38 +COPY build-asterisk_php.sh / +RUN chmod 755 /build-asterisk_php.sh +RUN /build-asterisk_php.sh $ID_USER_VOLUME + + +# definir as variáveis de ambiente para o cron +RUN printenv | sed 's/^\(.*\)$/\1/g' > /etc/environment +COPY crontab.sh / +RUN bash /crontab.sh +RUN crontab /etc/crontab + +# apache +COPY etc/apache2/sites-available/pabx_simples.conf /etc/apache2/sites-available/pabx_simples.conf +RUN rm -rf /etc/apache2/sites-enabled/* +RUN ln -s /etc/apache2/sites-available/pabx_simples.conf /etc/apache2/sites-enabled/pabx_simples.conf + + +# colocar os arquivos include_pat do php +RUN sed -i '745 s/^[;]\? *include_path = .*/include_path = \".:\/var\/www\/html\/include\"/g' /etc/php/8.2/cli/php.ini +RUN sed -i '745 s/^[;]\? *include_path = .*/include_path = \".:\/var\/www\/html\/include\"/g' /etc/php/8.2/apache2/php.ini + +# Executar o apache no usuário pbx +RUN sed -i 's/APACHE_RUN_USER=.*/APACHE_RUN_USER=pbx/g' /etc/apache2/envvars +RUN sed -i 's/APACHE_RUN_GROUP=.*/APACHE_RUN_GROUP=pbx/g' /etc/apache2/envvars + +# cnvrtd � usado para executar fun��es como root +COPY etc/init.d/cnvrtd /etc/init.d/ +COPY etc/init.d/functions /etc/init.d/ + +EXPOSE 80/tcp + +COPY docker-entrypoint.sh / +COPY supervisord.conf /etc/supervisor/supervisord.conf + + +ENTRYPOINT ["/docker-entrypoint.sh"] + + +CMD ["supervisord","-n","-c","/etc/supervisor/supervisord.conf"] + +#docker run -it -d --name v1712 -p 8080:80/tcp + diff --git a/version_0.1-monitor/pabx/build-asterisk_php.sh b/version_0.1-monitor/pabx/build-asterisk_php.sh new file mode 100644 index 0000000..b2f8395 --- /dev/null +++ b/version_0.1-monitor/pabx/build-asterisk_php.sh @@ -0,0 +1,148 @@ +#!/bin/bash + +set -ex + +/usr/sbin/groupadd "pbx" +# Este é o id do usuário para fora do container ter acesso +/usr/sbin/useradd -u $1 -s "/usr/bin/bash" -d '/var/lib/asterisk/' 'pbx' -g 'pbx' + +/usr/sbin/groupadd "simples" +/usr/sbin/useradd -s "/usr/bin/bash" -m 'simples' -g 'simples' + + + +apt-get -y update + +apt-get install lsb-release apt-transport-https ca-certificates software-properties-common -y +apt-get install wget + +wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg +sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' + +apt-get -y update + + +apt-get install -y \ + supervisor \ + cron \ + curl \ + daemon \ + libcurl4-openssl-dev \ + libncurses-dev \ + libssl-dev \ + tar \ + curl \ + bison \ + git \ + vim \ + apache2 \ + libjansson-dev \ + ffmpeg \ + build-essential \ + libedit-dev \ + libsqlite3-dev \ + uuid-dev \ + libxml2-dev \ + libspeex-dev \ + libspeexdsp-dev \ + libogg-dev \ + libvorbis-dev \ + libasound2-dev \ + libcurl4-openssl-dev \ + xmlstarlet \ + flex \ + libpq-dev \ + unixodbc-dev \ + libneon27-dev \ + libgmime-3.0-dev \ + liblua5.2-dev \ + liburiparser-dev \ + libxslt1-dev \ + libssl-dev \ + libmariadb-dev-compat \ + libmariadb-dev \ + libbluetooth-dev \ + libradcli-dev \ + freetds-dev \ + libosptk-dev \ + libjack-jackd2-dev \ + libcap-dev \ + libsnmp-dev \ + libiksemel-dev \ + libcorosync-common-dev \ + libcpg-dev \ + libcfg-dev \ + libnewt-dev \ + libpopt-dev \ + libical-dev \ + libspandsp-dev \ + libresample1-dev \ + libc-client2007e-dev \ + binutils-dev \ + libsrtp2-dev \ + libgsm1-dev \ + graphviz \ + sudo \ + zlib1g-dev \ + libldap2-dev \ + bzip2 \ + patch \ + php8.2 \ + php8.2-cli \ + php8.2-common \ + php8.2-dev \ + php8.2-gd \ + php8.2-mbstring \ + php8.2-mysql \ + php8.2-common \ + php8.2-snmp \ + php8.2-soap \ + php8.2-xml \ + php8.2-xmlrpc \ + php8.2-pgsql \ + php8.2-curl + +apt-get clean +apt-get autoremove -y + +mkdir /var/log/asterisk/ +chown -R pbx:pbx /var/log/asterisk/ + + + +### CONFIGURANDO O PHP ### +sed -i 's/^error_reporting = .*/error_reporting = E_ALL | E_STRICT/g' /etc/php/8.2/cli/php.ini +sed -i 's/^error_reporting = .*/error_reporting = E_ALL | E_STRICT/g' /etc/php/8.2/apache2/php.ini + +sed -i 's/display_errors = .*/display_errors = Off/g' /etc/php/8.2/cli/php.ini +sed -i 's/display_errors = .*/display_errors = Off/g' /etc/php/8.2/apache2/php.ini + +sed -i 's/^display_startup_errors = .*/display_startup_errors = Off/g' /etc/php/8.2/cli/php.ini +sed -i 's/^display_startup_errors = .*/display_startup_errors = Off/g' /etc/php/8.2/apache2/php.ini + +sed -i 's/^upload_max_filesize = .*/upload_max_filesize = 100M/g' /etc/php/8.2/cli/php.ini +sed -i 's/^upload_max_filesize = .*/upload_max_filesize = 100M/g' /etc/php/8.2/apache2/php.ini + +sed -i 's/memory_limit = .*/memory_limit = -1/g' /etc/php/8.2/cli/php.ini +sed -i 's/memory_limit = .*/memory_limit = 256M/g' /etc/php/8.2/apache2/php.ini + +sed -i 's/;error_log = php_errors.*/error_log = \/var\/log\/aplsimples.log/g' /etc/php/8.2/cli/php.ini +sed -i 's/;error_log = php_errors.*/error_log = \/var\/log\/aplsimples.log/g' /etc/php/8.2/apache2/php.ini + +sed -i 's/^default_charset = .*/default_charset = "iso-8859-1"/g' /etc/php/8.2/cli/php.ini +sed -i 's/^default_charset = .*/default_charset = "iso-8859-1"/g' /etc/php/8.2/apache2/php.ini + +sed -i '745s/^;include_path = .*/include_path = \".:\/var\/www\/html\/include:\/var\/www\/html\/include\/core\"/g' /etc/php/8.2/cli/php.ini +sed -i '745 s/^;include_path = .*/include_path = \".:\/var\/www\/html\/include:\/var\/www\/html\/include\/core\"/g' /etc/php/8.2/apache2/php.ini + +sed -i 's/^;date.timezone =.*/date.timezone = "America\/Cuiaba"/g' /etc/php/8.2/cli/php.ini +sed -i 's/^;date.timezone =.*/date.timezone = "America\/Cuiaba"/g' /etc/php/8.2/apache2/php.ini + +sed -i 's/^export APACHE_RUN_USER=.*/export APACHE_RUN_USER=pbx/g' /etc/apache2/envvars +sed -i 's/^export APACHE_RUN_GROUP=.*/export APACHE_RUN_GROUP=pbx/g' /etc/apache2/envvars + +echo "export DB_HOST=${DB_HOST}" >> /etc/apache2/envvars + +cd /var/www/html/ + +exec rm -f /build-asterisk.sh diff --git a/version_0.1-monitor/pabx/crontab.sh b/version_0.1-monitor/pabx/crontab.sh new file mode 100644 index 0000000..3e7021e --- /dev/null +++ b/version_0.1-monitor/pabx/crontab.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +echo "#Servicos Auxiliares" >> /etc/crontab +echo "0 1 * * * root /hdaux/utilitarios/scripts/hd.sh " >> /etc/crontab +echo "*/1 * * * * root /var/lib/asterisk/scripts/callcenter/queue_log.php" >> /etc/crontab +echo "*/1 * * * * root /var/lib/asterisk/scripts/callcenter/monitora_agentes.php" >> /etc/crontab +echo "*/1 * * * * root /var/lib/asterisk/scripts/manutencaoDB/importaBilhetes.php" >> /etc/crontab +echo "*/1 * * * * root /var/lib/asterisk/scripts/workflow/workflowSender.php" >> /etc/crontab +echo "0 2 * * * root /var/lib/asterisk/scripts/manutencaoDB/manutencaodb.php" >> /etc/crontab +echo "#Backup" >> /etc/crontab +echo "*/10 * * * * root /var/lib/asterisk/scripts/backup/backup.php" >> /etc/crontab +echo "#Backup - Shell" >> /etc/crontab +echo "0 1 * * * root /hdaux/utilitarios/scripts/backup.sh config,bd" >> /etc/crontab +echo "#VPN" >> /etc/crontab +echo "*/1 * * * * root /bin/sip_teste_vpn.sh" >> /etc/crontab +echo "#NTP" >> /etc/crontab +echo "*/15 * * * * root /hdaux/utilitarios/scripts/ntp.sh" >> /etc/crontab +echo "#Logrotate" >> /etc/crontab +echo "59 23 * * * root /hdaux/utilitarios/scripts/logrotate.sh --force" >> /etc/crontab +echo "57 23 * * * root /hdaux/utilitarios/scripts/temporizador_de_dados.sh" >> /etc/crontab \ No newline at end of file diff --git a/version_0.1-monitor/pabx/docker-entrypoint.sh b/version_0.1-monitor/pabx/docker-entrypoint.sh new file mode 100755 index 0000000..06d500c --- /dev/null +++ b/version_0.1-monitor/pabx/docker-entrypoint.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +# run as user asterisk by default +ASTERISK_USER=${ASTERISK_USER:-asterisk} + +if [ "$1" = "" ]; then + COMMAND="/usr/sbin/asterisk -T -W -U ${ASTERISK_USER} -p -vvvdddf" +else + COMMAND="$@" +fi + +if [ "${ASTERISK_UID}" != "" ] && [ "${ASTERISK_GID}" != "" ]; then + # recreate user and group for asterisk + # if they've sent as env variables (i.e. to macth with host user to fix permissions for mounted folders + + deluser asterisk && \ + adduser --gecos "" --no-create-home --uid ${ASTERISK_UID} --disabled-password ${ASTERISK_USER} \ + || exit +fi + +mkdir -p /var/run/asterisk + +chown -R ${ASTERISK_USER}: /var/log/asterisk \ + /var/lib/asterisk \ + /var/run/asterisk \ + /var/spool/asterisk; \ + +cp /var/www/html/config-docker.php /var/www/html/aplicativo/ +/hdaux/utilitarios/scripts/permissoes_atualizacao.sh + +exec ${COMMAND} \ No newline at end of file diff --git a/version_0.1-monitor/pabx/etc/apache2/sites-available/pabx_simples.conf b/version_0.1-monitor/pabx/etc/apache2/sites-available/pabx_simples.conf new file mode 100644 index 0000000..a25a115 --- /dev/null +++ b/version_0.1-monitor/pabx/etc/apache2/sites-available/pabx_simples.conf @@ -0,0 +1,78 @@ + + # The ServerName directive sets the request scheme, hostname and port that + # the server uses to identify itself. This is used when creating + # redirection URLs. In the context of virtual hosts, the ServerName + # specifies what hostname must appear in the request's Host: header to + # match this virtual host. For the default virtual host (this file) this + # value is not decisive as it is used as a last resort host regardless. + # However, you must set it for any further virtual host explicitly. + #ServerName www.example.com + + ServerAdmin webmaster@localhost + DocumentRoot /var/www/html/aplicativo + + Alias /gravacoes "/var/spool/asterisk/monitor" + + Options Indexes MultiViews + AllowOverride None + Order allow,deny + Require all granted + Allow from 127.0.0.1 + + + Alias /agenda "/var/www/html/agenda" + + Options Indexes MultiViews + AllowOverride None + Order allow,deny + Require all granted + Allow from all + + + Alias /downloads "/hdaux/downloads" + + Options Indexes MultiViews + AllowOverride None + Order allow,deny + Require all granted + Allow from all + + + Alias /ferramentas "/hdaux/utilitarios/ferramentas" + + Options Indexes MultiViews + AllowOverride None + Order allow,deny + Require all granted + Allow from all + + + Alias /manuais "/hdaux/utilitarios/manuais" + + Options Indexes MultiViews + AllowOverride None + Order allow,deny + Require all granted + Allow from all + + + + + # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, + # error, crit, alert, emerg. + # It is also possible to configure the loglevel for particular + # modules, e.g. + #LogLevel info ssl:warn + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + # For most configuration files from conf-available/, which are + # enabled or disabled at a global level, it is possible to + # include a line for only one particular virtual host. For example the + # following line enables the CGI configuration for this host only + # after it has been globally disabled with "a2disconf". + #Include conf-available/serve-cgi-bin.conf + + +# vim: syntax=apache ts=4 sw=4 sts=4 sr noet diff --git a/version_0.1-monitor/pabx/etc/init.d/cnvrtd b/version_0.1-monitor/pabx/etc/init.d/cnvrtd new file mode 100755 index 0000000..c598ae0 --- /dev/null +++ b/version_0.1-monitor/pabx/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/www/html/aplicativo/cnvrtd/cnvrtd.php || exit 0 + +# +# Set prog, proc and bin variables. +# +prog="cnvrtd" +proc=/var/lock/subsys/cnvrtd +bin=/var/www/html/aplicativo/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/version_0.1-monitor/pabx/etc/init.d/functions b/version_0.1-monitor/pabx/etc/init.d/functions new file mode 100755 index 0000000..158307a --- /dev/null +++ b/version_0.1-monitor/pabx/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/version_0.1-monitor/pabx/supervisord.conf b/version_0.1-monitor/pabx/supervisord.conf new file mode 100755 index 0000000..9450fcc --- /dev/null +++ b/version_0.1-monitor/pabx/supervisord.conf @@ -0,0 +1,25 @@ +[supervisord] +logfile=/var/log/supervisor/supervisord.log ; localização do arquivo de log do Supervisor +pidfile=/var/run/supervisord.pid ; localização do arquivo PID do Supervisor +user=root + +[program:apache2] +priority=100 +notdaemon=false +command=/usr/sbin/apachectl -D BACKGROUND +startsecs=0 +startretries=0 + +[program:cnvrtd] +priority=200 +notdaemon=false +command=/etc/init.d/cnvrtd start +startsecs=0 +startretries=0 + +[program:cron] +priority=150 +notdaemon=false +command=/usr/sbin/cron +startsecs=0 +startretries=0 diff --git a/version_0.1-monitor/postgres-13/Dockerfile b/version_0.1-monitor/postgres-13/Dockerfile new file mode 100644 index 0000000..dc4625c --- /dev/null +++ b/version_0.1-monitor/postgres-13/Dockerfile @@ -0,0 +1,32 @@ +# postgres:13.14 +FROM postgres@sha256:c1db66c55c1a4f6b3e51c81b60fca0e79d697141fbe085511c88bf12207c5a11 + +# id do usuário para definir o dono do arquivos do postgresql +ARG ID_USER_VOLUME + +# variaveis de ambiente ENV +ENV LC_ALL=en_US.ISO-8859-1 +ENV LC_MESSAGES=en_US.ISO-8859-1 +ENV LC_MONETARY=en_US.ISO-8859-1 +ENV LC_NUMERIC=en_US.ISO-8859-1 +ENV LC_TIME=en_US.ISO-8859-1 +# id do usuario postgres +ENV ID_USER_VOLUME=$ID_USER_VOLUME + +RUN echo "en_US ISO-8859-1" > /etc/locale.gen +RUN locale-gen "en_US ISO-8859-1" +RUN export LC_ALL="en_US ISO-8859-1" +RUN update-locale + +# Mudar o id do usuario postgres +RUN usermod -u $ID_USER_VOLUME postgres +RUN chown -R postgres:postgres /var/lib/postgresql/ + +# sh para restaurar o banco de dados +COPY base.sh /docker-entrypoint-initdb.d/ +RUN chmod 755 /docker-entrypoint-initdb.d/base.sh + +# permiss�o de acesso ao banco de dados +COPY permission_pg_hba.sh /docker-entrypoint-initdb.d/ +RUN chmod 755 /docker-entrypoint-initdb.d/permission_pg_hba.sh + diff --git a/version_0.1-monitor/postgres-13/README.md b/version_0.1-monitor/postgres-13/README.md new file mode 100644 index 0000000..a221e14 --- /dev/null +++ b/version_0.1-monitor/postgres-13/README.md @@ -0,0 +1,12 @@ +# Imagem postgres 13:14 para monitor Simples IP + +Container ISO-8859-1 + + +1. **base.sh** + - responsável por criar usuários + - Restaurar o banco da versão desejada + - Acrescentar as querys extras em /base/add_sql. São incluídos por ordens alfabéticas + +2. **permission_pg_hba.sh** + - Acrescenta permissões de acesso externo diff --git a/version_0.1-monitor/postgres-13/base.sh b/version_0.1-monitor/postgres-13/base.sh new file mode 100644 index 0000000..3e13dfa --- /dev/null +++ b/version_0.1-monitor/postgres-13/base.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Criar usuarios do banco de dados +# Usuario contacte é criado por default pelo container +psql -c "CREATE USER root WITH PASSWORD '\$imple\$ip' SUPERUSER CREATEDB CREATEROLE" +psql -c "CREATE USER simplesip WITH PASSWORD 'smplsIP' SUPERUSER CREATEDB CREATEROLE" +psql -c "CREATE USER postgres WITH PASSWORD 'SIP\$\$'" + +# excluir schema antes de restaurar o banco de dados +psql -d "pbx" -c "DROP SCHEMA public CASCADE;" + +# Restaurar o banco dedados do monitor +/usr/bin/pg_restore -v -Fc --jobs="5" -d pbx /base/base-monitor.sql + +# Adiciona query nacessarias depois que restaura o banco +# Incluida por ordem alfabetica no diretório /base/add_sql +# /base/add_sql -> espelho do projeto/base/add_sql +for file $(find /base/add_sql/ | sort) +do + psql -f "$file" +done + diff --git a/version_0.1-monitor/postgres-13/permission_pg_hba.sh b/version_0.1-monitor/postgres-13/permission_pg_hba.sh new file mode 100644 index 0000000..8c293cc --- /dev/null +++ b/version_0.1-monitor/postgres-13/permission_pg_hba.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +echo "host all all 192.168.115.0/24 md5" >> /var/lib/postgresql/data/pg_hba.conf +echo "host all all 10.252.252.0/24 md5" >> /var/lib/postgresql/data/pg_hba.conf +echo "host all all 177.67.197.146/32 md5" >> /var/lib/postgresql/data/pg_hba.conf