Merge branch 'ryzom/rites' into main/gingo-test
[ryzomcore.git] / ryzom / server / tools / shard
blob7cf19bd5f176fd7aa66a27ffd397eb463115eab5
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 helps to manage the shard using a screen session.
16 # You can start, join, stop and get state of services
19 CMD=$1
20 DOMAIN=shard
22 if [[ ! -z "$2" ]]
23 then
24 SHARD_PATH=$2
27 if [[ -z "$CMD" ]]
28 then
29 echo
30 echo Screen sessions currently running:
31 screen -list
32 echo
33 echo "Commands:"
34 echo " 'start' to start the ${DOMAIN}"
35 echo " 'stop' to stop the ${DOMAIN}"
36 echo " 'join' to join the ${DOMAIN}'s screen session"
37 echo " 'share' to join the ${DOMAIN} in shared mode"
38 echo " 'state' to view state information for the ${DOMAIN}"
39 echo
40 printf "Enter a command: "
41 read CMD
44 if [ "$CMD" = "stop" ]
45 then
46 if [ $(screen -list | grep \\\.${DOMAIN} | wc -l) != 1 ]
47 then
48 echo Cannot stop domain \'${DOMAIN}\' because no screen by that name appears to be running
49 screen -list
50 else
51 screen -d -r $(screen -list | grep \\\.${DOMAIN}| sed 's/(.*)//') -X quit > /dev/null
52 if [ -f $SHARD_PATH/run/aes_state.txt ]
53 then
54 rm -r $SHARD_PATH/run/*
59 STARTARGS=
60 if [ "$CMD" = "batchstart" ]
61 then
62 STARTARGS="-d -m"
63 CMD="start"
66 LIGHT=
67 if [ "$CMD" = "light" ]
68 then
69 LIGHT=".light"
70 CMD="start"
73 if [ "$CMD" = "start" ]
74 then
76 cd $SHARD_PATH/run
78 ulimit -c unlimited
79 screen -wipe > /dev/null
81 if [ $( screen -list | grep \\\.${DOMAIN} | wc -w ) != 0 ]
82 then
83 echo Cannot start domain \'${DOMAIN}\' because this domain is already started
84 screen -list | grep $DOMAIN
85 else
86 echo "Starting shard screen from $(pwd) with SHARD_PATH=$SHARD_PATH"
87 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SHARD_PATH/lib
88 export SHARD_PATH=$SHARD_PATH
89 screen $STARTARGS -S ${DOMAIN} -c $SHARD_PATH/tools/${DOMAIN}.screen${LIGHT}.rc
93 JOINARGS=
94 if [ "$CMD" = "share" ]
95 then
96 JOINARGS="-x"
97 CMD="join"
100 if [ "$CMD" = "join" ]
101 then
102 if [ $(screen -list | grep \\\.${DOMAIN} | wc -l) != 1 ]
103 then
104 echo Cannot join domain \'${DOMAIN}\' because no screen by that name appears to be running
105 screen -list
106 else
107 screen -r ${JOINARGS} $(screen -list | grep \\\.${DOMAIN}| sed 's/(.*)//')
111 if [ "$CMD" = "state" ]
112 then
113 cd $SHARD_PATH/run
114 echo State of domain ${DOMAIN}:
115 if [ $(echo */*.state) = "*/*.state" ]
116 then
117 echo - No state files found
118 else
119 grep RUNNING */*state