Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / tools / service_launcher.sh
blob4c74b61d50854d75cb81536582385c23103e4ad7
1 #!/bin/bash
2 # ______ _____ _ _ _____ _
3 # | ___ \ / ___| | | | |_ _| | |
4 # | |_/ / _ _______ _ __ ___ \ `--.| |__ __ _ _ __ __| | | | ___ ___ | |___
5 # | / | | |_ / _ \| '_ ` _ \ `--. \ '_ \ / _` | '__/ _` | | |/ _ \ / _ \| / __|
6 # | |\ \ |_| |/ / (_) | | | | | | /\__/ / | | | (_| | | | (_| | | | (_) | (_) | \__ \
7 # \_| \_\__, /___\___/|_| |_| |_| \____/|_| |_|\__,_|_| \__,_| \_/\___/ \___/|_|___/
8 # __/ |
9 # |___/
11 # Ryzom - MMORPG Framework <https://ryzom.com/dev/>
12 # Copyright (C) 2019 Winch Gate Property Limited
13 # This program is free software: read https://ryzom.com/dev/copying.html for more details
15 # This script is a service launcher that works with a command file
16 # to determine when to launch the application that it is responsible for
19 CWD=$(dirname "$0")
20 . "$CWD/config.sh"
22 NAME="$1"
23 shift
25 EXECUTABLE=$1
26 shift
28 CTRL_CMDLINE=$*
30 mkdir -p $NAME
32 DOMAIN=shard
33 NAME_BASE="$NAME/$NAME"
34 CTRL_FILE=${NAME_BASE}_immediate.launch_ctrl
35 NEXT_CTRL_FILE=${NAME_BASE}_waiting.launch_ctrl
36 STATE_FILE=${NAME_BASE}.state
37 START_COUNTER_FILE=${NAME_BASE}.start_count
39 echo
40 echo ---------------------------------------------------------------------------------
41 echo Starting service launcher
42 echo ---------------------------------------------------------------------------------
43 printf "%-16s = " CMDLINE ; echo $CTRL_CMDLINE
44 printf "%-16s = " CTRL_FILE ; echo $CTRL_FILE
45 printf "%-16s = " NEXT_CTRL_FILE ; echo $NEXT_CTRL_FILE
46 printf "%-16s = " STATE_FILE ; echo $STATE_FILE
47 echo ---------------------------------------------------------------------------------
48 echo
50 # reinit the start counter
51 echo 0 > $START_COUNTER_FILE
52 START_COUNTER=0
54 while true
56 # see if the conditions are right to launch the app
57 if [ -e $CTRL_FILE ]
58 then
60 # a control file exists so read it's contents
61 CTRL_COMMAND=_$(cat $CTRL_FILE)_
63 # do we have a 'launch' command?
64 if [ $CTRL_COMMAND = _LAUNCH_ ]
65 then
67 # update the start counter
68 START_COUNTER=$(( $START_COUNTER + 1 ))
69 echo $START_COUNTER > $START_COUNTER_FILE
71 # we have a launch command so prepare, launch, wait for exit and do the housekeeping
72 echo -----------------------------------------------------------------------
73 echo Launching $(pwd) $EXECUTABLE $CTRL_CMDLINE...
74 echo
75 printf RUNNING > $STATE_FILE
78 #notify start
79 if [ "$NAME" = "egs" ] || [ "$NAME" = "ios" ] || [ "$NAME" = "gpms" ]
80 then
81 sleep 2
82 elif [ "$NAME" = "ais_fyros" ] || [ "$NAME" = "ais_matis" ] || [ "$NAME" = "ais_tryker" ] || [ "$NAME" = "ais_roots" ] || [ "$NAME" = "ais_zorai" ] || [ "$NAME" = "ais_ark" ]
83 then
84 sleep 4
87 echo "notifying $CWD/notify.sh ServiceStarted $NAME"
88 "$CWD/notify.sh" ServiceStarted $NAME
90 export LC_ALL=C; unset LANGUAGE
92 if [[ "$USE_GDB" == "1" ]]
93 then
94 if [ "$NAME" = "egs" ] || [ "$NAME" = "ios" ] || [ "$NAME" = "ais_fyros" ] || [ "$NAME" = "ais_matis" ] || [ "$NAME" = "ais_tryker" ] || [ "$NAME" = "ais_roots" ] || [ "$NAME" = "ais_zorai" ] || [ "$NAME" = "ais_ark" ] || [ "$NAME" = "gpms" ]
95 then
96 echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SHARD_PATH/lib gdb -batch -ex 'set logging file $NAME/gdb_dump.txt' -ex 'set logging on' -ex 'run $CTRL_CMDLINE' -ex 'bt' $EXECUTABLE" > /tmp/run_$NAME
97 else
98 echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SHARD_PATH/lib $EXECUTABLE $CTRL_CMDLINE" > /tmp/run_$NAME
101 else
102 echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SHARD_PATH/lib $EXECUTABLE $CTRL_CMDLINE" > /tmp/run_$NAME
105 schroot -p -c atys -- sh /tmp/run_$NAME
106 #notify stop
107 "$CWD/notify.sh" ServiceStopped $NAME
109 echo -----------------------------------------------------------------------
110 printf STOPPED > $STATE_FILE
112 # consume (remove) the control file to allow start once
113 rm $CTRL_FILE
115 if [[ "$AUTO_RESTART" == "0" ]]
116 then
117 echo "Press ENTER to relaunch"
118 read
123 # either we haven't launched the app yet or we have launched and it has exitted
124 if [ -e $NEXT_CTRL_FILE ]
125 then
126 # we have some kind of relaunch directive lined up so deal with it
127 mv $NEXT_CTRL_FILE $CTRL_FILE
128 else
129 # automatic launch
130 printf LAUNCH > $CTRL_FILE
132 done