Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / tools / scripts / linux / service_launcher.sh
blob3be4af0128b547e3f798f37e84b85ad2e57e9991
1 #!/bin/sh
3 # the object is to make a launcher script that works with a command file to determine when to launch the application that it is responsible for
5 #DOMAIN=$(pwd |sed "s%/home/nevrax/%%" | sed "s%/.*%%")
6 DOMAIN=shard
7 #NAME_BASE=$(pwd | sed 's/\/home\/nevrax\///' | sed 's/^.*\///')
9 NAME_BASE="$1/$1"
10 mkdir $1
11 shift
13 #if [ _$DOMAIN == _pre_live ]
14 # then
15 CTRL_FILE=${NAME_BASE}.launch_ctrl
16 NEXT_CTRL_FILE=${NAME_BASE}.deferred_launch_ctrl
17 #elif [ _$DOMAIN == _pre_pre_live ]
18 # then
19 # CTRL_FILE=${NAME_BASE}.launch_ctrl
20 # NEXT_CTRL_FILE=${NAME_BASE}.deferred_launch_ctrl
21 #else
22 # CTRL_FILE=${NAME_BASE}_immediate.launch_ctrl
23 # NEXT_CTRL_FILE=${NAME_BASE}_waiting.launch_ctrl
24 #fi
25 STATE_FILE=${NAME_BASE}.state
26 START_COUNTER_FILE=${NAME_BASE}.start_count
27 CTRL_CMDLINE=$*
29 echo
30 echo ---------------------------------------------------------------------------------
31 echo Starting service launcher
32 echo ---------------------------------------------------------------------------------
33 printf "%-16s = " CMDLINE ; echo $CTRL_CMDLINE
34 printf "%-16s = " CTRL_FILE ; echo $CTRL_FILE
35 printf "%-16s = " NEXT_CTRL_FILE ; echo $NEXT_CTRL_FILE
36 printf "%-16s = " STATE_FILE ; echo $STATE_FILE
37 echo ---------------------------------------------------------------------------------
38 echo
40 # reinit the start counter
41 echo 0 > $START_COUNTER_FILE
42 START_COUNTER=0
44 echo Press ENTER to launch program
45 while true
48 # see if the conditions are right to launch the app
49 if [ -e $CTRL_FILE ]
50 then
52 # a control file exists so read it's contents
53 CTRL_COMMAND=_$(cat $CTRL_FILE)_
55 # do we have a 'launch' command?
56 if [ $CTRL_COMMAND = _LAUNCH_ ]
57 then
59 # update the start counter
60 START_COUNTER=$(( $START_COUNTER + 1 ))
61 echo $START_COUNTER > $START_COUNTER_FILE
63 # big nasty hack to deal with the special cases of ryzom_naming_service and ryzom_admin_service who have badly names cfg files
64 for f in ryzom_*cfg
66 cp $f $(echo $f | sed "s/ryzom_//")
67 done
69 # we have a launch command so prepare, launch, wait for exit and do the housekeeping
70 echo -----------------------------------------------------------------------
71 echo Launching ...
72 echo
73 printf RUNNING > $STATE_FILE
75 $CTRL_CMDLINE
77 echo -----------------------------------------------------------------------
78 printf STOPPED > $STATE_FILE
80 # consume (remove) the control file to allow start once
81 rm -f $CTRL_FILE
83 echo Press ENTER to relaunch
87 # either we haven't launched the app yet or we have launched and it has exitted
88 if [ -e $NEXT_CTRL_FILE ]
89 then
90 # we have some kind of relaunch directive lined up so deal with it
91 mv $NEXT_CTRL_FILE $CTRL_FILE
92 else
93 # give the terminal user a chance to press enter to provoke a re-launch when auto-relaunch in AES is disabled
94 HOLD=`sh -ic '{ read a; echo "ENTER" 1>&3; kill 0; } | { sleep 2; kill 0; }' 3>&1 2>/dev/null`
95 if [ "${HOLD}" = "ENTER" ]
96 then
97 printf LAUNCH > $CTRL_FILE
101 done