Extending pluggable arch for templates
[apps/app-templates.git] / template.d / start-on-target.sh.in
diff --git a/template.d/start-on-target.sh.in b/template.d/start-on-target.sh.in
new file mode 100755 (executable)
index 0000000..9e3a60d
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh
+# 
+# File:   start-on-target.sh
+# Author: Fulup Ar Foll @ IoT.bzh
+# Object: Forward signal (SIGTERM) to remote process
+# Created on 24-May-2017, 09:23:37
+# Usage: remote-target-populate update script under ./build directory
+
+# Do not change manually use 'make remote-target-populate'
+export RSYNC_TARGET=@RSYNC_TARGET@
+export PROJECT_NAME=@PROJECT_NAME@
+export RSYNC_PREFIX=@RSYNC_PREFIX@/@PROJECT_NAME@
+export AFB_REMPORT=@AFB_REMPORT@
+export AFB_TOKEN=@AFB_TOKEN@
+
+exec ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -tt $RSYNC_TARGET << EOF
+    afb-daemon --workdir=$RSYNC_PREFIX --port=$AFB_REMPORT --roothttp=./htdocs --ldpath=./lib --verbose --token=$AFB_TOKEN &
+    PID_DAEMON=\$!
+
+    trap "echo REMOTE-SIGNAL TRAP; kill -15 \$PID_DAEMON" INT QUIT TERM EXIT
+
+    # wait for daemon to finish
+    wait \$PID_DAEMON
+    exit
+EOF