Omnimaga

General Discussion => Other Discussions => Miscellaneous => Topic started by: helen on February 08, 2012, 05:10:20 pm

Title: How do I create a script that will restart another script after so many minutes?
Post by: helen on February 08, 2012, 05:10:20 pm
Okay I have OmnomIRC running in my channels which keeps closing now apparently it needs an auto restart script according to Nathem. How do I create one? I tried Googling but had no success what so ever. Is this in the wrong place or is there a better place for it?
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: Eeems on February 08, 2012, 08:00:43 pm
You could just do something like this:
Code: [Select]
p="process name"
while true; do
/path/to/process/to/run;
while [ "$(ps -C $p | grep $p)" != "" ]; do
sleep 3;
done;
done;
I haven't tested it but with some tweaking I'm pretty sure it should do what you want.
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: helen on February 09, 2012, 02:23:36 am
You could just do something like this:
Code: [Select]
p="process name"
while true; do
/path/to/process/to/run;
while [ "$(ps -C $p | grep $p)" != "" ]; do
sleep 3;
done;
done;
I haven't tested it but with some tweaking I'm pretty sure it should do what you want.

Okay I think it's working! :3 Okay sorry it's NOT working. :(
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: helen on February 09, 2012, 01:29:32 pm
You could just do something like this:
Code: [Select]
p="process name"
while true; do
/path/to/process/to/run;
while [ "$(ps -C $p | grep $p)" != "" ]; do
sleep 3;
done;
done;
I haven't tested it but with some tweaking I'm pretty sure it should do what you want.

Okay I think it's working! :3 Okay sorry it's NOT working. :( I can't find what the process would be.
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: Eeems on February 09, 2012, 02:07:27 pm
Well if I remember correctly it would probably be the name of the script/binary you are running. You could try changing it to ps -A instead, it's just less precise.
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: helen on February 09, 2012, 02:08:42 pm
Well if I remember correctly it would probably be the name of the script/binary you are running. You could try changing it to ps -A instead, it's just less precise.
I've tried looking through ps -A in the past only to find that my bots process names are "PHP". Any way of changing a process name for a bot?
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: Eeems on February 09, 2012, 02:19:03 pm
Oh it's a php bot? How are you running it?
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: helen on February 09, 2012, 02:20:22 pm
Oh it's a php bot? How are you running it?
php OmnomIRC.php
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: DJ Omnimaga on February 09, 2012, 02:22:00 pm
Netham45 appears to have the same problems for his OmnomIRC it seems. I wonder if your script could actually fix our split channel problems Eeems? (so we don't have to rely on AaronBot or Jimbauwen every few week or so)
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: helen on February 09, 2012, 02:23:41 pm
Netham45 appears to have the same problems for his OmnomIRC it seems. I wonder if your script could actually fix our split channel problems Eeems? (so we don't have to rely on AaronBot or Jimbauwen every few week or so)
You seriously rely on AaronBot? :o That thing is buggy! I used it as a relay and it kept getting mixed up and ended up relaying other peoples channels to mine.
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: Juju on February 09, 2012, 02:28:23 pm
You could modify the php script to write its pid to a file each startup.
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: DJ Omnimaga on February 09, 2012, 02:31:42 pm
Netham45 appears to have the same problems for his OmnomIRC it seems. I wonder if your script could actually fix our split channel problems Eeems? (so we don't have to rely on AaronBot or Jimbauwen every few week or so)
You seriously rely on AaronBot? :o That thing is buggy! I used it as a relay and it kept getting mixed up and ended up relaying other peoples channels to mine.
It didn't seem too bad last night, although when Alberthrocks modified it at one point it started freaking out. We only rely on AaronBot when Jimbauwen is not online.
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: Eeems on February 09, 2012, 02:40:35 pm
You could do the pid thing. You could also run the script itself ( ./OmnomIRC.php ( make sure to add the right stuff to the start of it ( #!/usr/bin/php5 ) ) ) that way the process name will be the name of the script instead of php :)

EDIT: @ DJ: my script probably wont fix the issues where omnom stops relaying to one of the channels. That is a code issue I think. Unless he has multiple processes ( one per server he connects to ).
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: DJ Omnimaga on February 09, 2012, 02:42:19 pm
Ah ok I was wondering, in case he didn't try it.
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: Eeems on February 09, 2012, 02:45:32 pm
I think he already has an auto-restart script. I'm not sure though, we'd have to ask him.
Oh, and btw helen, this script will also start Omnom on its own if it isn't running. You can start it first or just my script, it doesn't really matter.
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: helen on February 10, 2012, 10:01:28 am
I think he already has an auto-restart script. I'm not sure though, we'd have to ask him.
Oh, and btw helen, this script will also start Omnom on its own if it isn't running. You can start it first or just my script, it doesn't really matter.

Yes I'm aware of that. :3

You could do the pid thing. You could also run the script itself ( ./OmnomIRC.php ( make sure to add the right stuff to the start of it ( #!/usr/bin/php5 ) ) ) that way the process name will be the name of the script instead of php :)

EDIT: @ DJ: my script probably wont fix the issues where omnom stops relaying to one of the channels. That is a code issue I think. Unless he has multiple processes ( one per server he connects to ).
So if I had #!/usr/bin/php5 to the beginning of the script then what will the name of the script be?

EDIT (Eeems): merged posts
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: Eeems on February 10, 2012, 12:41:41 pm
it would be OmnomIRC.php
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: helen on February 10, 2012, 03:22:38 pm
it would be OmnomIRC.php
How long does it take for the script to do a restart?
Title: Re: How do I create a script that will restart another script after so many minutes?
Post by: Eeems on February 10, 2012, 08:54:52 pm
At most 3 seconds. It could be instant. If the script uses too much cpu power just increase the time for the sleep.