Added OS detection
This commit is contained in:
parent
017a6f1f12
commit
1c408b3009
|
@ -4,18 +4,18 @@ FUTURE IMPROVEMENTS
|
||||||
- Sync function merge (master and slave functions are more more or less the same)
|
- Sync function merge (master and slave functions are more more or less the same)
|
||||||
- Tree function merge (current and after tree functions are the same except for output filename and logging)
|
- Tree function merge (current and after tree functions are the same except for output filename and logging)
|
||||||
- Tree functions execute piped commands (grep, awk) on master when launched on remote slave which can cause more bandwith usage
|
- Tree functions execute piped commands (grep, awk) on master when launched on remote slave which can cause more bandwith usage
|
||||||
- Exit trap function must also kill child processes
|
|
||||||
- Make osync run on MSYS for Windows compatibility ?
|
|
||||||
|
|
||||||
KNOWN ISSUES
|
KNOWN ISSUES
|
||||||
------------
|
------------
|
||||||
|
|
||||||
- If master and remote slave systems don't have rsync in the same path, execution may fail (RSYNC_PATH is always configured on master, even when executed on slave)
|
- If master and remote slave systems don't have rsync in the same path, execution may fail (RSYNC_PATH is always configured on master, even when executed on slave)
|
||||||
- When remote system is Msys, Windows' find.exe is used instead of MSYS find
|
|
||||||
|
|
||||||
RECENT CHANGES
|
RECENT CHANGES
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
- Added local and remote operating system detection
|
||||||
|
- Added forced usage of MSYS find on remote MSYS hosts
|
||||||
|
- Updated MSYS handling
|
||||||
- Merged MSYS (MinGW minimal system) bash compatibility under Windows from Obackup
|
- Merged MSYS (MinGW minimal system) bash compatibility under Windows from Obackup
|
||||||
- Added check for /var/log directory
|
- Added check for /var/log directory
|
||||||
- Added check for shared memory directory
|
- Added check for shared memory directory
|
||||||
|
|
71
osync.sh
71
osync.sh
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
###### Osync - Rsync based two way sync engine with fault tolerance
|
###### Osync - Rsync based two way sync engine with fault tolerance
|
||||||
###### (L) 2013 by Orsiris "Ozy" de Jong (www.netpower.fr)
|
###### (L) 2013 by Orsiris "Ozy" de Jong (www.netpower.fr)
|
||||||
OSYNC_VERSION=0.99preRC2
|
OSYNC_VERSION=0.99preRC2-MSYS-compatible
|
||||||
OSYNC_BUILD=1010201301
|
OSYNC_BUILD=1110201301
|
||||||
|
|
||||||
DEBUG=no
|
DEBUG=no
|
||||||
SCRIPT_PID=$$
|
SCRIPT_PID=$$
|
||||||
|
@ -100,7 +100,7 @@ function TrapQuit
|
||||||
if type -p pkill > /dev/null 2>&1
|
if type -p pkill > /dev/null 2>&1
|
||||||
then
|
then
|
||||||
pkill -TERM -P $$
|
pkill -TERM -P $$
|
||||||
elif [ "$OSTYPE" == "msys" ]
|
elif [ "$LOCAL_OS" == "msys" ]
|
||||||
then
|
then
|
||||||
## This is not really a clean way to get child process pids, especially the tail -n +2 which resolves a strange char apparition in msys bash
|
## This is not really a clean way to get child process pids, especially the tail -n +2 which resolves a strange char apparition in msys bash
|
||||||
for pid in $(ps -a | awk '{$1=$1}$1' | awk '{print $1" "$2}' | grep " $$$" | awk '{print $1}' | tail -n +2)
|
for pid in $(ps -a | awk '{$1=$1}$1' | awk '{print $1" "$2}' | grep " $$$" | awk '{print $1}' | tail -n +2)
|
||||||
|
@ -174,6 +174,7 @@ function CleanUp
|
||||||
if [ "$DEBUG" != "yes" ]
|
if [ "$DEBUG" != "yes" ]
|
||||||
then
|
then
|
||||||
rm -f $RUN_DIR/osync_config_$SCRIPT_PID
|
rm -f $RUN_DIR/osync_config_$SCRIPT_PID
|
||||||
|
rm -f $RUN_DIR/osync_remote_os_$SCRIPT_PID
|
||||||
rm -f $RUN_DIR/osync_run_local_$SCRIPT_PID
|
rm -f $RUN_DIR/osync_run_local_$SCRIPT_PID
|
||||||
rm -f $RUN_DIR/osync_run_remote_$SCRIPT_PID
|
rm -f $RUN_DIR/osync_run_remote_$SCRIPT_PID
|
||||||
rm -f $RUN_DIR/osync_master-tree-current_$SCRIPT_PID
|
rm -f $RUN_DIR/osync_master-tree-current_$SCRIPT_PID
|
||||||
|
@ -265,13 +266,56 @@ function CheckEnvironment
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function GetOperatingSystem
|
||||||
|
{
|
||||||
|
LOCAL_OS_VAR=$(uname -spio)
|
||||||
|
if [ "$REMOTE_SYNC" == "yes" ]
|
||||||
|
then
|
||||||
|
eval "$SSH_CMD uname -spio > $RUN_DIR/osync_remote_os_$SCRIPT_PID 2>&1 &"
|
||||||
|
REMOTE_OS_VAR=$(cat $RUN_DIR/osync_remote_os_$SCRIPT_PID)
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $LOCAL_OS_VAR in
|
||||||
|
"Linux"*)
|
||||||
|
LOCAL_OS="Linux"
|
||||||
|
;;
|
||||||
|
"FreeBSD"*)
|
||||||
|
LOCAL_OS="FreeBSD"
|
||||||
|
;;
|
||||||
|
"MINGW32"*)
|
||||||
|
LOCAL_OS="msys"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
LogError "Running on >> $LOCAL_OS_VAR << not supported. Please report to the author."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case $REMOTE_OS_VAR in
|
||||||
|
"Linux"*)
|
||||||
|
REMOTE_OS="Linux"
|
||||||
|
;;
|
||||||
|
"FreeBSD"*)
|
||||||
|
REMOTE_OS="FreeBSD"
|
||||||
|
;;
|
||||||
|
"MINGW32"*)
|
||||||
|
REMOTE_OS="msys"
|
||||||
|
;;
|
||||||
|
"")
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
LogError "Running on remote >> $REMOTE_OS_VAR << not supported. Please report to the author."
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
# Waits for pid $1 to complete. Will log an alert if $2 seconds passed since current task execution unless $2 equals 0.
|
# Waits for pid $1 to complete. Will log an alert if $2 seconds passed since current task execution unless $2 equals 0.
|
||||||
# Will stop task and log alert if $3 seconds passed since current task execution unless $3 equals 0.
|
# Will stop task and log alert if $3 seconds passed since current task execution unless $3 equals 0.
|
||||||
function WaitForTaskCompletion
|
function WaitForTaskCompletion
|
||||||
{
|
{
|
||||||
soft_alert=0
|
soft_alert=0
|
||||||
SECONDS_BEGIN=$SECONDS
|
SECONDS_BEGIN=$SECONDS
|
||||||
if [ "$OSTYPE" == "msys" ]
|
if [ "$LOCAL_OS" == "msys" ]
|
||||||
then
|
then
|
||||||
PROCESS_TEST="ps -a | awk '{\$1=\$1}\$1' | awk '{print \$1}' | grep $1"
|
PROCESS_TEST="ps -a | awk '{\$1=\$1}\$1' | awk '{print \$1}' | grep $1"
|
||||||
else
|
else
|
||||||
|
@ -321,7 +365,7 @@ function WaitForTaskCompletion
|
||||||
function WaitForCompletion
|
function WaitForCompletion
|
||||||
{
|
{
|
||||||
soft_alert=0
|
soft_alert=0
|
||||||
if [ "$OSTYPE" == "msys" ]
|
if [ "$LOCAL_OS" == "msys" ]
|
||||||
then
|
then
|
||||||
PROCESS_TEST="ps -a | awk '{\$1=\$1}\$1' | awk '{print \$1}' | grep $1"
|
PROCESS_TEST="ps -a | awk '{\$1=\$1}\$1' | awk '{print \$1}' | grep $1"
|
||||||
else
|
else
|
||||||
|
@ -457,7 +501,7 @@ function CheckConnectivityRemoteHost
|
||||||
{
|
{
|
||||||
if [ "$REMOTE_HOST_PING" != "no" ] && [ "$REMOTE_SYNC" != "no" ]
|
if [ "$REMOTE_HOST_PING" != "no" ] && [ "$REMOTE_SYNC" != "no" ]
|
||||||
then
|
then
|
||||||
if [ "$OSTYPE" == "msys" ]
|
if [ "$LOCAL_OS" == "msys" ]
|
||||||
then
|
then
|
||||||
ping $REMOTE_HOST -n 2 > /dev/null 2>&1
|
ping $REMOTE_HOST -n 2 > /dev/null 2>&1
|
||||||
else
|
else
|
||||||
|
@ -480,7 +524,7 @@ function CheckConnectivity3rdPartyHosts
|
||||||
IFS=$' \t\n'
|
IFS=$' \t\n'
|
||||||
for i in $REMOTE_3RD_PARTY_HOSTS
|
for i in $REMOTE_3RD_PARTY_HOSTS
|
||||||
do
|
do
|
||||||
if [ "$OSTYPE" == "msys" ]
|
if [ "$LOCAL_OS" == "msys" ]
|
||||||
then
|
then
|
||||||
ping $i -n 2 > /dev/null 2>&1
|
ping $i -n 2 > /dev/null 2>&1
|
||||||
else
|
else
|
||||||
|
@ -1389,6 +1433,8 @@ function SoftDelete
|
||||||
|
|
||||||
function Init
|
function Init
|
||||||
{
|
{
|
||||||
|
GetOperatingSystem
|
||||||
|
|
||||||
# Set error exit code if a piped command fails
|
# Set error exit code if a piped command fails
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
set -o errtrace
|
set -o errtrace
|
||||||
|
@ -1415,14 +1461,19 @@ function Init
|
||||||
MAIL_ALERT_MSG="Warning: Execution of osync instance $OSYNC_ID (pid $SCRIPT_PID) as $LOCAL_USER@$LOCAL_HOST produced errors."
|
MAIL_ALERT_MSG="Warning: Execution of osync instance $OSYNC_ID (pid $SCRIPT_PID) as $LOCAL_USER@$LOCAL_HOST produced errors."
|
||||||
|
|
||||||
## If running Msys, find command of windows is used instead of msys one
|
## If running Msys, find command of windows is used instead of msys one
|
||||||
if [ "$OSTYPE" == "msys" ]
|
if [ "$LOCAL_OS" == "msys" ]
|
||||||
then
|
then
|
||||||
FIND_CMD=$(dirname $BASH)/find
|
FIND_CMD=$(dirname $BASH)/find
|
||||||
else
|
else
|
||||||
FIND_CMD=find
|
FIND_CMD=find
|
||||||
fi
|
fi
|
||||||
## Not elegant... waiting for a good idea on how to detect remote system
|
|
||||||
REMOTE_FIND_CMD=$FIND_CMD
|
if [ "$REMOTE_OS" == "msys" ]
|
||||||
|
then
|
||||||
|
REMOTE_FIND_CMD=$(dirname $BASH)/find
|
||||||
|
else
|
||||||
|
REMOTE_FIND_CMD=find
|
||||||
|
fi
|
||||||
|
|
||||||
## Rsync does not like spaces in directory names, considering it as two different directories. Handling this schema by escaping space
|
## Rsync does not like spaces in directory names, considering it as two different directories. Handling this schema by escaping space
|
||||||
## It seems this only happens when trying to execute an rsync command through eval $rsync_cmd... on a remote host. This is freaking unholy to find a workaround...
|
## It seems this only happens when trying to execute an rsync command through eval $rsync_cmd... on a remote host. This is freaking unholy to find a workaround...
|
||||||
|
|
Loading…
Reference in New Issue