LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-01-2008, 06:42 PM   #1
rova
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Rep: Reputation: 0
Question How to make a bash script to start & end apache and mysql ?


Hello everybody,

i installed apache, php and mysql on Ubuntu distro. (7.10) . Every time that i start my computer and Linux Ubuntu Apache and Mysql starts automatecally .

I want if its possible to create a script (propably bash script) so that Apache and Mysql will not start like now automatecally but to have the possibilty to start and turn them off whenever i like to .

Now every time that i start Ubuntu i have to write to console :
[HTML]/etc/init.d/mysql stop & /etc/init.d/apache2[/HTML] to stop and turn borth off !

So i want to know if its possible to be alble to manage when both of them will start and when will be off . I guess that, that can be possible by writing some bash script, so please be kind and show me how i can make one !? (a... newbie)

Thanks in advance

Last edited by rova; 03-01-2008 at 06:44 PM.
 
Old 03-01-2008, 06:56 PM   #2
danboland
Member
 
Registered: Feb 2006
Location: NJ, USA
Distribution: Debian
Posts: 72

Rep: Reputation: 17
This is actually quite easy to do. there are two steps.

First, remove the mysql and apache start up scripts. (i also stop postfix as well since i dont need it with apache and mysql) just enter the following commands as root:

Code:
 cd /etc/rc2.d/
 mv S91apache2 K09apache2
 mv S20postfix K80postfix
 mv S19mysql K81mysql
 mv S18mysql-ndb K82mysql-ndb
 mv S17mysql-ndb-mgm K83mysql-ndb-mgm
You technically could delete them, but the proper thing to do is to move them with the S becoming a K and replacing the number in front of it with 100 minus the current number. This will stop the services if they get started by accident by another service.

Secondly, create 2 script and move them to /usr/local/bin (or any other directory in your path)

to start the services:
Code:
#!/bin/sh

# start up services needed by web server
sudo /etc/init.d/postfix start
sudo /etc/init.d/mysql-ndb-mgm start
sudo /etc/init.d/mysql-ndb start
sudo /etc/init.d/mysql start
sudo /etc/init.d/apache2 start
to stop the services:
Code:
#!/bin/sh

# stop up services needed by web server
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql-ndb stop
sudo /etc/init.d/mysql-ndb-mgm stop
sudo /etc/init.d/postfix stop
I call them web-start and web-stop on my comp, but they can be named anything. If you have anyother servies running that are only for development you could do the same thing with them (such as bind). There is no need to stop php, since the interpertor is only run when you access it directly.
The sudo will let you run these command as a normal user and just enter your password.

Dan

Last edited by danboland; 03-01-2008 at 07:00 PM.
 
Old 03-01-2008, 07:27 PM   #3
rova
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Arrow

Thank you very much danboland, it works
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
End & Home keys for Bash on FreeBSD mdixon *BSD 4 11-20-2004 08:57 PM
Bash script - to save and run a command at the end satimis Programming 15 11-02-2004 08:53 AM
How To make MySql and Apache start at boot time? umeshz Red Hat 1 05-18-2004 01:00 PM
How to make a programm to start at the end of startup process ayachi Linux - Software 1 04-15-2004 10:31 AM
Mount hd with start & end jsalvoeiro Linux - Newbie 1 09-16-2003 02:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration