How to monitor/revive a process in linux?

Place blocks, run from skeletons
zel
Elite Member
Elite Member
 
Posts: 2442
Joined: Wed Dec 31, 1969 8:00 pm
Location: Naples, FL

How to monitor/revive a process in linux?

Postby zel on Thu Dec 16, 2010 1:58 pm

So for some crazy reason the MC My Admin on the server just dies. Now it has built in server process crash detection and restart but that only applies if it is only the minecraft server process and not the minecraft my admin process as well. Soooooo anyone good with linux know how to make a script that will check for the mcmyadmin process and restart it if it isn't there with the "screen ./start.sh" command? i dunno wtf "screen" does, apparently it runs something in a background so when you log out it doesn't go poof!

PCMILPH
 
Posts: 1591
Joined: Wed Dec 31, 1969 8:00 pm
Location: Washington, DC
if you do a show of the running procs and | that to a grep for the minecraft admin processs name you should be able to make a condition of some kind for a script, I dont know much about linux scripting but i would imagine it wouldnt be hard if i had access to it. I know rhys has been fucking around w linux so he might be better suited.

BlueSix
Elite Member
Elite Member
 
Posts: 2511
Joined: Wed Dec 31, 1969 8:00 pm
Location: Saint Pete, FL.gif
PCMILPH wrote:I know rhys has been fucking around w linux so he might be better suited.

Challenge accepted.

BlueSix
Elite Member
Elite Member
 
Posts: 2511
Joined: Wed Dec 31, 1969 8:00 pm
Location: Saint Pete, FL.gif
I'm still pretty noob but this seems to work for me:
Code: Select all
isrunning=$(ps -A | grep -c gedit)
if [ $isrunning = 0 ]; then gedit; else echo Process already running...; fi


Change gedit in both lines to mcmyadmin or whatever the process is you are looking for. If the process is running but hung, this won't do anything, but it doesn't sound like that's your problem. Let me know.

Edit: looks like this dies if you close the terminal it was run with - so prepend the command with 'screen ' which I believe will allow it to stay alive (I think you already know this but just in case).

BlueSix
Elite Member
Elite Member
 
Posts: 2511
Joined: Wed Dec 31, 1969 8:00 pm
Location: Saint Pete, FL.gif
Update - Getting closer to a workable script that will auto-run when it crashes.

Code: Select all
#!/bin/sh

sleeptime=10      # seconds to sleep
process="gedit"      # target process

while true;      # loop forever
do
   isrunning=$(ps ax | grep -v grep | grep -c $process)
   if [ $isrunning = 0 ]
      then
         echo Restarting $process...
         $process&
   else
      echo $process is already running...
   fi
sleep $sleeptime

done

zel
Elite Member
Elite Member
 
Posts: 2442
Joined: Wed Dec 31, 1969 8:00 pm
Location: Naples, FL

Re: How to monitor/revive a process in linux?

Postby zel on Fri Dec 17, 2010 10:49 am

sweet :) getting tired of that thing dying

buzz
Site Admin
Site Admin
 
Posts: 6307
Joined: Fri Nov 08, 2002 2:01 am
Location: Omicron Percei 8 .gif

Re: How to monitor/revive a process in linux?

Postby buzz on Fri Dec 17, 2010 12:28 pm

You could setup a cron job to start every 5 or 10 mins that runs Rhys' script to check if the proc is running. That might be better then running screen

PCMILPH
 
Posts: 1591
Joined: Wed Dec 31, 1969 8:00 pm
Location: Washington, DC

Re: How to monitor/revive a process in linux?

Postby PCMILPH on Fri Dec 17, 2010 12:57 pm

cant you also just tell it to run in the background with -z or w/e the command is?


Return to Minecraft

Who is online

Users browsing this forum: No registered users and 1 guest

cron