File size: 1,065 Bytes
1aeabca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8da962
 
 
 
 
 
 
 
 
1aeabca
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash

list_descendants()
{
  local children=$(ps -o pid= --ppid "$1")
  for pid in $children
  do
    list_descendants "$pid"
  done
  echo "$children"
}

kill_descendants()
{
    kill $(list_descendants $$) >/dev/null 2>&1
}

trap 'kill_descendants' KILL INT TERM EXIT # just a precaution to not to keep anything running

# kill previous instance of this script, if running
script_name=${BASH_SOURCE[0]}
for pid in $(pidof -x $script_name); do
    if [ $pid != $$ ]; then
        echo "Killing previous instance of this script ($script_name)"
        kill $pid
        sleep 5
    fi 
done

# run
echo "Starting MCU Proxy with arguments: '$@'..."
cd "$(dirname "$0")"
cd ..
ENTRY_POINT=./SLS4All.Compact.McuApp
# enable listening on ports below 1024
# enable changing time
# enable core dumping
# enable priorities and nice
sudo setcap 'cap_sys_ptrace,cap_sys_admin,cap_net_bind_service,cap_sys_time,cap_sys_nice=+eip' $ENTRY_POINT
# start in FIFO scheduler
sudo chmod +x $ENTRY_POINT
chrt --fifo 90 $ENTRY_POINT $@ &

echo "Waiting for exit signal..."
wait