0

I have a game server. It runs on linux via dotnet. I run this inside a 'screen' session. However I am struggling with restarting this server. From outside, it is easy. I just kill existing screen via name and create new one. However when I want to restart server from inside (existing game process starts new process that runs script that kills named screen and starts new one)

To be specific:

stop.sh:

screen -r gameserver -X quit

start.sh:

screen -L -A -m -d -S gameserver /usr/bin/dotnet /gameserver/game.dll

restart.sh:

/gameserver/stop.sh
/gameserver/start.sh

Now If I run restart.sh programmatically from inside screen, it calls stop.sh, which terminates current screen and also this restart.sh script, so the new one is not started.

I tried to run restart.sh via screen:

screen -L -m -d /bin/bash -c /gameserver/restart.sh

But it still doesn't work... I would expect this to run restart.sh in new screen, where the 'gameserver' screen will terminate and start new one and after that screen running restart.sh will stop. But no :(

Any ideas?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Jacob
  • 627
  • 6
  • 15

2 Answers2

0

Cant you just kill this process inside the screen? Something like

screen -r gameserver kill $(ps aux|grep 'game.dll'|awk '{print $2}') ?

Igor Zilberman
  • 1,048
  • 1
  • 11
  • 16
0

I think you probably should NOT run such a script inside screen. Kill the whole session then re-create it inside screen is kind of weird.

And in your script stop.sh, though using -r with -X may sometime work, it doesn't make much sense. I think you should use -S instead of -r.

Run outside screen:

If you replace stop.sh with screen -S gameserver -X quit, and run restart.sh outside screen, it should work.

Run inside screen:

However, if you really need to run it inside screen, you could try to kill a window instead of terminate the whole session.

stop.sh:

# Create a new window before kill 'server'
# Without this, the session will be terminated if 'server' is the only window
screen
screen -p server -X kill

start.sh:

# Are we in the 'gameserver' session?
if [ "${STY#*.}" = gameserver ]; then
    # Create a window named 'server' and run your program in it
    screen -t server /usr/bin/dotnet /gameserver/game.dll
else
    # Create a new screen session named 'gameserver' 
    # And it's default window is named 'server'
    # -T $TERM to make sure things such as '-t' work
    screen -L -A -m -d -S gameserver -t server -T $TERM /usr/bin/dotnet /gameserver/game.dll
fi
alzee
  • 463
  • 2
  • 10