Merge branch 'ryzom/rites' into main/gingo-test
[ryzomcore.git] / ryzom / server / tools / service_launcher.sh
blob6040830aff4bf66b5b352d4b0d450b6088f9d1ce
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" == "ais_fyros" ]] || [[ "$NAME" == "ais_matis" ]] || [[ "$NAME" == "ais_tryker" ]] || [[ "$NAME" == "ais_roots" ]] || [[ "$NAME" == "ais_zorai" ]] || [[ "$NAME" == "ais_ark" ]]
80 then
81 touch "$SHARD_PATH/logs/ai_service_${NAME}.log"
82 "$CWD/wait_and_notify.sh" "$SHARD_PATH/logs/ai_service_${NAME}.log" "[[ARK]] AIS UP" $NAME 0 &
83 sleep 4
84 elif [[ "$NAME" == "egs" ]]
85 then
86 touch "$SHARD_PATH/logs/entities_game_service.log"
87 "$CWD/wait_and_notify.sh" "$SHARD_PATH/logs/entities_game_service.log" "onAiInstanceReady : AI Instance 1 is up" $NAME 0 &
88 sleep 2
89 elif [[ "$NAME" == "ios" ]]
90 then
91 touch "$SHARD_PATH/logs/input_output_service.log"
92 "$CWD/wait_and_notify.sh" "$SHARD_PATH/logs/input_output_service.log" "cbDynChatAddChan: add channel : FACTION_MARAUDER" $NAME 0 &
93 sleep 2
94 elif [[ "$NAME" == "gpms" ]]
95 then
96 touch "$SHARD_PATH/logs/gpm_service.log"
97 "$CWD/wait_and_notify.sh" "$SHARD_PATH/logs/gpm_service.log" "cbCreateIndoorUnit : MSG: Creating indoor unit 256" $NAME 0 &
98 sleep 2
99 else
100 declare -A ServiceLogs
101 ServiceLogs[aes] = "admin_executor_service.log"
102 ServiceLogs[bms_master] = "backup_service.log"
103 ServiceLogs[fes] = "frontend_service.log"
104 ServiceLogs[las] = "log_analyser_service.log"
105 ServiceLogs[lgs] = "logger_service.log"
106 ServiceLogs[mos] = "monitor_service.log"
107 ServiceLogs[ms] = "mirror_service.log"
108 ServiceLogs[ras] = "admin_service.log"
109 ServiceLogs[rns] = "naming_service.log"
110 ServiceLogs[rws] = "welcome_service.log"
111 ServiceLogs[sbs] = "session_browser_server.log"
112 ServiceLogs[su] = "shard_unifier_service.log"
113 ServiceLogs[ts] = "tick_service.log"
115 touch "$SHARD_PATH/logs/${ServiceLogs[$NAME]}"
116 "$CWD/wait_and_notify.sh" "$SHARD_PATH/logs/${ServiceLogs[$NAME]}" "SERVICE: Service ready" $NAME 2 &
119 export LC_ALL=C; unset LANGUAGE
121 if [[ "$USE_GDB" == "1" ]]
122 then
123 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" ]]
124 then
125 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
126 else
127 echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SHARD_PATH/lib $EXECUTABLE $CTRL_CMDLINE" > /tmp/run_$NAME
130 else
131 echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SHARD_PATH/lib $EXECUTABLE $CTRL_CMDLINE" > /tmp/run_$NAME
134 schroot -p -c atys -- sh /tmp/run_$NAME
135 #notify stop
136 "$CWD/notify.sh" ServiceStopped $NAME
138 echo -----------------------------------------------------------------------
139 printf STOPPED > $STATE_FILE
141 # consume (remove) the control file to allow start once
142 rm $CTRL_FILE
144 if [[ "$AUTO_RESTART" == "0" ]]
145 then
146 echo "Press ENTER to relaunch"
147 read
152 # either we haven't launched the app yet or we have launched and it has exitted
153 if [ -e $NEXT_CTRL_FILE ]
154 then
155 # we have some kind of relaunch directive lined up so deal with it
156 mv $NEXT_CTRL_FILE $CTRL_FILE
157 else
158 # automatic launch
159 printf LAUNCH > $CTRL_FILE
161 done