From 541c9ff1b42952b2271458b600125e8bda8e1592 Mon Sep 17 00:00:00 2001 From: Rafael Ameijeiras Date: Thu, 15 Oct 2020 18:48:29 +0200 Subject: [PATCH] Adding dockerfiles for pandora stack centos 8 and percona --- extras/docker/centos8/base/Dockerfile | 257 ++++++++++++++ extras/docker/centos8/build_image_el8.sh | 112 ++++++ extras/docker/centos8/docker-compose.yml | 43 +++ .../docker/centos8/pandora-stack/Dockerfile | 24 ++ .../centos8/pandora-stack/sources/.gitignore | 5 + .../pandora-stack/sources/init_pandora.sh | 336 ++++++++++++++++++ extras/docker/percona/Dockerfile | 31 ++ 7 files changed, 808 insertions(+) create mode 100644 extras/docker/centos8/base/Dockerfile create mode 100755 extras/docker/centos8/build_image_el8.sh create mode 100644 extras/docker/centos8/docker-compose.yml create mode 100644 extras/docker/centos8/pandora-stack/Dockerfile create mode 100644 extras/docker/centos8/pandora-stack/sources/.gitignore create mode 100755 extras/docker/centos8/pandora-stack/sources/init_pandora.sh create mode 100644 extras/docker/percona/Dockerfile diff --git a/extras/docker/centos8/base/Dockerfile b/extras/docker/centos8/base/Dockerfile new file mode 100644 index 0000000000..285f2f7ef8 --- /dev/null +++ b/extras/docker/centos8/base/Dockerfile @@ -0,0 +1,257 @@ +#docker build -t pandorafms/pandorafms-open-base-el8 -f $HOME/code/pandorafms/extras/docker/centos8/base/Dockerfile $HOME/code/pandorafms/extras/docker/centos8/base/ +#docker push pandorafms/pandorafms-open-base-el8 + +FROM centos:8 + +RUN dnf install -y --setopt=tsflags=nodocs \ + epel-release \ + dnf-utils \ + http://rpms.remirepo.net/enterprise/remi-release-8.rpm + +RUN dnf module reset -y php && dnf module install -y php:remi-7.3 +RUN dnf config-manager --set-enabled PowerTools + +# Install console +RUN dnf install -y --setopt=tsflags=nodocs \ + php \ + php-mcrypt \php-cli \ + php-gd \ + php-curl \ + php-session \ + php-mysqlnd \ + php-ldap \ + php-zip \ + php-zlib \ + php-fileinfo \ + php-gettext \ + php-snmp \ + php-mbstring \ + php-pecl-zip \ + php-xmlrpc \ + libxslt \ + wget \ + php-xml \ + httpd \ + mod_php \ + atk \ + avahi-libs \ + cairo \ + cups-libs \ + fribidi \ + gd \ + gdk-pixbuf2 \ + ghostscript \ + graphite2 \ + graphviz \ + gtk2 \ + harfbuzz \ + hicolor-icon-theme \ + hwdata \ + jasper-libs \ + lcms2 \ + libICE \ + libSM \ + libXaw \ + libXcomposite \ + libXcursor \ + libXdamage \ + libXext \ + libXfixes \ + libXft \ + libXi \ + libXinerama \ + libXmu \ + libXrandr \ + libXrender \ + libXt \ + libXxf86vm \ + libcroco \ + libdrm \ + libfontenc \ + libglvnd \ + libglvnd-egl \ + libglvnd-glx \ + libpciaccess \ + librsvg2 \ + libthai \ + libtool-ltdl \ + libwayland-client \ + libwayland-server \ + libxshmfence \ + mesa-libEGL \ + mesa-libGL \ + mesa-libgbm \ + mesa-libglapi \ + pango \ + pixman \ + nfdump \ + xorg-x11-fonts-75dpi \ + xorg-x11-fonts-misc \ + poppler-data \ + php-yaml; yum clean all + +RUN mkdir -p /run/php-fpm/ ; chown -R root:apache /run/php-fpm/ +# not installed perl-Net-Telnet gtk-update-icon-cach ghostscript-fonts + +# Install server + +RUN dnf install -y --setopt=tsflags=nodocs \ + GeoIP \ + GeoIP-GeoLite-data \ + dwz \ + efi-srpm-macros \ + ghc-srpm-macros \ + go-srpm-macros \ + ocaml-srpm-macros \ + openblas-srpm-macros \ + perl \ + perl-Algorithm-Diff \ + perl-Archive-Tar \ + perl-Archive-Zip \ + perl-Attribute-Handlers \ + perl-B-Debug \ + perl-CPAN \ + perl-CPAN-Meta \ + perl-CPAN-Meta-Requirements \ + perl-CPAN-Meta-YAML \ + perl-Compress-Bzip2 \ + perl-Config-Perl-V \ + perl-DBD-MySQL \ + perl-DBI \ + perl-DB_File \ + perl-Data-Dump \ + perl-Data-OptList \ + perl-Data-Section \ + perl-Devel-PPPort \ + perl-Devel-Peek \ + perl-Devel-SelfStubber \ + perl-Devel-Size \ + perl-Digest-HMAC \ + perl-Digest-SHA \ + perl-Encode-Locale \ + perl-Encode-devel \ + perl-Env \ + perl-ExtUtils-CBuilder \ + perl-ExtUtils-Command \ + perl-ExtUtils-Embed \ + perl-ExtUtils-Install \ + perl-ExtUtils-MM-Utils \ + perl-ExtUtils-MakeMaker \ + perl-ExtUtils-Manifest \ + perl-ExtUtils-Miniperl \ + perl-ExtUtils-ParseXS \ + perl-File-Fetch \ + perl-File-HomeDir \ + perl-File-Listing \ + perl-File-Which \ + perl-Filter \ + perl-Filter-Simple \ + perl-Geo-IP \ + perl-HTML-Parser \ + perl-HTML-Tagset \ + perl-HTML-Tree \ + perl-HTTP-Cookies \ + perl-HTTP-Date \ + perl-HTTP-Message \ + perl-HTTP-Negotiate \ + perl-IO-HTML \ + perl-IO-Socket-INET6 \ + perl-IO-Zlib \ + perl-IO-stringy \ + perl-IPC-Cmd \ + perl-IPC-SysV \ + perl-IPC-System-Simple \ + perl-JSON \ + perl-JSON-PP \ + perl-LWP-MediaTypes \ + perl-Locale-Codes \ + perl-Locale-Maketext \ + perl-Locale-Maketext-Simple \ + perl-MRO-Compat \ + perl-Math-BigInt \ + perl-Math-BigInt-FastCalc \ + perl-Math-BigRat \ + perl-Memoize \ + perl-Module-Build \ + perl-Module-CoreList \ + perl-Module-CoreList-tools \ + perl-Module-Load \ + perl-Module-Load-Conditional \ + perl-Module-Loaded \ + perl-Module-Metadata \ + perl-NTLM \ + perl-Net-HTTP \ + perl-Net-Ping \ + perl-NetAddr-IP \ + perl-Package-Generator \ + perl-Params-Check \ + perl-Params-Util \ + perl-Perl-OSType \ + perl-PerlIO-via-QuotedPrint \ + perl-Pod-Checker \ + perl-Pod-Html \ + perl-Pod-Parser \ + perl-SelfLoader \ + perl-Socket6 \ + perl-Software-License \ + perl-Sub-Exporter \ + perl-Sub-Install \ + perl-Sys-Syslog \ + perl-Test \ + perl-Test-Harness \ + perl-Test-Simple \ + perl-Text-Balanced \ + perl-Text-Diff \ + perl-Text-Glob \ + perl-Text-Template \ + perl-Thread-Queue \ + perl-Time-Piece \ + perl-TimeDate \ + perl-Try-Tiny \ + perl-Unicode-Collate \ + perl-WWW-RobotRules \ + perl-XML-NamespaceSupport \ + perl-XML-Parser \ + perl-XML-SAX \ + perl-XML-SAX-Base \ + perl-XML-Simple \ + perl-XML-Twig \ + perl-autodie \ + perl-bignum \ + perl-devel \ + perl-encoding \ + perl-experimental \ + perl-inc-latest \ + perl-libnetcfg \ + perl-libwww-perl \ + perl-local-lib \ + perl-open \ + perl-perlfaq \ + perl-srpm-macros \ + perl-utils \ + perl-version \ + python-srpm-macros \ + python3-pyparsing \ + python3-rpm-macros \ + qt5-srpm-macros \ + redhat-rpm-config \ + rust-srpm-macros \ + systemtap-sdt-devel \ + perl-TermReadKey \ + perl \ + perl-DBD-MySQL \ + perl-DBI \ + initscripts \ + net-tools \ + nmap-ncat \ + nmap \ + net-snmp-utils \ + sudo \ + http://firefly.artica.es/centos8/perl-Net-Telnet-3.04-1.el8.noarch.rpm \ + http://www6.atomicorp.com/channels/atomic/centos/7/x86_64/RPMS/wmi-1.3.14-4.el7.art.x86_64.rpm + + +RUN dnf install -y supervisor crontabs mysql http://firefly.artica.es/centos8/phantomjs-2.1.1-1.el7.x86_64.rpm --setopt=tsflags=nodocs + + +EXPOSE 80 443 41121 162/udp diff --git a/extras/docker/centos8/build_image_el8.sh b/extras/docker/centos8/build_image_el8.sh new file mode 100755 index 0000000000..00c50f6ff2 --- /dev/null +++ b/extras/docker/centos8/build_image_el8.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +VERSION=$1 +ENT="$HOME/code/pandora_enterprise" +OPEN="$HOME/code/pandorafms" +OS="Centos" +ARCH="x86_64" +EL="el7" +EXT="demo" +TARGET_URL="http://atlantis.artica.es" +DOCKER_PATH="$OPEN/extras/docker/centos8/" +OSTACK_IMAGE="pandorafms/pandorafms-open-stack-el8" +OBASE_IMAGE="pandorafms/pandorafms-open-base-el8" +PERCONA_IMAGE="pandorafms/pandorafms-percona-base" + + +function help { + echo "To excute the builder you must declare 4 parameters: the version image, upload (push) tokens, build base (rebuild centos base image), build percona (rebuild percona base image)" + echo "" + echo "$0 [ ] [] []" + echo "Ex creates a local image from 749 packages : $0 749 0 1 1" +} + +if [ "$1" == "" ] || [ "$1" == "-h" ] ; then + help + exit +fi + +if [ "$2" == "1" ]; then + UPDATE="1" +fi + +if [ "$3" == "1" ]; then + BASEBUILD="1" +fi + +if [ "$4" == "1" ]; then + DBBUILD="1" +fi + +#Defining packages urls + +oconsoleurl=$TARGET_URL/Releases/7.0NG.$VERSION/$OS/noarch/pandorafms_console-7.0NG.$VERSION.noarch.rpm +oserverurl=$TARGET_URL/Releases/7.0NG.$VERSION/$OS/noarch/pandorafms_server-7.0NG.$VERSION.noarch.rpm +url=$(curl -I -s $TARGET_URL/Releases/7.0NG.$VERSION/ 2> /dev/null | grep "200 OK" | wc -l) + +# log in into docker acount to acces private repo. + +# docker login -u $DOCKERUSER -p$DOCKERPASS + +Check athlantis is reachable +if [ "$url" -lt 1 ] ; then + echo "$url Athlantis unreachable ..." + exit +fi + +echo "Start" +# Removing old packages +cd $DOCKER_PATH/pandora-stack/sources +rm -rf ./pandorafms_* + +# Downloading new packages +wget $oconsoleurl +wget $oserverurl + +if [ "$BASEBUILD" == 1 ] ; then + # Open Base image + echo "building Base el8 image" + cd $DOCKER_PATH/base + docker build -t $OBASE_IMAGE:$VERSION -f $DOCKER_PATH/base/Dockerfile $DOCKER_PATH/base + echo "Taging Open stack el8 latest image before upload" + docker tag $OBASE_IMAGE:$VERSION $OBASE_IMAGE:latest + echo -e ">>>> \n" +fi + +if [ "$DBBUILD" == 1 ] ; then + # Percona image + echo "building Percona image" + cd $OPEN/extras/docker/percona + docker build -t $PERCONA_IMAGE:latest -f $OPEN/extras/docker/percona/Dockerfile $OPEN/extras/docker/percona + echo -e ">>>> \n" +fi + +#Open Stack image +echo "building Open el8 image" +cd $DOCKER_PATH/pandora-stack +docker build -t $OSTACK_IMAGE:$VERSION -f $DOCKER_PATH/pandora-stack/Dockerfile $DOCKER_PATH/pandora-stack +echo "Taging Open base latest image before upload" +docker tag $OSTACK_IMAGE:$VERSION $OSTACK_IMAGE:latest +echo -e ">>>> \n" + +# Upload images + +if [ "$UPDATE" == 1 ] ; then + if [ "$BASEBUILD" == 1 ] ; then + #Open base Images + echo "Uploading Open $OBASE_IMAGE:$VERSION . . ." + docker push $OBASE_IMAGE:$VERSION + docker push $OBASE_IMAGE:latest + fi + + if [ "$DBBUILD" == 1 ] ; then + #Open base Images + echo "Uploading percona $PERCONA_IMAGE:latest . . ." + docker push $PERCONA_IMAGE:latest + fi + + #Open Stack Images + echo "Uploading Open $OSTACK_IMAGE:$VERSION . . ." + docker push $OSTACK_IMAGE:$VERSION + docker push $OSTACK_IMAGE:latest +fi diff --git a/extras/docker/centos8/docker-compose.yml b/extras/docker/centos8/docker-compose.yml new file mode 100644 index 0000000000..f33b6fe9ed --- /dev/null +++ b/extras/docker/centos8/docker-compose.yml @@ -0,0 +1,43 @@ +# Use root/example as user/password credentials +# este compose incluye la base de datos en otro docker y levanta aplicacion y DB juntos +version: '3.1' + +services: + + db: + image: pandorafms/pandorafms-percona-base + restart: always + #command: ["mysqld", "--innodb-buffer-pool-size=900M"] + environment: + MYSQL_ROOT_PASSWORD: pandora + MYSQL_DATABASE: pandora + MYSQL_USER: pandora + MYSQL_PASSWORD: pandora + networks: + - pandora + + pandora: + image: pandorafms/pandorafms-open-stack-el8:749 + restart: always + depends_on: + - db + environment: + MYSQL_ROOT_PASSWORD: pandora + DBHOST: db + DBNAME: pandora + DBUSER: pandora + DBPASS: pandora + DBPORT: 3306 + INSTANCE_NAME: pandora01 + PUBLICURL: "" + SLEEP: 5 + RETRIES: 10 + networks: + - pandora + ports: + - "8080:80" + - "41121:41121" + - "162:162/udp" + - "9995:9995/udp" +networks: + pandora: diff --git a/extras/docker/centos8/pandora-stack/Dockerfile b/extras/docker/centos8/pandora-stack/Dockerfile new file mode 100644 index 0000000000..59728b37d6 --- /dev/null +++ b/extras/docker/centos8/pandora-stack/Dockerfile @@ -0,0 +1,24 @@ +#docker build -t pandorafms/pandorafms-open-stack-el8:$VERSION -f $HOME/code/pandorafms/extras/docker/centos8/pandora-stack/Dockerfile $HOME/code/pandorafms/extras/docker/centos8/pandora-stack/ + +FROM pandorafms/pandorafms-open-base-el8 + +ENV DBNAME=pandora +ENV DBUSER=pandora +ENV DBPASS=pandora +ENV DBHOST=pandora +ENV DBPORT=3306 +ENV SLEEP=5 +ENV RETRIES=1 +ENV OPEN=1 + +ENV LC_ALL=C + +RUN rm -rf /etc/localtime ; ln -s /usr/share/zoneinfo/Europe/Madrid /etc/localtime + +COPY ./sources /opt/pandora +# Install the Pandora console +RUN dnf install -y /opt/pandora/pandorafms_console-*.rpm /opt/pandora/pandorafms_server-*.rpm ; yum clean all + +EXPOSE 80 443 41121 162/udp 9995/udp + +CMD sh /opt/pandora/init_pandora.sh diff --git a/extras/docker/centos8/pandora-stack/sources/.gitignore b/extras/docker/centos8/pandora-stack/sources/.gitignore new file mode 100644 index 0000000000..9e870cb2e3 --- /dev/null +++ b/extras/docker/centos8/pandora-stack/sources/.gitignore @@ -0,0 +1,5 @@ +# exclude packages +demos/ +*.tar* +*.rpm +phantomjs diff --git a/extras/docker/centos8/pandora-stack/sources/init_pandora.sh b/extras/docker/centos8/pandora-stack/sources/init_pandora.sh new file mode 100755 index 0000000000..56424e6cb9 --- /dev/null +++ b/extras/docker/centos8/pandora-stack/sources/init_pandora.sh @@ -0,0 +1,336 @@ +#!/bin/bash +# +# Prepares environment and launchs Pandora FMS +# +# Global vars +# +PANDORA_CONSOLE=/var/www/html/pandora_console +PANDORA_SERVER_CONF=/etc/pandora/pandora_server.conf +PANDORA_SERVER_BIN=/usr/bin/pandora_server +PANDORA_HA_BIN=/usr/bin/pandora_ha +PANDORA_TABLES_MIN=160 +# +# Check database +# +function db_check { + # Check DB + echo -n ">> Checking dbengine connection: " + + for i in `seq $RETRIES`; do + r=`echo 'select 1' | mysql -u$DBUSER -p$DBPASS -P$DBPORT -h$DBHOST -A` + if [ $? -ne 0 ]; then + echo -n "retriying DB conection in $SLEEP seconds: " + sleep $SLEEP + else + break + fi + done + + r=`echo 'select 1' | mysql -u$DBUSER -p$DBPASS -P$DBPORT -h$DBHOST -A` + if [ $? -eq 0 ]; then + echo "OK" + echo -n ">> Checking database connection: " + r=`echo 'select 1' | mysql -u$DBUSER -p$DBPASS -P$DBPORT -h$DBHOST -A $DBNAME` + if [ $? -eq 0 ]; then + echo "OK" + return 0 + fi + echo -n ">> Cannot connect to $DBNAME, trying to create: " + r=`echo "create database $DBNAME" | mysql -u$DBUSER -p$DBPASS -P$DBPORT -h$DBHOST` + if [ $? -eq 0 ]; then + echo "OK" + return 0 + fi + echo "Cannot create database $DBNAME on $DBUSER@$DBHOST:$DBPORT" + + return 1 + fi + + if [ "$DEBUG" == "1" ]; then + echo "Command: [echo 'select 1' | mysql -u$DBUSER -p$DBPASS -P$DBPORT -h$DBHOST -A $DBNAME]" + echo "Output: [$r]" + + traceroute $DBHOST + nmap $DBHOST -v -v -p $DBPORT + fi + + + return 1 +} + +# Load database +# +function db_load { + # Load DB + echo -n ">> Checking database state:" + r=`mysql -u$DBUSER -p$DBPASS -P$DBPORT -h$DBHOST -A $DBNAME -s -e 'show tables'| wc -l` + if [ "$DEBUG" == "1" ]; then + echo "Command: [mysql -u$DBUSER -p$DBPASS -P$DBPORT -h$DBHOST -A $DBNAME -s -e 'show tables'| wc -l]" + echo "Output: [$r]" + fi + + if [ "$r" -ge "$PANDORA_TABLES_MIN" ]; then + echo 'OK. Already exists, '$r' tables detected' + return 0 + fi + echo 'Empty database detected'; + + # Needs to be loaded. + echo -n "- Loading database schema: " + r=`mysql -u$DBUSER -p$DBPASS -P$DBPORT -h$DBHOST $DBNAME < $PANDORA_CONSOLE/pandoradb.sql` + if [ $? -ne 0 ]; then + echo "mysql -u$DBUSER -p$DBPASS -P$DBPORT -h$DBHOST $DBNAME < $PANDORA_CONSOLE/pandoradb.sql" + echo "ERROR" + echo "$r" + return 1; + fi + echo "OK" + + echo -n "- Loading database data: " + r=`mysql -u$DBUSER -p$DBPASS -P$DBPORT -h$DBHOST $DBNAME < $PANDORA_CONSOLE/pandoradb_data.sql` + if [ $? -ne 0 ]; then + echo "ERROR" + echo $r + return 2; + fi + echo "OK" + + # Loaded. + return 0 +} + +# +# Prepare & start Pandora FMS Console +# +function console_prepare { + CONSOLE_PATH=/var/www/html/pandora_console + + echo ">> Preparing console" + # Delete install and license files. + mv $CONSOLE_PATH/install.php $CONSOLE_PATH/install.done + rm -f $CONSOLE_PATH/enterprise/PandoraFMS_Enteprise_Licence.txt + + # Configure console. + cat > $CONSOLE_PATH/include/config.php << EO_CONFIG_F + /etc/httpd/conf.d/pandora.conf << EO_CONFIG_F + + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + + +EO_CONFIG_F + + cat > /var/www/html/index.html << EOF_INDEX + +EOF_INDEX + + echo "- Fixing permissions" + chmod 600 $CONSOLE_PATH/include/config.php + chown -R apache. $CONSOLE_PATH + + # prepare php.ini + sed -i -e "s/^max_input_time.*/max_input_time = -1/g" /etc/php.ini + sed -i -e "s/^max_execution_time.*/max_execution_time = 0/g" /etc/php.ini + sed -i -e "s/^upload_max_filesize.*/upload_max_filesize = 800M/g" /etc/php.ini + sed -i -e "s/^memory_limit.*/memory_limit = 500M/g" /etc/php.ini + + echo "- Setting Public URL: $PUBLICURL" + q=$(mysql -u$DBUSER -p$DBPASS $DBNAME -h$DBHOST -sNe "select token from tconfig;" | grep public_url) + [[ ! "$q" ]] && mysql -u $DBUSER -p$DBPASS $DBNAME -P$DBPORT -h$DBHOST -sNe "INSERT INTO tconfig (token,value) VALUES ('public_url',\"$PUBLICURL\");" + mysql -u$DBUSER -p$DBPASS $DBNAME -h$DBHOST -sNe "UPDATE tconfig SET value=\"$PUBLICURL\" WHERE token=\"public_url\";" + +#touch $CONSOLE_PATH/pandora_console.log +#chown apache. $CONSOLE_PATH/pandora_console.log + +} + +function check_mr { + ## geting MR + Package + CMR=$(mysql -u$DBUSER -p$DBPASS $DBNAME -h$DBHOST -sNe "select value from tconfig where token = 'MR'") + CPK=$(mysql -u$DBUSER -p$DBPASS $DBNAME -h$DBHOST -sNe "select value from tconfig where token = 'current_package_enterprise'") + + DPK=$(grep pandora_version $PANDORA_CONSOLE/include/config_process.php | awk '{print $3}' | tr -d "'" | tr -d ";" | cut -d . -f 3) + DMR=$(ls $PANDORA_CONSOLE/extras/mr/ | sort -n | tail -1 | cut -d . -f 1) + + if [[ $DMR -gt $CMR ]]; then + echo ">> Fixing DB: MR: $CMR Current Package: $CPK Desired MR: $DMR" + cd $PANDORA_CONSOLE/extras/mr/ + for i in $(ls | sort -n); do + cat $i | mysql -u$DBUSER -p$DBPASS $DBNAME -h$DBHOST + done + cd - + + echo ">> Updating DB: MR: $CMR Current Package: $CPK Desired MR: $DMR" + + mysql -u $DBUSER -p$DBPASS $DBNAME -h$DBHOST -sNe "update tconfig set value = $DMR where token = 'MR';" + mysql -u $DBUSER -p$DBPASS $DBNAME -h$DBHOST -sNe "update tconfig set value = $DPK where token = 'current_package_enterprise';" + fi + + +} + +function server_prepare { + sed -i -e "s/^dbhost.*/dbhost $DBHOST/g" $PANDORA_SERVER_CONF + sed -i -e "s/^dbname.*/dbname $DBNAME/g" $PANDORA_SERVER_CONF + sed -i -e "s/^dbuser.*/dbuser $DBUSER/g" $PANDORA_SERVER_CONF + sed -i -e "s|^dbpass.*|dbpass $DBPASS|g" $PANDORA_SERVER_CONF + sed -i -e "s/^dbport.*/dbport $DBPORT/g" $PANDORA_SERVER_CONF + sed -i -e "s/^#servername.*/servername $INSTANCE_NAME/g" $PANDORA_SERVER_CONF + echo "pandora_service_cmd /etc/init.d/pandora_server" >> $PANDORA_SERVER_CONF + + # prepare snmptrapd + cat > /etc/snmp/snmptrapd.conf << EOF +authCommunity log public +disableAuthorization yes +EOF + + ## Enable WUX + if [ "$WUX_SERVER" == "1" ] && [ "$WUX_HOST" ]; then + if [ ! $WUX_PORT ]; then + WUX_PORT=4444 + fi + echo "Enabling WUX server HOST=$WUX_HOST PORT=$WUX_PORT" + sed -i -r "s/#?wuxserver.*/wuxserver 1/g" $PANDORA_SERVER_CONF + sed -i -r "s/#?wux_host.*/wux_host $WUX_HOST/g" $PANDORA_SERVER_CONF + sed -i -r "s/#?wux_port.*/wux_port $WUX_PORT/g" $PANDORA_SERVER_CONF + + fi +} + + +## +## MAIN +## + +if [ "$DBUSER" == "" ] || [ "$DBPASS" == "" ] || [ "$DBNAME" == "" ] || [ "$DBHOST" == "" ]; then + echo "Required environemntal variables DBUSER, DBPASS, DBNAME, DBHOST" + exit 1 +fi +if [ "$DBPORT" == "" ]; then + DBPORT=3306 +fi + +echo "" > /opt/pandora/crontasks || touch /opt/pandora/crontasks + + +#install pandora packages +echo "-> Istalling pandorafms" +cd /opt/pandora +useradd pandora + +if [[ $OPEN != 1 ]]; then + # install enterprise + dnf install -y /opt/pandora/pandorafms_console*.rpm + tar xvfz /opt/pandora/pandorafms_server_*tar* && cd pandora_server && ./pandora_server_installer --install ; rm -rf /opt/pandora/pandora_server + [[ -e /var/www/html/pandora_console/include/config.php ]] || yum reinstall -y /opt/pandora/pandorafms*.rpm + PANDORA_BIN="pandora_ha" + PANDORA_EXEC="/usr/bin/pandora_ha /etc/pandora/pandora_server.conf" +else + install only open + dnf install -y /opt/pandora/pandorafms_console-*.rpm /opt/pandora/pandorafms_server-*.rpm + dnf reinstall -y /opt/pandora/pandorafms_server-*.rpm + [[ -e /var/www/html/pandora_console/include/config.php ]] || dnf reinstall -y /opt/pandora/pandorafms_console-*.rpm + PANDORA_BIN="pandora_server" + PANDORA_EXEC="/usr/bin/pandora_server /etc/pandora/pandora_server.conf" +fi + + + +db_check && db_load + +# Sync to MC. +if [ "$META_DBNAME" != "" ] && [ "$META_DBHOST" != "" ]; then + if [ "$META_DBPORT" == "" ]; then + META_DBPORT=3306 + fi + register_mc +fi + +check_mr +console_prepare +server_prepare + +echo ">> Enable oracle env file cron: " +cat > /etc/pandora/pandora_server.env << 'EOF_ENV' +#!/bin/bash +VERSION=19.8 +export PATH=$PATH:$HOME/bin:/usr/lib/oracle/$VERSION/client64/bin +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/$VERSION/client64/lib +export ORACLE_HOME=/usr/lib/oracle/$VERSION/client64 +EOF_ENV + +echo ">> Enable discovery cron: " +#while true ; do wget -q -O - --no-check-certificate http://localhost/pandora_console/enterprise/cron.php >> /var/www/html/pandora_console/pandora_console.log && sleep 60 ; done & +echo "*/5 * * * * wget -q -O - --no-check-certificate http://localhost/pandora_console/enterprise/cron.php >> /var/www/html/pandora_console/log/cron.log" >> /opt/pandora/crontasks + +echo ">> Enable pandora_db cron: " +/usr/bin/perl /usr/share/pandora_server/util/pandora_db.pl /etc/pandora/pandora_server.conf +#while true ; do sleep 1h && /usr/bin/pandora_db /etc/pandora/pandora_server.conf; done & +echo "0 */1 * * * /usr/bin/pandora_db /etc/pandora/pandora_server.conf" >> /opt/pandora/crontasks + +echo ">> Loading crontab tasks" +crontab -r +crontab /opt/pandora/crontasks && crontab -l + +ip addr | grep -w "inet" | grep -v "127.0.0.1" | grep -v -e "172.1[0-9].0.1" | awk '{print $2}' | awk -F '/' '{print "-> Go to http://"$1"/pandora_console to manage this server"}' + +# Check and launch supervisord +echo ">> Starting process: Running supervisord" +# Create supervisor.conf + +cat > /etc/supervisord.conf << EOF_CON +[unix_http_server] +file=/tmp/supervisor.sock + +[supervisord] +nodaemon=true +loglevel = debug + +[program:php-fpm] +command=/usr/sbin/php-fpm -F +riredirect_stderr=true + +[program:httpd] +command=/usr/sbin/apachectl -DFOREGROUND +riredirect_stderr=true + +[program:tentacle] +command=/etc/init.d/tentacle_serverd restart + +[program:$PANDORA_BIN] +command=$PANDORA_EXEC +riredirect_stderr=true + +[program:cron] +command=crond -n + +[group:allservices] +programs=httpd,cron,php-fpm,$PANDORA_BIN,tentacle + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[supervisorctl] +serverurl=unix:///tmp/supervisor.sock + +EOF_CON + +# execute supervisor +touch /var/log/pandora/pandora_server.log ; tail -F /var/log/pandora/* & +su - -c supervisord diff --git a/extras/docker/percona/Dockerfile b/extras/docker/percona/Dockerfile new file mode 100644 index 0000000000..82b97401d6 --- /dev/null +++ b/extras/docker/percona/Dockerfile @@ -0,0 +1,31 @@ + +#docker build -t pandorafms/pandorafms-percona-base -f $HOME/code/pandorafms/extras/docker/percona/Dockerfile $HOME/code/pandorafms/extras/docker/percona + +FROM percona:5.7 + +RUN echo -e '#PandoraFMS configuration \n\ +[mysqld] \n\ +max_allowed_packet = 64M \n\ +innodb_buffer_pool_size = 500M \n\ +innodb_lock_wait_timeout = 90 \n\ +innodb_file_per_table \n\ +innodb_flush_log_at_trx_commit = 0 \n\ +innodb_flush_method = O_DIRECT \n\ +innodb_log_file_size = 64M \n\ +innodb_log_buffer_size = 16M \n\ +innodb_io_capacity = 100 \n\ +thread_cache_size = 8 \n\ +thread_stack = 256K \n\ +max_connections = 100 \n \n\ +key_buffer_size=4M \n\ +read_buffer_size=128K \n\ +read_rnd_buffer_size=128K \n\ +sort_buffer_size=128K \n\ +join_buffer_size=4M \n\n\ +query_cache_type = 1 \n\ +query_cache_size = 64M \n\ +query_cache_min_res_unit = 2k \n\ +query_cache_limit = 256K \n\n\ +sql_mode="" ' > /etc/my.cnf.d/pandora.cnf + +EXPOSE 3306