Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Fri Aug 14, 2009 11:23 am 
Offline
Senior Newbie

Joined: Wed Nov 19, 2008 10:09 pm
Posts: 18
Good morning/evening everyone.
I'm facing a little problem here.

I have a perl script which I use to backup my DB (a large db).
(I run it via crontab)..
and sometime it crushing mysql server.

so I want to do the following.
1- stop apache service (to stop any http sql requests)..
2- run the backup script.
3- restart mysql to make sure that it'll run smoothly.
4- start apache service.

I have added the following to my crontab file
Code:
MAILTO=my@mail.com
0 0 * * * /etc/init.d/apache2 stop
1 0 * * * perl /var/path/to/my/backup/script
4 0 * * * /etc/init.d/mysql restart
5 0 * * * /etc/init.d/apache2 start


the backup script runs at time just fine, the same for mysql restarting command..
but the apache command is not executed..

please tell me what do I miss?


Top
   
 Post subject:
PostPosted: Fri Aug 14, 2009 11:31 am 
Offline
Senior Member
User avatar

Joined: Sun Feb 08, 2004 7:18 pm
Posts: 562
Location: Austin
What you should really do is put those four commands into a script, and execute that one script from cron. That way you're sure one won't start before the previous one is finished. Maybe that will resolve the issue you're seeing also.


Top
   
 Post subject:
PostPosted: Fri Aug 14, 2009 12:38 pm 
Offline
Senior Newbie

Joined: Wed Nov 19, 2008 10:09 pm
Posts: 18
by script, I think you mean shell script, right?

if so, I don't have any previous experiences with shell scripting..

but if that the only way to cross over this problem, I'll appreciate it if someone direct me to appropriate start point to learn about shell scripting.


Last edited by Pepo on Fri Aug 14, 2009 2:37 pm, edited 1 time in total.

Top
   
 Post subject:
PostPosted: Fri Aug 14, 2009 12:41 pm 
Offline
Senior Member
User avatar

Joined: Sun Feb 08, 2004 7:18 pm
Posts: 562
Location: Austin
It would look something like this:

Code:
#!/bin/sh
/etc/init.d/apache2 stop
perl /var/path/to/my/backup/script
/etc/init.d/mysql restart
/etc/init.d/apache2 start


Save that as backup.sh (or whatever) and point cron to that.


Top
   
 Post subject:
PostPosted: Fri Aug 14, 2009 12:42 pm 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
Start here : http://linuxcommand.org/writing_shell_scripts.php

Basically, what you want is a file like this:
Code:
#!/bin/bash
/etc/init.d/apache2 stop
perl /var/path/to/my/backup/script
/etc/init.d/mysql restart
/etc/init.d/apache2 start

Then make it executable:
Code:
chmod +x /path/to/your/new/script

And put it in your crontab instead of all the individual commands.

Edit: Oops, Xan beats me to it. #!/bin/sh might be a little more lightweight than #!/bin/bash, depending on the way your distro is wired up.


Top
   
 Post subject:
PostPosted: Fri Aug 14, 2009 12:44 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
At the most basic level, a shell script is just a series of commands. It's the same as typing the contents of the script into the console.

Code:
#!/bin/bash

/etc/init.d/apache2 stop
perl /var/path/to/my/backup/script
/etc/init.d/mysql restart
/etc/init.d/apache2 start


That's not to say that what you're doing looks particularly proper for backing anything up...


Top
   
 Post subject:
PostPosted: Fri Aug 14, 2009 1:07 pm 
Offline
Senior Newbie

Joined: Wed Nov 19, 2008 10:09 pm
Posts: 18
Xan, hybinet and Guspaz
I can't find enough words in my dictionary to thank you.

I'll follow every example posted above; I don't why, but I feel sure that will work just fine..

I'll reply again if I get any trouble, thanks a lot guys.


Top
   
 Post subject:
PostPosted: Fri Aug 14, 2009 1:24 pm 
Offline
Senior Newbie

Joined: Wed Nov 19, 2008 10:09 pm
Posts: 18
am very happy guys.
#!/bin/bash
working very will (with ubuntu 8.10)..

one thing I'd like to note for anyone in my situation is that,
if you wrote your shell script using notepad (or the like), you will end up with similar error message when you try to run your shell script
"path to your script: /bin/sh^M: bad interpreter: No such file or directory"

I installed tofrodos package and ran the command dos2unix path/to/my/shell/script

and that solve it..

thanks once more all of you guys.


Last edited by Pepo on Fri Aug 14, 2009 2:46 pm, edited 2 times in total.

Top
   
 Post subject:
PostPosted: Fri Aug 14, 2009 2:13 pm 
Offline
Senior Member

Joined: Sat Mar 28, 2009 4:23 pm
Posts: 415
Website: http://jedsmith.org/
Location: Out of his depth and job-hopping without a clue about network security fundamentals
That was probably the best forum race condition I've ever seen.

_________________
Disclaimer: I am no longer employed by Linode; opinions are my own alone.


Top
   
 Post subject:
PostPosted: Fri Aug 14, 2009 2:46 pm 
Offline
Senior Newbie

Joined: Sun Jul 19, 2009 11:54 am
Posts: 10
It's apache2ctl, not apache2.


Top
   
 Post subject:
PostPosted: Fri Aug 14, 2009 4:28 pm 
Offline
Senior Member
User avatar

Joined: Sun Feb 08, 2004 7:18 pm
Posts: 562
Location: Austin
It's
Code:
/usr/sbin/apache2ctl -k restart

or
Code:
/etc/init.d/apache2 restart


Jed, I think you need to install some kind of mutex on the forum here! I'd have grabbed it before writing the script that three of us wrote, and things would be much tidier. :-)


Top
   
 Post subject:
PostPosted: Fri Aug 14, 2009 6:17 pm 
Offline
Senior Member
User avatar

Joined: Mon Dec 10, 2007 4:30 pm
Posts: 341
Website: http://markwalling.org
Hmm, a real time communication protocol exposing a way to discuss Linode (and other things)... I should invent this


Top
   
 Post subject:
PostPosted: Sat Aug 15, 2009 12:11 am 
Offline
Senior Member

Joined: Fri May 02, 2008 8:44 pm
Posts: 1121
jed wrote:
That was probably the best forum race condition I've ever seen.

And I thought at least some of us were trying to fix the OP's potential race condition! 8)


Top
   
 Post subject:
PostPosted: Mon Aug 17, 2009 2:20 pm 
Offline
Senior Member

Joined: Sat Mar 28, 2009 4:23 pm
Posts: 415
Website: http://jedsmith.org/
Location: Out of his depth and job-hopping without a clue about network security fundamentals
Xan wrote:
Jed, I think you need to install some kind of mutex on the forum here!

Naw. People fighting over replies is better, as it communicates to me the willingness of the community to help. :)

_________________
Disclaimer: I am no longer employed by Linode; opinions are my own alone.


Top
   
 Post subject:
PostPosted: Mon Aug 17, 2009 4:51 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
mwalling wrote:
Hmm, a real time communication protocol exposing a way to discuss Linode (and other things)... I should invent this


It looks like the latest stable version of CGI:IRC was released over 3 years ago. You should consider Mibbit (which, coincidentally, is hosted at Linode). It gets much more active development, is much more feature-rich and usable, and can be embedded in sites (http://widget.mibbit.com/manager/).

The downside? Closed-source, so it only runs on Mibbit's linode. Can't port it elsewhere.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group