49 lines
1.5 KiB
Bash
49 lines
1.5 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
# Arrete le socle, Nettoie les fichiers temporaire et logs
|
||
|
|
||
|
# Nombre de jour de conservation
|
||
|
SOCLE_LOG_KEEP=30
|
||
|
TOMCAT_LOG_KEEP=5
|
||
|
|
||
|
# Chemin des dossiers
|
||
|
TOMCAT_TEMP=~/tomcat/temp/
|
||
|
TOMCAT_LOGS=~/tomcat/logs/
|
||
|
SOCLE_LOGS=~/logs/
|
||
|
|
||
|
# Les variables ci dessus sont écrasés si le fichier .exploit_vars existe dans le home et les variables redéfis
|
||
|
test -f ~/.exploit_vars && source ~/.exploit_vars
|
||
|
|
||
|
# On arrete le socle
|
||
|
sudo systemctl stop socle
|
||
|
|
||
|
sleep 20
|
||
|
|
||
|
# on nettoie
|
||
|
# fichiers et dossiers temp du tomcat
|
||
|
find "${TOMCAT_TEMP}" -mindepth 1 -type f -delete -print
|
||
|
find "${TOMCAT_TEMP}" -mindepth 1 -type d -delete -print
|
||
|
|
||
|
# fichier logs du tomcat a l'arret
|
||
|
gzip -S ".$(date +%Y%m%d).gz" ${TOMCAT_LOGS}/catalina.out
|
||
|
find "${TOMCAT_LOGS}" -name "*.log" -mtime +${TOMCAT_LOG_KEEP} -delete -print
|
||
|
find "${TOMCAT_LOGS}" -name "*.txt" -mtime +${TOMCAT_LOG_KEEP} -delete -print
|
||
|
find "${TOMCAT_LOGS}" -name "*.gz" -mtime +${TOMCAT_LOG_KEEP} -delete -print
|
||
|
|
||
|
# fichiers logs de l'application socle
|
||
|
find "${SOCLE_LOGS}" -name "*.log*" -mtime +${SOCLE_LOG_KEEP} -delete -print
|
||
|
|
||
|
# Recherche et compression des fichiers de logs non compressés
|
||
|
YMD=$(date +%y%m%d -d "1 days ago")
|
||
|
for xfile in $(find "${SOCLE_LOGS}" -name "*.log*" -mtime +2 -type f | grep -v ".gz")
|
||
|
do
|
||
|
echo "Compression de : $xfile"
|
||
|
gzip --suffix=_$YMD.gz $xfile
|
||
|
done
|
||
|
|
||
|
# Suppression des répertoires vides
|
||
|
find ${SOCLE_LOGS} -empty -mtime +${SOCLE_LOG_KEEP} -type d -delete
|
||
|
|
||
|
# on redemarre le socle
|
||
|
sudo systemctl start socle
|