Register
It is currently Mon Sep 22, 2014 12:15 pm

Apache and MySQL start / stop.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Wed Jul 29, 2009 12:51 pm   

Joined: Wed Jul 29, 2009 10:23 am
Posts: 1
Wrote a very simple script to manually start apache and mysql when i really need it.
What script is doing is starting apache and mysql and pops a message that everything has been started.

Code:
#!/bin/bash
sudo service apache2 start
sudo service mysql start
zenity --info --text 'Apache and MySQL has been started sucessfully!'

start can be changed on stop or restart, depends on why you need this scirpt for

Please note that in order for this to run correctly with no password you have to modify /etc/sudoers
The part that you need looks like this.

Code:
# Cmnd alias specification
Cmnd_Alias HTTPD = /etc/init.d/apache2, /var/init.d/mysql

# User privilege specification
root   ALL=(ALL) ALL
screatch     ALL=NOPASSWD: HTTPD

* Change screatch on your username

Also please note that this is my first ever script so i will be glad to hear any complaints and advices.


Top
 Profile  
 PostPosted: Tue Sep 01, 2009 7:41 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
You might want to add in some error checking. The return code of the last run command is in $?. If it's not equal to 0, there was an error.
So, maybe something like this:
Code:
#!/bin/bash
sudo service apache2 start
if [ $? -ne 0 ] ; then
  zenity --info --text 'Apache failed!'
  exit 1
fi
sudo service mysql start
if [ $? -ne 0 ] ; then
  zenity --info --text 'MySQL failed!'
  exit 1
fi
zenity --info --text 'Apache and MySQL has been started sucessfully!'
exit 0


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 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
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP