Commit 61d37180 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

collect: Add rotate-log.sh script

Correct and improve some comments.

Add a description to the beginning of each script.
Signed-off-by: 's avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parent 1adbf83a
......@@ -14,9 +14,10 @@ TMPDIR=${PREFIX}/tmp
LASTEXEC=${TMPDIR}/last-exec.tmp
NETLASTEXEC=${TMPDIR}/net-last-exec.tmp
NETMONITOR=${PREFIX}/net/bandwidth.sh
SCHEDULE="* * * * ${PREFIX}/integrity-checker.sh; ${PREFIX}/update.sh; ${PREFIX}/inventory.sh; ${PREFIX}/network-usage.sh; ${PREFIX}/extra-tincuca.sh"
SCHEDULE="* * * * ${PREFIX}/integrity-checker.sh; ${PREFIX}/rotate-log.sh; ${PREFIX}/update.sh; ${PREFIX}/inventory.sh; ${PREFIX}/network-usage.sh; ${PREFIX}/extra-tincuca.sh"
NETSCHEDULE="0-59/5 * * * * ${NETMONITOR}"
UPDATETRIES=3
UPDATETIMEOUT=100
DELAY=86400 # 24 hours
DAYSTOEXPIRELOG=31 # 1 month
XMLPARSER=${PREFIX}/bin/collect-parser
......@@ -19,6 +19,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# This script executes TincUCA
export PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 1
......@@ -31,5 +33,5 @@ for script in ${PREFIX}/extra/scripts/* ; do
${script}
done
date +"%F %T - TincUCA execution terminated sucessfully."
date +"%F %T - TincUCA execution terminated successfully."
exit 0
......@@ -19,6 +19,13 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# This script checks the agente files' integrity and restore them from backup if
# needed. In case the backup doesn't work, an update is forced to occur. It also
# verifies if some update went wrong and tries to redo it. Exit status:
#
# 0 - Success
# 1 - Error: could not restore files nor force update
PREFIX="$(dirname $0)"
PREFIXESC="$(echo ${PREFIX} | sed "s/\./\\\./g")"
......@@ -57,8 +64,8 @@ restore_backup(){
}
# ------------------------------------------------------------------------------
# Will check one file integrity
# If this file is corrupted, tries to restore it from a backup
# Function that checks the integrity of one file. If the file is corrupted, try
# to restore it from a backup
check_file_integrity(){
FILE="$*"
FILEREAL="$(echo ${FILE} |sed "s#^${MD5DIRESC}##g")"
......@@ -69,29 +76,27 @@ check_file_integrity(){
}
# ------------------------------------------------------------------------------
# Will check if all necessary files to run the agent are ok
# If we can't restore some file, this update can't happen
# Function that checks if all necessary files to update the agent are ok. If the
# function is not able to restore some file, this update can't happen
try_force_update(){
DEPENDENTFILES="agent.sh agent.conf client/run.sh client/bin/client
load-config.sh client/common.sh client/conf/version
agent.conf"
DEPENDENTFILES="update.sh agent.conf load-config.sh client/run.sh
client/common.sh client/bin/client client/conf/version"
for FILE in ${DEPENDENTFILES}; do
check_file_integrity "${MD5DIR}/${FILE}" || return 1
done
# Just to make sure the agent will auto update
# Make sure the agent will update itself
echo "0.0.0" > "${PREFIX}/client/conf/version"
# Luck for us, all needed files are ok so we can call the agent
# Source the agent, it will be auto updated
source "${PREFIX}/agent.sh" || return 1
# All needed files are ok, so call the update script
source "${PREFIX}/update.sh" || return 1
return 0
}
# ------------------------------------------------------------------------------
# Will try to auto update in a simpler way
# Function that tries to autoupdate in a simpler way
# If everything goes wrong, this is our last hope
update_myself(){
UPDATETRIES=3
......@@ -142,7 +147,7 @@ update_myself(){
-O "${TMPDIR}/SEED2-update.run" \
&> /dev/null || return 1
# Package downloaded, now try to update
# The package was downloaded, now try to update the agent
bash "${TMPDIR}/SEED2-update.run" || return 1
rm -f "${TMPDIR}/SEED2-update.run" &> /dev/null
......@@ -150,19 +155,22 @@ update_myself(){
}
# ------------------------------------------------------------------------------
# First check if some update went wrong
date +"%F %T - Start of integrity checker execution."
# First, check if some update went wrong
if test -e "${PREFIX}/updating" || ! test -d "${MD5DIR}"; then
try_force_update || update_myself || exit 1
try_force_update || update_myself ||
(printf "ERROR: Forced update didn't work.\n" && exit 1)
rm -f "${PREFIX}/updating" 2> /dev/null
exit 0
else
# Check all MD5 files
for FILE in $(find "${MD5DIR}" -type f); do
check_file_integrity ${FILE} ||
((try_force_update || update_myself) && exit 0) ||
(printf "ERROR: Could not restore files nor update the agent.\n"
&& exit 1)
done
fi
# ------------------------------------------------------------------------------
# Checking all files MD5
for FILE in $(find "${MD5DIR}" -type f); do
check_file_integrity ${FILE} ||
((try_force_update || update_myself) && exit 0) ||
exit 1
done
date +"%F %T - Integrity checker terminated successfully."
exit 0
......@@ -19,10 +19,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# Exit status:
# This script collects the machine inventory, generating and sending an XML to
# the server. Exit status:
#
# 0 - Success
# 1 - Error when loading configuration
# 1 - Error while loading configuration
# 2 - INEP not configured
# 3 - XML filename not defined
# 4 - Client not found or without execution permission
......@@ -68,10 +69,13 @@ source ${PREFIX}/load-config.sh || exit 1
exec >> ${LOGFILE} 2>&1
date +"%F %T - Start of inventory execution."
# Check if inep file exists and is configured
if ! test -f ${CLIENTCONFDIR}/inep -a -n "$(cat ${CLIENTCONFDIR}/inep \
2> /dev/null)"; then
date +"%F %T - INEP not found in ${CLIENTCONFDIR}/inep, waiting configuration."
date \
+"%F %T - INEP not found in ${CLIENTCONFDIR}/inep, waiting configuration."
exit 2
fi
......@@ -106,5 +110,5 @@ if elapsedTime; then
date +%s > ${LASTEXEC}
fi
date +"%F %T - Inventory terminated sucessfully."
date +"%F %T - Inventory terminated successfully."
exit 0
......@@ -19,6 +19,12 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# This script loads the configuration file and all of its valid variables. Exit
# status:
#
# 0 - Success
# 1 - Error
# ------------------------------------------------------------------------------
# Function: message
# Treat output error stream.
......
......@@ -19,14 +19,15 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# Exit status:
# This script collects the machine network usage, generating and sending an XML
# to the server. Exit status:
#
# 0 - Success
# 1 - Error when loading configuration
# 1 - Error while loading configuration
# 2 - INEP not configured
# 3 - XML filename not defined
# 4 - Client not found or without execution permission
# 5 - Error while collecting network usage
# 5 - Error while collecting network usage data
# 6 - Error while executing the client
# ------------------------------------------------------------------------------
......@@ -69,6 +70,8 @@ PREVIOUS_TRAFFIC="${PREFIX}/../../../net/previous-traffic.txt"
exec >> ${LOGFILE} 2>&1
date +"%F %T - Start of network usage execution."
# Check if inep file exists and is configured
if ! test -f ${CLIENTCONFDIR}/inep -a -n "$(cat ${CLIENTCONFDIR}/inep \
2> /dev/null)"; then
......@@ -100,7 +103,7 @@ if elapsedTime && test -s "${PREVIOUS_TRAFFIC}"; then
fi
date +"%F %T - New network usage data collected."
if ! clientExec --network; then
if ! clientExec --net-usage; then
exit 6
fi
......@@ -108,5 +111,5 @@ if elapsedTime && test -s "${PREVIOUS_TRAFFIC}"; then
date +%s > ${NETLASTEXEC}
fi
date +"%F %T - Network usage terminated sucessfully."
date +"%F %T - Network usage terminated successfully."
exit 0
#!/bin/bash
# Copyright (C) 2009-2012 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of collect-agent
#
# collect-agent is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# This script rotates the collect log file if it has expired. Exit status:
#
# 0 - Success
# 1 - Error while rolling log file
# ------------------------------------------------------------------------------
# Function: rotateLogFile
# If the log file is out-of-date (set by $2), execute savelog(1) to rotate it.
# Parameters:
# $1: log file name
# $2: time in days to expire
# $3: save $3 versions of the log file
function rotateLogFile()
{
find "${LOGDIR}" -type f -name "$1" -atime +$2 -exec savelog -c $3 {} \; ||
return 1
return 0
}
# ------------------------------------------------------------------------------
export PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 1
exec >> ${LOGFILE} 2>&1
date +"%F %T - Start of rotate log execution."
# Rotate the log file if it has already expired
if ! rotateLogFile '*.log' ${DAYSTOEXPIRELOG} 12; then
date +"%F %T - Error while rolling log file."
exit 1
fi
date +"%F %T - Rotate log terminated successfully."
exit 0
......@@ -19,28 +19,12 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# Exit status:
# This script updates the agent if there's a new version available. Exit status:
#
# 0 - Success
# 1 - Error when loading configuration
# 2 - Error to rotate log file
# 3 - Error to edit crontab
# 4 - Error while trying to update the agent
# ------------------------------------------------------------------------------
# Function: rotateLogFile
# If the log file is out-of-date (set by $2), execute savelog(1) to rotate it.
# Parameters:
# $1: log file name
# $2: time in days to expire
# $3: save $3 versions of the log file
function rotateLogFile()
{
find "${LOGDIR}" -type f -name "$1" -atime +$2 -exec savelog -c $3 {} \; ||
return 1
return 0
}
# 1 - Error while loading configuration
# 2 - Error to edit crontab
# 3 - Error while trying to update the agent
# ------------------------------------------------------------------------------
# Function: checkUpdate
......@@ -100,18 +84,12 @@ source ${PREFIX}/client/common.sh
exec >> ${LOGFILE} 2>&1
# Rotate the log file if it has already expired
if ! rotateLogFile '*.log' ${DAYSTOEXPIRELOG} 12; then
date +"%F %T - Error while rolling log file."
exit 2
fi
date +"%F %T - Agent started."
date +"%F %T - Start of update process execution."
# Edit crontab if it isn't correct
if ! schedule; then
date +"%F %T - Error to edit crontab."
exit 3
exit 2
fi
# If this is the agent's first execution, save the version and force the update
......@@ -130,8 +108,8 @@ test "${FIRST_EXECUTION}" && echo "${REALVERSION}" > "${VERSIONFILE}"
test ${updateStatus} -eq 4 && exit 0
if test ${updateStatus} -ne 0; then
date +"%F %T - Error while trying to update the agent."
exit 4
exit 3
fi
date +"%F %T - Update process terminated sucessfully."
date +"%F %T - Update process terminated successfully."
exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment