-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from nperron/bug_3925/int/prevent_from_having…
…_no_uuid Fixes #3925 - Prevent UUID to be removed
- Loading branch information
Showing
6 changed files
with
113 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/sh | ||
##################################################################################### | ||
# Copyright 2013 Normation SAS | ||
##################################################################################### | ||
# | ||
# This program 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, Version 3. | ||
# | ||
# 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, see <http://www.gnu.org/licenses/>. | ||
# | ||
##################################################################################### | ||
|
||
set -e | ||
|
||
check_and_fix_cfengine_processes() { | ||
|
||
# Default variables for CFEngine binaries and disable files | ||
CFE_DIR=/var/rudder/cfengine-community | ||
CFE_BIN_DIR=${CFE_BIN_DIR}/bin | ||
CFE_DISABLE_FILE=/opt/rudder/etc/disable-agent | ||
|
||
# If no disable file AND no process of CFEngine from Rudder, then relaunch cf-agent with a failsafe first | ||
# But this is applied only on servers or nodes already initialized (policy server set) | ||
if [ ! -e ${CFE_DISABLE_FILE} -a `ps -efww | grep -E "(cf-execd|cf-agent)" | grep -E "${CFE_BIN_DIR}/(cf-execd|cf-agent)" | grep -v grep | wc -l` -eq 0 -a -f ${CFE_DIR}/policy_server.dat ]; then | ||
echo -n "WARNING: No disable file detected and no CFEngine process neither. Relaunching CFEngine processes..." | ||
${CFE_BIN_DIR}/cf-agent -f failsafe.cf >/dev/null 2>&1 | ||
${CFE_BIN_DIR}/cf-agent >/dev/null 2>&1 | ||
echo " Done" | ||
fi | ||
} | ||
|
||
check_and_fix_rudder_uuid() { | ||
|
||
# Default variables about UUID file and its backups | ||
BACKUP_DIR=/var/backups/rudder/ | ||
UUID_FILE=/opt/rudder/etc/uuid.hive | ||
LATEST_BACKUPED_UUID="" | ||
|
||
# Generate a UUID if we don't have one yet | ||
if [ ! -e ${UUID_FILE} ]; then | ||
if [ -d ${BACKUP_DIR} ]; then | ||
LATEST_BACKUPED_UUID=$(ls -v1 ${BACKUP_DIR} | tail -n1) | ||
fi | ||
if [ -f ${BACKUP_DIR}${LATEST_BACKUPED_UUID} ]; then | ||
echo -n "WARNING: The UUID of the node does not exist. The lastest backup (${LATEST_BACKUPED_UUID}) will be recovered..." | ||
cp -a ${BACKUP_DIR}${LATEST_BACKUPED_UUID} ${UUID_FILE} >/dev/null 2>&1 | ||
echo " Done" | ||
else | ||
echo -n "WARNING: The UUID of the node does not exist and no backup exist. A new one will be generated..." | ||
uuidgen > ${UUID_FILE} | ||
echo " Done" | ||
fi | ||
else | ||
# UUID is valid only if it has been generetaed by uuidgen or if it is set to 'root' for policy server | ||
CHECK_UUID=`cat /opt/rudder/etc/uuid.hive | grep -E "^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}|root" | wc -l` | ||
# If the UUID is not valid, regenerate it | ||
if [ ${CHECK_UUID} -ne 1 ]; then | ||
echo -n "INFO: Creating a new UUID for Rudder as the existing one is invalid..." | ||
# Keep a backup of UUID even if it is not valid | ||
mkdir -p /var/backups/rudder | ||
cp -f /opt/rudder/etc/uuid.hive /var/backups/rudder/uuid-$(date +%Y%m%d).hive | ||
# Generate a new one | ||
uuidgen > ${UUID_FILE} | ||
echo " Done." | ||
fi | ||
fi | ||
} | ||
|
||
# Ensure script is executed by root | ||
if [ ! $(whoami) = 'root' ];then echo "You must be root"; exit; fi | ||
|
||
# Launch each check with a certain order | ||
check_and_fix_rudder_uuid | ||
check_and_fix_cfengine_processes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters