Skip to content

Commit 970161c

Browse files
committed
add nest-desktop wrapper-script
1 parent baa7748 commit 970161c

File tree

1 file changed

+105
-9
lines changed

1 file changed

+105
-9
lines changed
Lines changed: 105 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,109 @@
11
#!/bin/bash
22

3-
# you might need to modify your environment
4-
# before you can start 'nest-desktop'
5-
# Do it here.
3+
# extract file path
4+
extract_fpath() {
5+
local arg="$1"
6+
if [[ "$arg" == file:filename=* ]]; then
7+
nestsrv_auth_file="${arg#file:filename=}"
8+
fi
9+
}
610

7-
# example:
8-
# module purge
9-
# module load Stages/2023
10-
# module load GCCcore/.11.3.0
11-
# module load nest-desktop/3.2.0
11+
# Loop through the arguments
12+
nestsrv_start=false
13+
nestsrv_port=""
14+
nestsrv_auth_file=""
15+
nestsrv_logfile="/tmp/nest-server-$USER-$$.log"
16+
app_args=()
17+
while [[ $# -gt 0 ]]; do
18+
key="$1"
19+
case $key in
20+
--srv-start)
21+
shift
22+
nestsrv_start=true
23+
;;
24+
--srv-auth)
25+
shift
26+
extract_fpath "$1"
27+
shift
28+
;;
29+
--srv-port)
30+
shift
31+
nestsrv_port="$1"
32+
shift
33+
;;
34+
--srv-log)
35+
shift
36+
nestsrv_logfile="$1"
37+
shift
38+
;;
39+
*)
40+
app_args+=("$1")
41+
shift
42+
;;
43+
esac
44+
done
1245

13-
nest-desktop "$@"
46+
# Clean up
47+
nestsrv_pid=""
48+
cleanup() {
49+
if [ -n "$nestsrv_pid" ]; then
50+
kill "$nestsrv_pid"
51+
echo "NEST-Server with PID $nestsrv_pid killed."
52+
fi
53+
}
54+
trap cleanup INT TERM
55+
56+
# Load the modules
57+
<MODULES>
58+
59+
# Start nest-server
60+
if [ "$nestsrv_start" = true ]; then
61+
echo "NEST-Desktop: starting a NEST-Server"
62+
63+
# Set log-file
64+
if [ ! -z "$nestsrv_logfile" ]; then
65+
echo "NEST-Server: log-file = $nestsrv_logfile"
66+
else
67+
echo "NEST-Server: log-file (generated) = $nestsrv_logfile"
68+
$nestsrv_logfile=/tmp/nest-server-$USER-$$.log
69+
fi
70+
export NEST_SERVER_LOGFILE=$nestsrv_logfile
71+
touch $NEST_SERVER_LOGFILE
72+
chmod 600 $NEST_SERVER_LOGFILE
73+
74+
# Set port
75+
if [ ! -z "$nestsrv_port" ]; then
76+
echo "NEST-Server: port = $nestsrv_port"
77+
export NEST_SERVER_PORT=$nestsrv_port
78+
fi
79+
80+
# Set token
81+
if [ ! -z "$nestsrv_auth_file" ]; then
82+
echo "NEST-Server: auth-file = $nestsrv_auth_file"
83+
84+
export NEST_SERVER_DISABLE_AUTH=0
85+
if [ -e "$nestsrv_auth_file" ] && [ -r "$nestsrv_auth_file" ]; then
86+
export NEST_SERVER_ENABLE_EXEC_CALL=1
87+
export NEST_SERVER_DISABLE_RESTRICTION=1
88+
export NEST_SERVER_CORS_ORIGINS="http://localhost:*"
89+
export NEST_SERVER_ACCESS_TOKEN=$(cat $nestsrv_auth_file)
90+
else
91+
echo "NEST-Server: ERROR auth-file not readable. The server will NOT start."
92+
nestsrv_start=false
93+
fi
94+
fi
95+
96+
# Start NEST-Server
97+
if [ "$nestsrv_start" = true ]; then
98+
echo "NEST-Server: cmd = nest-server start -o > $NEST_SERVER_LOGFILE 2>&1"
99+
nest-server start -o >> $NEST_SERVER_LOGFILE 2>&1 &
100+
nestsrv_pid="$!"
101+
fi
102+
fi
103+
104+
# Start NEST-Desktop
105+
echo "NEST-Desktop: cmd = nest-desktop ${app_args[@]}"
106+
nest-desktop "${app_args[@]}"
107+
108+
# Cleanup on finish
109+
cleanup

0 commit comments

Comments
 (0)