]> source.dussan.org Git - nextcloud-server.git/commitdiff
Replace shitty netcat use with dedicated PHP script
authorRobin McCorkell <rmccorkell@owncloud.com>
Tue, 24 Nov 2015 15:42:01 +0000 (15:42 +0000)
committerRobin McCorkell <rmccorkell@owncloud.com>
Tue, 24 Nov 2015 16:05:08 +0000 (16:05 +0000)
apps/files_external/tests/env/start-amazons3-ceph.sh
apps/files_external/tests/env/start-ftp-morrisjobke.sh
apps/files_external/tests/env/start-sftp-atmoz.sh
apps/files_external/tests/env/start-smb-silvershell.sh
apps/files_external/tests/env/start-smb-windows.sh
apps/files_external/tests/env/start-swift-ceph.sh
apps/files_external/tests/env/start-webdav-ownCloud.sh
apps/files_external/tests/env/wait-for-connection [new file with mode: 0755]

index b40d28f1ec6af695fbf5621b023c6e231d438bf7..20fa7e7bb2b9b653f64e4994726b988de05a44aa 100755 (executable)
@@ -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"
index 3c6cc62bce8db573aee521e929c7dc9e89df4f42..3a5f6ffcb67c082a84c3c3759358f98e7a40fed3 100755 (executable)
@@ -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
index 3e0616f03d296e01033188b0f8b1c9cd6fd3320b..0fc0c5c427ff037e7c46e70301338da1d72ecdf9 100755 (executable)
@@ -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
index 31e3da4464610eb6205dc4829ab885a569400581..a7ff3f71eb1f88e157fdeedb43710e2cc7fe854a 100755 (executable)
@@ -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
index 6779cdb2d5672347c31e70c9647a71384bc420d8..9453b4eb3e7072529ad6b5f94b5ad63fa36fe539 100755 (executable)
@@ -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
index ea16e167af9ae82f4587de9a1683012a686e7f53..936bb667e94bb9b4bc8faf373537181512146edb 100755 (executable)
@@ -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
index f04616d49916e7023644cfe72897528f68bd0906..d992516d7b18bd0ed00e1d94f187f8e1d0fbc793 100755 (executable)
@@ -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
diff --git a/apps/files_external/tests/env/wait-for-connection b/apps/files_external/tests/env/wait-for-connection
new file mode 100755 (executable)
index 0000000..2c480fb
--- /dev/null
@@ -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);