From 913356445543ddbdf6953a7cc3bcf7aaf2b996b0 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 6 Aug 2020 16:20:43 +0200 Subject: [PATCH] Correction du bug cron Ajout de couleurs dans les logs --- glpi.cron | 4 ++++ glpi_init.sh | 46 ++++++++++++++++++++++++++++------------ service/20-cron/run | 7 ++++++ service/30-apache2/run | 5 +++++ service/90-glpi_init/run | 6 ++++++ service/template | 7 ++++++ 6 files changed, 62 insertions(+), 13 deletions(-) create mode 100755 service/20-cron/run create mode 100755 service/30-apache2/run create mode 100755 service/90-glpi_init/run create mode 100644 service/template diff --git a/glpi.cron b/glpi.cron index 2803a1d..1b31779 100644 --- a/glpi.cron +++ b/glpi.cron @@ -1 +1,5 @@ +GLPI_CONFIG_DIR=/etc/glpi +GLPI_VAR_DIR=/var/lib/glpi +GLPI_LOG_DIR=/var/log/glpi + */1 * * * * www-data /usr/local/bin/php /var/www/html/front/cron.php diff --git a/glpi_init.sh b/glpi_init.sh index dae1ee3..8843288 100644 --- a/glpi_init.sh +++ b/glpi_init.sh @@ -1,19 +1,37 @@ #!/bin/sh GLPI_TARBALL="/root/glpi-9.5.1.tgz" FUSION_TARBALL="/root/fusioninventory-9.5.0+1.0.tar.bz2" +NORMAL='\e[39m' +RED='\e[31m' +GREEN='\e[32m' -init_db() { -while ! mysqlshow -h db -uroot -p${MYSQL_ROOT_PASSWORD} | grep "^| ${MYSQL_DATABASE}" > /dev/null 2>&1 ; do - echo "Waiting for mysql database initilization..." - sleep 5 -done -echo "Starting glpi configuration..." - +msglog() { + case "${1}" in + green) + TEXT_COLOR="${GREEN}" + ;; + red) + TEXT_COLOR="${RED}" + ;; + normal) + TEXT_COLOR="${NORMAL}" + ;; + esac + DATE=$(date '+%Y %b %d %H:%M:%S') + echo ${DATE} ${TEXT_COLOR}${2}${NORMAL} } -if [ -z $(ls -A /var/www/html) ] ; then - init_db - echo "Initilazing ${GLPI_TARBALL}" +waiting_for_db() { +while ! mysqlshow -h db -uroot -p${MYSQL_ROOT_PASSWORD} 2>&1 | grep "^| ${MYSQL_DATABASE}" > /dev/null 2>&1 ; do + msglog red "Waiting for mysql database initilization..." + sleep 5 +done +} + + +if [ -z "$(ls -A /var/www/html)" ] ; then + waiting_for_db + msglog red "Initialazing ${GLPI_TARBALL}..." cd /root tar xf ${GLPI_TARBALL} cp -r /root/glpi/config/. /etc/glpi/. @@ -33,16 +51,18 @@ EOF php bin/console glpi:plugin:activate fusioninventory -n rm install/install.php chown -R www-data:www-data /var/www/html /etc/glpi /var/lib/glpi /var/log/glpi + msglog green "Initialazing complete..." else - echo "GLPI is already initialized" + msglog green "GLPI is already initialized" cd /var/www/html GLPI_ACTUAL_VERSION=$(awk -F", '" '/^define\(.GLPI_VERSION/ { print $2 }' inc/define.php | sed 's/\([0-9\.]*\).*/\1/') FUSIONINVENTORY_ACTUAL_VERSION=$(awk -F', "' '/^define \(.PLUGIN_FUSIONINVENTORY_VERSION/ { print $2 }' plugins/fusioninventory/setup.php | sed 's/\([0-9\.+]*\).*/\1/') if [ "${GLPI_ACTUAL_VERSION}" = "${GLPI_VERSION}" -a "${FUSIONINVENTORY_ACTUAL_VERSION}" = "${FUSIONINVENTORY_VERSION}" ] ; then - echo GLPI already up2date + msglog green "GLPI already up2date" exit fi - init_db + msglog red "Updating GLPI from ${GLPI_ACTUAL_VERSION} to ${GLPI_VERSION}" + waiting_for_db php bin/console glpi:maintenance:enable -n php bin/console glpi:plugin:deactivate fusioninventory -n cd /root diff --git a/service/20-cron/run b/service/20-cron/run new file mode 100755 index 0000000..6e627a1 --- /dev/null +++ b/service/20-cron/run @@ -0,0 +1,7 @@ +#!/bin/sh +. /etc/service/template + +msglog "Starting Cron..." +# Touch cron files to fix 'NUMBER OF HARD LINKS > 1' issue. See https://github.com/phusion/baseimage-docker/issues/198 +touch -c /etc/crontab /etc/cron.*/* /var/spool/cron/crontabs/* +exec /usr/sbin/cron -f diff --git a/service/30-apache2/run b/service/30-apache2/run new file mode 100755 index 0000000..fe65c83 --- /dev/null +++ b/service/30-apache2/run @@ -0,0 +1,5 @@ +#!/bin/sh +. /etc/service/template + +msglog "Starting Apache..." +exec apache2-foreground diff --git a/service/90-glpi_init/run b/service/90-glpi_init/run new file mode 100755 index 0000000..c721ff1 --- /dev/null +++ b/service/90-glpi_init/run @@ -0,0 +1,6 @@ +#!/bin/sh +. /etc/service/template + +msglog "Starting glpi_init.sh..." +/root/glpi_init.sh +sleep infinity diff --git a/service/template b/service/template new file mode 100644 index 0000000..1b7e167 --- /dev/null +++ b/service/template @@ -0,0 +1,7 @@ +NORMAL='\e[39m' +RED='\e[31m' + +msglog() { + DATE=$(date '+%Y %b %d %H:%M:%S') + echo ${DATE} ${RED}${@}${NORMAL} +}