Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
1. Check if apache is running
2. if so, echo "its running"
3. if not, start Apache
4. Check if apache is running (or has started or something) and echo "Apache started"
Any pointers?
PS
I can do this /usr/sbin/apachectl graceful just to make it happend, but I want to play with some shell scripting.
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
Read the following manual pages:
pidof, pgrep, ps, grep, httpd, bash (for some things like shell expansion). You would better copy-and-paste apache launch command from init script (I do not think it is a good idea to master all switches of Apache web server without need), but all the rest is relatively easy. Find where pid file lies, read it, check that such PID exists, check it is owned by Apache.
Read the following manual pages:
pidof, pgrep, ps, grep, httpd, bash (for some things like shell expansion). You would better copy-and-paste apache launch command from init script (I do not think it is a good idea to master all switches of Apache web server without need), but all the rest is relatively easy. Find where pid file lies, read it, check that such PID exists, check it is owned by Apache.
I'm less concerned about the specifics because I am not doing any system administration. This is just for my dev machine at home.
I'm less concerned about the specifics because I am not doing any system administration. This is just for my dev machine at home.
Trying to learn a few things.
Quick and dirty way would be to use the ps command and grep for httpd, which is what the process is always listed as or run as.
From that point, if it's present, do nothing, if it's not, start it. I'll let you come up with the script so you actually learn something if you really want to develop your own bash script or Perl even.. whatever floats your boat..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.