epoptes team mailing list archive
-
epoptes team
-
Mailing list archive
-
Message #00976
[Merge] lp:~oiteam/epoptes/auto-reconnect into lp:epoptes
Laércio de Sousa has proposed merging lp:~oiteam/epoptes/auto-reconnect into lp:epoptes.
Requested reviews:
Epoptes Developers (epoptes)
For more details, see:
https://code.launchpad.net/~oiteam/epoptes/auto-reconnect/+merge/273468
Re-proposing this merge after some rework following Alkis advices (via IRC).
--
Your team Epoptes Developers is requested to review the proposed merge of lp:~oiteam/epoptes/auto-reconnect into lp:epoptes.
=== modified file 'epoptes-client/epoptes-client'
--- epoptes-client/epoptes-client 2015-08-14 19:35:28 +0000
+++ epoptes-client/epoptes-client 2015-10-05 20:03:48 +0000
@@ -230,15 +230,44 @@
cert_param="verify=0"
fi
-# Connect to the server, or keep retrying until the server gets online
-# (for standalone workstations booted before the server).
if [ -s /etc/epoptes/server.crt ] || [ "$cert_param" = "verify=0" ]; then
- exec socat openssl-connect:$SERVER:$PORT,$cert_param,interval=60,forever EXEC:"$cmdline"
+ SOCAT_PREFIX="openssl-connect"
+ SOCAT_CERT=",$cert_param"
+ SOCAT_SUFFIX=""
elif [ -f /etc/epoptes/server.crt ]; then
- exec socat tcp:$SERVER:$PORT,interval=60,forever EXEC:"$cmdline",nofork
+ SOCAT_PREFIX="tcp"
+ SOCAT_CERT=""
+ SOCAT_SUFFIX=",nofork"
else
die "
The epoptes certificate file, /etc/epoptes/server.crt, doesn't exist.
You can fetch the server certificate by running:
$0 -c"
+ exit 1
+fi
+
+# Connect to the server, or keep retrying until the server gets online
+# (for standalone workstations booted before the server).
+# Uses SIGTERM-propagation scheme as proposed in
+# http://veithen.github.io/2014/11/16/sigterm-propagation.html
+if [ "$TYPE" = "standalone" ]; then
+ trap 'kill -TERM $SOCAT_PID; KEEP_ALIVE=false' TERM INT
+ KEEP_ALIVE=true
+
+ while $KEEP_ALIVE; do
+ socat ${SOCAT_PREFIX}:${SERVER}:${PORT}${SOCAT_CERT},interval=60,forever EXEC:"$cmdline"${SOCAT_SUFFIX} &
+ SOCAT_PID=$!
+ wait $SOCAT_PID
+ trap - TERM INT
+ wait $SOCAT_PID
+ SOCAT_RET=$?
+
+ if [ $SOCAT_RET -eq 0 ]; then
+ log_begin_msg "Connection lost. Epoptes-client reconnecting to $SERVER:$PORT..."
+ else
+ log_begin_msg "WARNING: socat exited with unexpected code $SOCAT_RET. Epoptes-client reconnecting to $SERVER:$PORT..."
+ fi
+ done
+else
+ exec socat ${SOCAT_PREFIX}:${SERVER}:${PORT}${SOCAT_CERT},interval=60,forever EXEC:"$cmdline"${SOCAT_SUFFIX}
fi
Follow ups