Skip to content

Add automatic crash detection and restarts#271

Closed
michael2847 wants to merge 7 commits intoMinecraftServerControl:mainfrom
michael2847:main
Closed

Add automatic crash detection and restarts#271
michael2847 wants to merge 7 commits intoMinecraftServerControl:mainfrom
michael2847:main

Conversation

@michael2847
Copy link
Member

Hi,

This is an updated PR from #257 : New changes:

  • Updated the code to reflect the most recent codebase
  • Changed the default setting to now being disabled
  • Changed the name of the flag (from mscs-enable-restart-after-crash to mscs-restart-after-crash) for brevity
  • Added the ability to set it on a per world basis (mscs-default-restart-after-crash and mscs-restart-after-crash)
  • Changed the flags from 0/1 to false/true for clarity's sake
  • Removed the old changes I made (in the if statements when trying to test if the server was running) that made the code less readable, and reverted it back to how the old way was done
  • Updated the copyright year ;)

I still need to figure out if there's a way to check if there's a server monitor process running without using flock (which the code uses right now). As I mentioned in the last PR, I tried using the createLockFile() function that's in the script but it didn't work for me for some reason.

Probably should also test it a bit more. It does seem to be working as intended on my computer, though!

Thanks

@sandain
Copy link
Member

sandain commented Dec 31, 2020

Thanks for the new PR @Roflicide. This looks much better!

I had to rebuild my server a month ago due to a failed drive, and haven't yet installed MSCS (I haven't even played Minecraft in what seems like years). I'll try to make some time soon to give this a try. If @zanix or anyone else has the chance to test this out, and approves it before I get the chance, feel free to merge the PR.

Copy link
Member

@zanix zanix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also make a PR for the documentation to add the new mscs setting options?

Copy link
Member Author

@michael2847 michael2847 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @zanix, thanks for leaving some feedback. I believe I've fixed all of your requested edits with the exception of the added white space, as I think it's necessary it since the mscs-default-restart-after-crash variable is so long. let me know if you find anything else

thanks!

@sandain
Copy link
Member

sandain commented Jan 24, 2021

What is the status of this PR? Has anyone been able to test it? I don't have time right now (switching jobs, moving to a new state, etc). The only change request I see is to add documentation for the new options..

Integration with my PR #274 can come before or after this PR as far as I'm concerned..

@zanix
Copy link
Member

zanix commented Jan 24, 2021

I haven't had time to test this, and @Roflicide still need to make a couple changes.

Copy link
Member Author

@michael2847 michael2847 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think ive made all the changes requested, just gotta update the docs and good to go!

@michael2847
Copy link
Member Author

Just updated the docs! also, i learned today that flock is part of the util-linux package, which is a standard linux package shipped with all linux distros, so i think most people should already have it! but i've updated the install instructions just in case.

anyone else is welcome to do more testing with this PR if they'd like! i'd probably like to do a little more testing, but also good to merge too.

Copy link
Member

@zanix zanix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change those calls to flock with $FLOCK

michael2847 and others added 2 commits February 5, 2021 21:37
Co-authored-by: Joshua Clark <1580378+zanix@users.noreply.github.com>
Co-authored-by: Joshua Clark <1580378+zanix@users.noreply.github.com>
@michael2847
Copy link
Member Author

Change those calls to flock with $FLOCK

thanks for the catch, fixed!

@michael2847 michael2847 requested a review from zanix February 6, 2021 02:38
@sandain
Copy link
Member

sandain commented Mar 8, 2021

Sorry all, I moved across the country and don't currently have my server setup for testing purposes. Has this been tested? Is it now ready to merge?

@zanix
Copy link
Member

zanix commented Mar 16, 2021

Hey @Roflicide, this needs a rebase

Copy link
Member

@sandain sandain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Roflicide, I left a few minor comments. Once you rebase and fix these remaining minor issues, I'll merge this PR. Thanks for all the work.

# Nohup does not allow you to pass functions. However, the code below mimics nohup behavior by doing the following:
# Start subshell, ignore HUP signal, redirect stdin to /dev/null, redirect stdout and stderr to log file, run in background.
# Also store the PID of this process for later use.
( trap "true" HUP ; pid=$(exec sh -c 'echo "$PPID"'); echo $pid > "$MONITOR_PID"; serverMonitor $1 ) </dev/null 2>&1 1>>"$MONITOR_LOG" &
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this "true" value used anywhere? Could this be changed to:

trap "" HUP;

I'm not really familiar with trap, but my reading of the docs leads me to believe that you don't need the "true" value.

Rather than creating the temporary variable $pid, could the second bit be shortened to:

echo $(exec sh -c 'echo "$PPID"') > "$MONITOR_PID";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching these, shortening them worked!

@michael2847
Copy link
Member Author

Thanks for reviewing @sandain @zanix , going to re-open this as a new PR as I accidently deleted the old fork (but I still have the code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants