Jump to content

detecting an empty server via a script


Recommended Posts

I recently setup a private dedicated server in Linux running on an Amazon EC2 virtual machine.  In an attempt to reduce costs, I'd like to be able to detect when the server is empty so I can automatically shutdown the VM via a script.

 

Is there a way to detect when the DST server is empty?  I've looked at the output from dontstarve_dedicated_server_nullrenderer and did not see anything useful.  I have pause_when_empty set to true, but there was also no indication when the sim paused.

 

Any help is appreciated.

 

--
firedfly

 
Link to comment
Share on other sites

You can do this with mods!

 

For example:

Put pause_when_empty on false. Put this mod on your server.

 

This works like this:

1) When a new day starts, it checks the server for players.

2) If no players are found, it will check again 10 seconds later.

3) If no players are found again, the server will save and shutdown.

 

If you want to check after two days instead of one, you would need to replace the WatchWorldState for a DoPeriodicTask(2*480, ...).

 

Shutdown.zip

Link to comment
Share on other sites

@rezecib - I had thought of keeping track of connect/disconnects, but that seems like it could be error prone.  e.g. what is the behavior if a client times out (client-side) and reconnects before the server is aware of the time out?  That may not be an issue, but things like that could cause the counts to be off.

 

@DarkXero - I hadn't considered a mod. Thanks for the suggestion.  I really like the pause_when_empty feature and would ideally have the sim paused for 20-30 minutes before I shutdown the VM.  Do you know if scripts/mods will still run when the sim is paused?  I would assume mods would not.  However, I'm not sure if the built-in scripts would.  I'll play around with this and see if I can figure anything out.

 

 

Thanks to both of you for offering suggestions!

Link to comment
Share on other sites

I've created a mod that will write to the log.txt when the server is empty.  I tried testing to see if any LUA code would run after the server was empty (and the sim paused), but my brief testing shows that all of the LUA code is paused as well.  For now, I'll plan on using my EmptyServer mod to write the entries into the log so I can have another process/script detect the empty server and shutdown the VM after a period of time.

 

If you are interested, the mod is attached and sample output is below:

[EmptyServer] The server is occupied[Load] SPAWNING PLAYER AT: (137.61, 0.00, -6.37)[Announcement] firedfly has joined the game.[Announcement] firedfly has left the game.[EmptyServer] The server is now emptyID_CONNECTION_LOST <ip address and port removed>

EmptyServer.zip

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...