summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/getconfig.sh6
-rwxr-xr-xtools/plopcontrol.py35
2 files changed, 38 insertions, 3 deletions
diff --git a/tools/getconfig.sh b/tools/getconfig.sh
index 9b75ce9..2ce9be3 100755
--- a/tools/getconfig.sh
+++ b/tools/getconfig.sh
@@ -15,7 +15,7 @@ plopcontrolport=
configversion="unknown"
if [ "${plopcontrolfile}" != "force-compile" -a -f ${plopcontrolfile} ]; then
plopcontrolport=$(cat ${plopcontrolfile})
- configversion=$(echo "configversion" | nc 127.0.0.1 ${plopcontrolport} || echo unreachable)
+ configversion=$($BINDIR/plopcontrol.py ${plopcontrolfile} "configversion" || echo unreachable)
fi
echo "version before reload: $configversion"
@@ -23,12 +23,12 @@ getconfigresult=$(${BINDIR}/getconfig.py --localconfig ${localconfig} --dest ${g
if [ "${plopcontrolfile}" = "force-compile" -o "$getconfigresult" = "newconfig" ]; then
${BINDIR}/compileconfig.py --localconfig ${localconfig} --config ${globalconfig}
if [ "${plopcontrolport}" != "" ]; then
- reloadresult=$(echo "reload" | nc 127.0.0.1 ${plopcontrolport} || echo unreachable)
+ reloadresult=$($BINDIR/plopcontrol.py ${plopcontrolfile} "reload" || echo unreachable)
echo $reloadresult
if [ "$reloadresult" != "reload completed" ]; then
exit 1
fi
- configversion=$(echo "configversion" | nc 127.0.0.1 ${plopcontrolport} || echo unreachable)
+ configversion=$($BINDIR/plopcontrol.py ${plopcontrolfile} "configversion" || echo unreachable)
echo "version after reload: $configversion"
fi
else
diff --git a/tools/plopcontrol.py b/tools/plopcontrol.py
new file mode 100755
index 0000000..295f311
--- /dev/null
+++ b/tools/plopcontrol.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2017, NORDUnet A/S.
+# See LICENSE for licensing information.
+
+import socket
+import sys
+import signal
+
+def send_message(plopcontrolfile, message):
+ plopcontrolport = int(open(plopcontrolfile).read())
+ print >>sys.stderr, "plopcontrolport", plopcontrolport
+ s = socket.socket(socket.AF_INET)
+ print >>sys.stderr, "opened socket"
+ s.connect(("127.0.0.1", plopcontrolport))
+ print >>sys.stderr, "connected, sending message", message
+ s.sendall(message + "\n")
+ print >>sys.stderr, "sent message"
+ data = ""
+ while "\n" not in data:
+ data = data + s.recv(1024)
+ print >>sys.stderr, "received data"
+ data = data.rstrip("\n")
+ print >>sys.stderr, "received all data"
+ s.close()
+ return data
+
+def main():
+ signal.alarm(5)
+ reply = send_message(sys.argv[1], sys.argv[2])
+ print reply
+
+if __name__ == '__main__':
+ main()