-2

I built apache 2.4.2 on CentOS from source and now am trying to create an init.d script to go along with it. A friend gave me one script but it never outputted a success or fail and I disliked it. I found in the tar a httpd.init script file. It just needed the location of apache changed but besides that seemed like it would work. However, it fails to stop httpd. It will start just fine however. Below is my current script in /etc/init.d/httpd. I found on this other topic: Restarting the httpd service in RHEL returns "Stopping httpd: [FAILED]" - How do I fix this? to check that a pid file is created in the /var/run directory but it is not being created there even when starting with service httpd start or the init.d script directly. I'm still fairly new to linux so please explain as much as possible. I'm a fast learner.

Can anyone help me find what's wrong with this script? I'm running CentOS 6.3 x86_x64.

http://pastebin.com/sucmvBF6

Dustin
  • 11
  • 4

3 Answers3

0

Have you tried init.d script from httpd packages for latest Fedora?

http://koji.fedoraproject.org/koji/packageinfo?packageID=280

Denis
  • 473
  • 3
  • 9
0

What I dislike about your script (but I`ve seen this many times in distribution supplied ones, too) is that the location of the httpd-pid-file is somewhat hard-coded.

This is probably your problem here. If that hard-coded location and filename does not match the httpd configuration (there is the directive PidFile in httpd.conf) your killproc will do nothing intelligent.

So either you should parse your config-file for PidFile and fall back to the compiled-in standard, or use apachectl (with your config-file as parameter) for stopping httpd.

IMHO the latter is better and also covers the case where the pid-file has vanished (by accident).

Nils
  • 7,657
  • 3
  • 31
  • 71
  • I forgot to mention that I changed the lines: apachectl=/usr/sbin/apachectl and httpd=/usr/sbin/httpd to reflect the correct location of those files. As I see the script does have the apachectl location how do I change it to use apachectl instead? Also in my httpd.conf (/etc/httpd/conf/httpd.conf) there is no line for PidFile? (EDIT: I didn't write this, it's from the site I posted.) – Dustin Jul 28 '12 at 20:15
  • Okay so I added the PID file directive (/var/run/httpd.pid is the path now) But I'm still wondering how I change it to use the apachectl? – Dustin Jul 28 '12 at 20:34
  • @Dustin look at the **stop** function. It uses `killproc` and the pid-file. Use `$apachectl -k stop -f $configfile` instead (look at `man apachectl` for details). This is propably much better than fiddling around with PID-files. But you have to define the **configfile** instead. – Nils Jul 28 '12 at 20:47
  • thank you, I'll try it out in a few hours. This seems promising. Could you just tell me how to define the config file? I'm having a very hard time trying to understand how these files work. – Dustin Jul 28 '12 at 20:54
  • @Dustin `configfile=/etc/httpd/conf/httpd.conf` just below the definition of `apachectl` - set it to wherever your config resides. – Nils Jul 28 '12 at 20:58
  • This worked! I also changed the start section to use apachectl and it seems to be working. Last question though, Is it possible to have it print the [ OK ] and [ FAILED ] depending on what happens? Or is that dependent on apachectl? – Dustin Jul 29 '12 at 02:32
  • Wait, it still is failing to stop. It says the pid file isn't running. I have PidFile set to /var/run/httpd.pid in my httpd.conf and the script has the same path assigned to the pidfile path. – Dustin Jul 29 '12 at 02:37
  • So I've discovered that it's not deleting the pid file so running status says dead but pid file exists. But the command is there to remove it it seems. I've updated my origonal post with my latest script. – Dustin Jul 29 '12 at 02:50
  • @Dustin the **ok** and so on messages are distribution dependent. Look at other init-scripts. `. /etc/rc.d/init.d/functions` is parsed by most of them (CentOS/RedHat specific). This gives you the functions `success` and `failure`. This file is already being parsed, so you can use the functions directly. – Nils Jul 30 '12 at 19:20
0

Remi has httpd 2.4.2 in his github repo, though he doesn't seem to have built it yet (or it doesn't yet work) as I don't see RPMs for it yet. But you may be able to take his stuff and build RPMs.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940