Replace shitty netcat use with dedicated PHP script

This commit is contained in:
Robin McCorkell 2015-11-24 15:42:01 +00:00
parent 4978a785fa
commit 125b090627
8 changed files with 71 additions and 81 deletions

View File

@ -50,19 +50,10 @@ echo "${docker_image} container: $container"
echo $container >> $thisFolder/dockerContainerCeph.$EXECUTOR_NUMBER.amazons3
echo -n "Waiting for ceph initialization"
starttime=$(date +%s)
# support for GNU netcat and BSD netcat
while ! (nc -c -w 1 ${host} ${port} </dev/null >&/dev/null \
|| nc -w 1 ${host} ${port} </dev/null >&/dev/null); do
sleep 1
echo -n '.'
if (( $(date +%s) > starttime + 60 )); then
echo
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
done
echo
if ! "$thisFolder"/env/wait-for-connection ${host} ${port} 60; then
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
sleep 1
echo "Create ceph user"

View File

@ -55,19 +55,10 @@ echo "ftp container: $container"
echo $container >> $thisFolder/dockerContainerMorrisJobke.$EXECUTOR_NUMBER.ftp
echo -n "Waiting for ftp initialization"
starttime=$(date +%s)
# support for GNU netcat and BSD netcat
while ! (nc -c -w 1 ${host} 21 </dev/null >&/dev/null \
|| nc -w 1 ${host} 21 </dev/null >&/dev/null); do
sleep 1
echo -n '.'
if (( $(date +%s) > starttime + 60 )); then
echo
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
done
echo
if ! "$thisFolder"/env/wait-for-connection ${host} 21 60; then
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
sleep 1
if [ -n "$DEBUG" ]; then

View File

@ -55,19 +55,10 @@ echo "sftp container: $container"
echo $container >> $thisFolder/dockerContainerAtmoz.$EXECUTOR_NUMBER.sftp
echo -n "Waiting for sftp initialization"
starttime=$(date +%s)
# support for GNU netcat and BSD netcat
while ! (nc -c -w 1 ${host} 22 </dev/null >&/dev/null \
|| nc -w 1 ${host} 22 </dev/null >&/dev/null); do
sleep 1
echo -n '.'
if (( $(date +%s) > starttime + 60 )); then
echo
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
done
echo
if ! "$thisFolder"/env/wait-for-connection ${host} 22 60; then
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
sleep 1
if [ -n "$DEBUG" ]; then

View File

@ -53,19 +53,10 @@ echo "samba container: $container"
echo $container >> $thisFolder/dockerContainerSilvershell.$EXECUTOR_NUMBER.smb
echo -n "Waiting for samba initialization"
starttime=$(date +%s)
# support for GNU netcat and BSD netcat
while ! (nc -c -w 1 ${host} 445 </dev/null >&/dev/null \
|| nc -w 1 ${host} 445 </dev/null >&/dev/null); do
sleep 1
echo -n '.'
if (( $(date +%s) > starttime + 60 )); then
echo
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
done
echo
if ! "$thisFolder"/env/wait-for-connection ${host} 445 60; then
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
sleep 1
if [ -n "$DEBUG" ]; then

View File

@ -19,8 +19,7 @@ user=smb-test
password=!owncloud123
host=WIN-9GTFAS08C15
if ! (nc -c -w 1 ${host} 445 </dev/null >&/dev/null \
|| nc -w 1 ${host} 445 </dev/null >&/dev/null); then
if ! "$thisFolder"/env/wait-for-connection ${host} 445 0; then
echo "[ERROR] Server not reachable" >&2
exit 1
fi

View File

@ -57,19 +57,10 @@ echo "${docker_image} container: $container"
echo $container >> $thisFolder/dockerContainerCeph.$EXECUTOR_NUMBER.swift
echo -n "Waiting for ceph initialization"
starttime=$(date +%s)
# support for GNU netcat and BSD netcat
while ! (nc -c -w 1 ${host} 80 </dev/null >&/dev/null \
|| nc -w 1 ${host} 80 </dev/null >&/dev/null); do
sleep 1
echo -n '.'
if (( $(date +%s) > starttime + 60 )); then
echo
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
done
echo
if ! "$thisFolder"/env/wait-for-connection ${host} 80 60; then
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
sleep 1
cat > $thisFolder/config.swift.php <<DELIM

View File

@ -46,22 +46,13 @@ fi
container=`docker run -P $parameter -d -e ADMINLOGIN=test -e ADMINPWD=test morrisjobke/owncloud`
host=`docker inspect $container | grep IPAddress | cut -d '"' -f 4`
host=`docker inspect --format="{{.NetworkSettings.IPAddress}}" $container`
echo -n "Waiting for ownCloud initialization"
starttime=$(date +%s)
# support for GNU netcat and BSD netcat
while ! (nc -c -w 1 ${host} 80 </dev/null >&/dev/null \
|| nc -w 1 ${host} 80 </dev/null >&/dev/null); do
sleep 1
echo -n '.'
if (( $(date +%s) > starttime + 60 )); then
echo
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
done
echo
if ! "$thisFolder"/env/wait-for-connection ${host} 80 60; then
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
# wait at least 5 more seconds - sometimes the webserver still needs some additional time
sleep 5

View File

@ -0,0 +1,45 @@
#!/usr/bin/php
<?php
$timeout = 60;
switch ($argc) {
case 4:
$timeout = (float)$argv[3];
case 3:
$host = $argv[1];
$port = (int)$argv[2];
break;
default:
fwrite(STDERR, 'Usage: '.$argv[0].' host port [timeout]'."\n");
exit(2);
}
if ($timeout < 0) {
fwrite(STDERR, 'Timeout must be greater than zero'."\n");
exit(2);
}
if ($port < 1) {
fwrite(STDERR, 'Port must be an integer greater than zero'."\n");
exit(2);
}
$socketTimeout = (float)ini_get('default_socket_timeout');
if ($socketTimeout > $timeout) {
$socketTimeout = $timeout;
}
$stopTime = time() + $timeout;
do {
$sock = @fsockopen($host, $port, $errno, $errstr, $socketTimeout);
if ($sock !== false) {
fclose($sock);
fwrite(STDOUT, "\n");
exit(0);
}
sleep(1);
fwrite(STDOUT, '.');
} while (time() < $stopTime);
fwrite(STDOUT, "\n");
exit(1);