1


I'm trying to simplify commands on my ubuntu server.

For now, to start / stop / restart apache2, we have to type those commands :
stop : /etc/apache2/bin/apachectl -k stop
start : /etc/apache2/bin/apachectl -f /usr/local/apache2/conf/httpd.conf
restart : /etc/apache2/bin/apachectl restart

and kinda same for MySql :
stop : mysqladmin -u root shutdown
start : mysqld_safe --user=mysql --log &

What I wish is to be able to use /etc/init.d/apache2 start or /etc/init.d/mysql start to make it simple and not having to always look at the Wiki to find the exact command to use each time...
I tried to find samples of files to put in init.d folder, but found nothing.

I also wanted to know how to do the same with service apache2 start (and same for stop/restart and MySql).
Is there a difference between using /etc/init.d/xx start and service xx start ?
Thanks for you help !

Random
  • 3,158
  • 1
  • 15
  • 25

1 Answers1

1

Just put the executable file i.e apachectl in /etc/init.d/ and than try with /etc/init.d/apache{tab} restart/start/stop and all for mysql too it will work.

Actually init.d contains the shell script file that is executable.

Take care the file should be executable like below chmod +x /etc/init.d/apachectl

chintan thakar
  • 1,440
  • 1
  • 15
  • 25
  • Ok, isn't there any script to write in order to say `start` means : running the executable with `-f /usr/local/apache2/conf/httpd.conf` parameter ? – Random Apr 30 '15 at 12:03
  • yes if you properly configured environment variable than. just try out by placing /bin/apachectl to /init.d/ – chintan thakar Apr 30 '15 at 12:37
  • and one more thing if you install apache in ubuntu with `sudo apt-get install apache` than it would be by default installed in /init.d/ directory no need to do this long process I think – chintan thakar Apr 30 '15 at 12:39
  • We had to install MySql and Apache manually since we need specific versions to be production-like. I can actually use /etc/init.d/apache2 restart/start/stop (after renaming apachectl), it works. What do you mean by "yes if you properly configured environment variable" ? what should I put in my environnement variables ? – Random Apr 30 '15 at 15:50
  • Means you have to make your default `/bin` in path like `PATH="$HOME/bin:$PATH"` you will find that by `vim ~/.profile` if its /bin than it will execute all the shell script and in your case it will be so you can place shell file inside /init.d/ and execute it. – chintan thakar May 01 '15 at 05:37