timvisee / lazymc

💤 Put your Minecraft server to rest when idle.
GNU General Public License v3.0
579 stars 16 forks source link

Config option to use `SIGSTOP` and `SIGCONT` to freeze and unfreeze server instead of restarting #37

Closed obj-obj closed 1 year ago

obj-obj commented 1 year ago

Works on https://github.com/timvisee/lazymc/issues/7

obj-obj commented 1 year ago

Not even close to being done but im putting it here anyway

obj-obj commented 1 year ago

Hmm that was surprisingly easy, the code works now at least on my machine Only step left is to add a config option, I'll do that later

obj-obj commented 1 year ago

This is so good when the server is configured to sleep after only 1 second of inactivity It feels like the server is always on because there's no lag when joining the game, the process instantly gets resumed

timvisee commented 1 year ago

Thanks a lot for this! I'll take a look at this later as I'm currently on holiday.

Maybe the unsafe bits can be removed by using the nix crate.

obj-obj commented 1 year ago

Yeah using the nix crate is cleaner and I was able to get rid of the entire unix.rs file

obj-obj commented 1 year ago

Code worked first try, no way

obj-obj commented 1 year ago

@timvisee it's ready now with a config option (defaults to true), review it whenever you have time

obj-obj commented 1 year ago

Oh wait I didn't add a check to make sure the system is running on unix before defaulting to true so it would be broken by default on windows

Okazakee commented 1 year ago

Hope this gets seen, it's been a while since the last update

timvisee commented 1 year ago

Sorry once again for the delay. I promise to give this a proper check ASAP!

Okazakee commented 1 year ago

Sorry once again for the delay. I promise to give this a proper check ASAP!

Obviously I do not want to press you mister, your work is incredible, I am just a big fan of lazymc, it is a true relief for SBCs, and my main "selling point" for my project ahahahah

obj-obj commented 1 year ago

Thanks a lot for your work on this! You've made some great changes and improvements.

You enable freeing by default. I do prefer having it disabled by default though. Freezing would still waste memory, whereas freeing this by shutting down was one of the selling points of this projects. What do you think of this, what made you enable by default? What do others think?

I've added some review comments. Don't worry, you did a fantastic job. Those are mostly nitpicks. Are you fine by looking into them to make the appropriate changes? I'd also be happy to do it for you.

I enabled it by default because I thought that most people would want it enabled by default. It does waste more memory, but I'm personally using this project to make the computer that's running the minecraft server to idle at lower wattage (minecraft uses 15% of a thread doing nothing when no players are online, even if the server isn't ticking, and it made the server idle 20W higher for some reason)

I didn't really consider ram usage until now, maybe we should do a poll or something?

obj-obj commented 1 year ago

Also another thing that we might need to do - if you set the sleep timeout to a really small value, like 1 second, while clients are on a slow connection

lazymc will detect the connection, start the server, and then put the server back to sleep if it takes more than 1 second for the client to join the server

timvisee commented 1 year ago

Also another thing that we might need to do - if you set the sleep timeout to a really small value, like 1 second, while clients are on a slow connection

A minimum online time (for the server) can be configured here to prevent this:

https://github.com/timvisee/lazymc/blob/5f13132c57b1ec3cf4d695c072c5eac81bd167af/res/lazymc.toml#L72-L73

obj-obj commented 1 year ago

Also another thing that we might need to do - if you set the sleep timeout to a really small value, like 1 second, while clients are on a slow connection

A minimum online time (for the server) can be configured here to prevent this:

https://github.com/timvisee/lazymc/blob/5f13132c57b1ec3cf4d695c072c5eac81bd167af/res/lazymc.toml#L72-L73

Ah, I didn't see that option

obj-obj commented 1 year ago

Maybe we should make it default to 30 seconds (same as the minecraft client timeout) if freezing the process is also enables?

timvisee commented 1 year ago

Did some testing today. Works perfectly! It instantly resumes, that's awesome. :rocket:

I did found one problem though. When rcon.enabled = true lazymc shuts down the server through rcon rather than freezing the process. It seems rcon has priority over freezing the process. I'll be able to patch that later today or tomorrow.

On second thought, I'm happy to keep freeze_process enabled by default.

Okazakee commented 1 year ago

Nice to read that, hope to see the new release soon, I'm so much hyped, I don't even play Minecraft anymore, but it's just a playground for devs

timvisee commented 1 year ago

I'll implement the required changes to merge this now.

timvisee commented 1 year ago

I've released v0.2.8 which includes this feature.

obj-obj commented 1 year ago

@timvisee how do you get the repository to mirror with ci status from gitlab? I might do that so I can develop on gitlab but still have the project visible on github

timvisee commented 1 year ago

You can enable repository mirroring in GitLab (Repository -> Settings -> Repository -> Mirroring repository).

To add the GitLab CI status to your GitHub commits, enable the GitHub integration over on GitLab (Repository -> Settings -> Integrations -> GitHub).

obj-obj commented 1 year ago

You can enable repository mirroring in GitLab (Repository -> Settings -> Repository -> Mirroring repository).

To add the GitLab CI status to your GitHub commits, enable the GitHub integration over on GitLab (Repository -> Settings -> Integrations -> GitHub).

Oh thanks, that integration was the step I was missing

Edit: premium only :(

timvisee commented 1 year ago

Edit: premium only :(

That's a bummer! Maybe I enabled it before this became a premium feature.

obj-obj commented 1 year ago

@timvisee They just gave me ultimate after filling out a form and giving a screenshot of my license

Aint no way 💀