Correction du bug cron

Ajout de couleurs dans les logs
This commit is contained in:
root 2020-08-06 16:20:43 +02:00
parent 65ed791507
commit 9133564455
6 changed files with 62 additions and 13 deletions

View File

@ -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 */1 * * * * www-data /usr/local/bin/php /var/www/html/front/cron.php

View File

@ -1,19 +1,37 @@
#!/bin/sh #!/bin/sh
GLPI_TARBALL="/root/glpi-9.5.1.tgz" GLPI_TARBALL="/root/glpi-9.5.1.tgz"
FUSION_TARBALL="/root/fusioninventory-9.5.0+1.0.tar.bz2" FUSION_TARBALL="/root/fusioninventory-9.5.0+1.0.tar.bz2"
NORMAL='\e[39m'
RED='\e[31m'
GREEN='\e[32m'
init_db() { msglog() {
while ! mysqlshow -h db -uroot -p${MYSQL_ROOT_PASSWORD} | grep "^| ${MYSQL_DATABASE}" > /dev/null 2>&1 ; do case "${1}" in
echo "Waiting for mysql database initilization..." green)
sleep 5 TEXT_COLOR="${GREEN}"
done ;;
echo "Starting glpi configuration..." 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 waiting_for_db() {
init_db while ! mysqlshow -h db -uroot -p${MYSQL_ROOT_PASSWORD} 2>&1 | grep "^| ${MYSQL_DATABASE}" > /dev/null 2>&1 ; do
echo "Initilazing ${GLPI_TARBALL}" 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 cd /root
tar xf ${GLPI_TARBALL} tar xf ${GLPI_TARBALL}
cp -r /root/glpi/config/. /etc/glpi/. cp -r /root/glpi/config/. /etc/glpi/.
@ -33,16 +51,18 @@ EOF
php bin/console glpi:plugin:activate fusioninventory -n php bin/console glpi:plugin:activate fusioninventory -n
rm install/install.php rm install/install.php
chown -R www-data:www-data /var/www/html /etc/glpi /var/lib/glpi /var/log/glpi chown -R www-data:www-data /var/www/html /etc/glpi /var/lib/glpi /var/log/glpi
msglog green "Initialazing complete..."
else else
echo "GLPI is already initialized" msglog green "GLPI is already initialized"
cd /var/www/html cd /var/www/html
GLPI_ACTUAL_VERSION=$(awk -F", '" '/^define\(.GLPI_VERSION/ { print $2 }' inc/define.php | sed 's/\([0-9\.]*\).*/\1/') 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/') 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 if [ "${GLPI_ACTUAL_VERSION}" = "${GLPI_VERSION}" -a "${FUSIONINVENTORY_ACTUAL_VERSION}" = "${FUSIONINVENTORY_VERSION}" ] ; then
echo GLPI already up2date msglog green "GLPI already up2date"
exit exit
fi 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:maintenance:enable -n
php bin/console glpi:plugin:deactivate fusioninventory -n php bin/console glpi:plugin:deactivate fusioninventory -n
cd /root cd /root

7
service/20-cron/run Executable file
View File

@ -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

5
service/30-apache2/run Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
. /etc/service/template
msglog "Starting Apache..."
exec apache2-foreground

6
service/90-glpi_init/run Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
. /etc/service/template
msglog "Starting glpi_init.sh..."
/root/glpi_init.sh
sleep infinity

7
service/template Normal file
View File

@ -0,0 +1,7 @@
NORMAL='\e[39m'
RED='\e[31m'
msglog() {
DATE=$(date '+%Y %b %d %H:%M:%S')
echo ${DATE} ${RED}${@}${NORMAL}
}