Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been searching for an hour and have found a hundred examples that use it, but no explanation of what it does. I did check man apache2ctl; it doesn't explain the k flag either (elthough it does use it in examples).

share|improve this question
up vote 7 down vote accepted

Yeah, it's a little buried in the description:

When acting in pass-through mode, apachectl can take all the arguments available for the httpd binary.

apachectl [ httpd-argument ]

So let's look at http's documentation then:

-k start|restart|graceful|stop|graceful-stop

Signals httpd to start, restart, or stop.

So if you use -k <option>, you'll simply pass on to httpd, which needs this argument.

If you don't use the -k, apache2ctl will instead look for commands that it will handle itself, which are again the same as httpd would take.


Looking at the source code exhibits this behavior, where a case statement checks whether the first argument is one of the recognized internal commands, and finally (as a fallback), everything's passed onto httpd.

case $ARGV in
start)
  HTTPD ${APACHE_ARGUMENTS} -k $ARGV # <= note the -k here
  # ...
stop|graceful-stop)
  # ...
# ...
*)
    $HTTPD ${APACHE_ARGUMENTS} $ARGV
    ERROR=$?
esac
share|improve this answer
    
I'm new to this. Could you explain to me in plain English what ommitting the k flag will actually do? On my Ubuntu server it seems to make no difference if I use the k flag or not, it always restarts successfully as far as I can tell. – BadHorsie Nov 24 '15 at 11:29
    
What you're seeing is normal. Like I said, if you do not use -k, then apachectl will handle the commands itself, but it does the same as httpd. If you use -k, the command is passed on to httpd as-is. – slhck Nov 24 '15 at 15:08
    
I still don't really know what that means in terms of functionality, to be honest, but are you saying then that it doesn't matter if you use the -k flag or not, it will do the same thing in a roundabout way? – BadHorsie Nov 24 '15 at 16:12
1  
That's what I'm saying, yeah. It's for historical reasons that both work. – slhck Nov 24 '15 at 21:42

Edit to add: Sorry, slhck types faster than me :D

'apache2ctl' is actually just a front-end for the 'httpd' executable and runs in two modes depending on if you're wanting it to be SysV init scriptable or if you're wanting to pass-through options to the httpd executable. The -k actually gets passed through to httpd.

http://httpd.apache.org/docs/2.2/programs/apachectl.html

When acting in pass-through mode, apachectl can take all the arguments available for the httpd binary.

apachectl [ httpd-argument ]

So from the httpd man page, http://httpd.apache.org/docs/2.2/programs/httpd.html

-k start|restart|graceful|stop|graceful-stop Signals httpd to start, restart, or stop.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.