Jump to content

  • Curse Sites
Become a Premium Member! Help
Latest News Article

server restart?


  • Please log in to reply
7 replies to this topic

#1

kalixxx
    kalixxx

    Tree Puncher

  • Members
  • 12 posts

Posted 27 April 2011 - 12:47 AM

is there any way to automatically restart a server if it crashes, disconnected, stupidly closed?  

other people use the computer so they some time restart it  or something

Register or log in to remove.

#2

rch
    rch

    Minecraft.cm

  • Members
  • 4104 posts
  • Location: Florida
  • Minecraft: rch

Posted 27 April 2011 - 12:54 AM

McMyAdmin has options to restart the server at certain timed intervals or when there is a crash.. but I don't believe it will restart it if it is properly shut down. Can't you just tell the other folks in your home to not shut down Minecraft?

#3

TheYeti
    TheYeti

    Tree Puncher

  • Curse Premium
  • Curse Premium
  • 21 posts
  • Location: Beaverton, OR

Posted 27 April 2011 - 12:59 AM

Would be helpful to know if this is a linux server or a Windows server.  It can be done on both, it's just easier to do on linux with a cronjob and an init script.
Posted Image

My Website    |    Server Forums    |    My Twitter    |    Server Twitter

#4

kalixxx
    kalixxx

    Tree Puncher

  • Members
  • 12 posts

Posted 27 April 2011 - 01:20 AM

its win7. and sadly not server ....

and you try to explain to your parents for the 5th time not to close that shiny minecraft tab on there taskbar!

#5

frogger4

Posted 29 April 2011 - 03:59 AM

I was wondering a similar thing. I'm looking for a way to have the server automatically restart at given intervals (and maybe not using mcadmin, since its a bukkit server). I'm using a mac, so the server set up is much like linux, if that helps.
Any ideas are appreciated!

#6

JohnTheRipper
  • Location: ::1

Posted 29 April 2011 - 04:07 AM

http://forums.bukkit... ... e-733.674/

/endofthread
i7-3770K @ 4.5GHz, Hyper 212 Evo, 16GB 1600MHz RAM, Z77X-UD5H, GTX 670 OC, 256GB 840 Pro, 2TB + 500GB HDDs, Fractal R4, HX750 (with bonus fan noise), Dell U2713HM.

Please read the rules!
Global | Discussion | MnM | Other Platforms | Servers | Support | SyC | Off Topic
“Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.” — Albert Einstein
"Never try to teach a pig to sing; it wastes your time and it annoys the pig." — Robert Heinlein

Posted Image


#7

rch
    rch

    Minecraft.cm

  • Members
  • 4104 posts
  • Location: Florida
  • Minecraft: rch

Posted 29 April 2011 - 04:21 AM

I just coded this up as a quick example, if you're familiar with bash scripting at all you can adjust it to fit your needs, but bash is pretty simple and I'm sure you'll have few troubles with it.

First, this is the startup script start.sh
#!/bin/sh
screen -md -S mc java -jar -Xms1024M -Xmx1024M minecraft_server.jar nogui

The -md flag starts the screen in 'detached' mode, meaning it wont come up on the Terminal window, but you can view it with 'screen -r' or 'screen -ls'

screen manual said:

-d -m   Start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.

The -S flag gives the screen a 'session' name/id - in this case 'mc', which is necessary for the next script to send data to the proper screen.

screen manual said:

-S sessionname
            When  creating  a  new  session,  this  option  can be used to specify a meaningful name for the session. This name identifies the session for "screen -list" and "screen -r" actions. It substitutes the default [tty.host] suffix

So now when you call the startup script, you'll no longer have to type, for example:
screen ./start.sh
You would simply start it with:
./start.sh

Next is the restarter script.. for this example I only set it to a 20 second 'warning' notice for the players, it will send text to the game from '[Console]' telling the users the server is restarting, the countdown starts at 20 seconds, then 15, then 10, then 5, 4, 3, 2 then the restart begins. It does a 'save-all' and then does a 'stop' command, I only put the save-all in there as a precaution, it's not usually necessary since the 'stop' command does a save prior to exiting the server, but it doesn't hurt either. Then it will pause for about 10 seconds to let the server stop completely and exit and runs your start.sh script again to bring the server back online.

The restart code/script restart.sh
#!/bin/sh
screen -S mc -p 0 -X stuff "`printf "say Server is restarting in 20 seconds!\r"`";
sleep 5
screen -S mc -p 0 -X stuff "`printf "say Server is restarting in 15 seconds!\r"`";
sleep 5
screen -S mc -p 0 -X stuff "`printf "say Server is restarting in 10 seconds!\r"`";
sleep 5
screen -S mc -p 0 -X stuff "`printf "say Server is restarting in 5 seconds!\r"`";
sleep 1
screen -S mc -p 0 -X stuff "`printf "say Server is restarting in 4 seconds!\r"`";
sleep 1
screen -S mc -p 0 -X stuff "`printf "say Server is restarting in 3 seconds!\r"`";
sleep 1
screen -S mc -p 0 -X stuff "`printf "say Server is restarting in 2 seconds!\r"`";
sleep 1
screen -S mc -p 0 -X stuff "`printf "say Server is restarting now!\r"`";
sleep 1
screen -S mc -p 0 -X stuff "`printf "save-all\r"`";
screen -S mc -p 0 -X stuff "`printf "stop\r"`";
sleep 10
./start.sh

Place both of these in your server directory, adjust the startup script as necessary for your RAM allotment or Craftbukkit jar, or if you want to add your own custom flags to the Java startup... then you'd set up a cron job to run every X minutes/hours, whatever to run the 'restart.sh' script. You can find instructions on how to use crontab in OSX here: http://benr75.com/pa... ... unix_linux

Best of luck!

#8

frogger4

Posted 29 April 2011 - 04:44 AM

awesome thanks guys, thats what I was looking for  ^_^