58

I am using apache2 for a project and I am wondering what is exactly the difference between these commands:

service apache2 restart
service apache2 reload
service apache2 graceful
halfer
  • 19,824
  • 17
  • 99
  • 186
VDarricau
  • 2,699
  • 2
  • 19
  • 24

3 Answers3

35

There main difference between the four different ways of stopping/restarting are what does the main process do about its threads, and about itself.

Note that Apache recommends using apachectl -k as the command, and for systemd, the command is replaced by httpd -k


apachectl -k stop or httpd -k stop

This tells the process to kill all of its threads and then exit


apachectl -k graceful or httpd -k graceful

Apache will advise its threads to exit when idle, and then apache reloads the configuration (it doesn't exit itself), this means statistics are not reset.


apachectl -k restart or httpd -k restart

This is similar to stop, in that the process kills off its threads, but then the process reloads the configuration file, rather than killing itself.


apachectl -k graceful-stop or httpd -k graceful-stop

This acts like -k graceful but instead of reloading the configuration, it will stop responding to new requests and only live as long as old threads are around. Combining this with a new instance of httpd can be very powerful in having concurrent apaches running while updating configuration files.


Source: https://httpd.apache.org/docs/2.4/stopping.html

Recommendation: Use -k graceful unless there is something wrong with the main process itself, in which case a combination of -k stop and -k start or -k graceful-stop and -k start are the options of choice.

4wk_
  • 2,458
  • 3
  • 34
  • 46
jeffmcneill
  • 2,052
  • 1
  • 30
  • 26
  • 9
    `service apache2 reload` is equivalent to `-k graceful`. `service apache2 restart` is equivalent to `-k stop` followed by starting the server again. At least in my system; read the init.d script in your distro to make sure. – Nicolás Mar 11 '18 at 02:09
  • @Nicolás I think you meant `service apache2 restart` is equivalent to `-k restart`, isn't it? _(just to be clear)_ – ecedenyo Feb 24 '21 at 16:10
  • The init.d script in Ubuntu doesn't ever use `-k restart`. `service apache2 restart` is equivalent to `service apache2 stop; service apache2 start`, and `service apache2 stop` runs `apache2 -k stop`. Other distros may vary, look at your own init.d script to be sure. – Nicolás Mar 03 '21 at 21:14
  • If you use systemd, it's not even *possible* for a service unit file to specify a command for restarting; it's a stop followed by start, always, so it can't use -k restart. – Nicolás Mar 03 '21 at 21:16
33
  1. Difference between “restart” and “reload”

    • Restart= stop + start
    • Reload = remain running + re-read configuration files.
  2. Normal restart and graceful restart, you can reference article:

    https://teckadmin.wordpress.com/2013/10/23/difference-between-graceful-restart-and-normal-restart/

Phi Thien Than
  • 339
  • 3
  • 4
  • 2
    can you please elaborate here? – Enamul Hassan Dec 15 '15 at 02:30
  • 2
    @manetsus elaborate on what specifically? A graceful is a nicer restart. Restart will stop all worker threads regardless of what they're doing, shutdown, and start up again. A graceful tells all worker threads to stop once they are finished, and when all the threads terminate, it shuts down the main process and starts up again. This is important if your apache processes aren't written with the ability to bail out safely. If you are not using a transaction, writing a file, or sending packets, a restart can cause half written/finished data. It's also very rude to users. – Fodagus Jan 19 '17 at 17:40
  • 2
    Ran out of comment space... By 'rude to users'. If a user has a request processing, even if it can be terminated without causing damage to the system, an apache restart will return a 500 error to the user. Users do not like that. – Fodagus Jan 19 '17 at 17:42
  • Thanks for the info. Quick question : Suppose on Amazon ECS , one site with huge number of sub-domains and while adding new sub-domain on fly programmatically , if we set apache2 graceful or reload. That will harm the active request / response on other sub-domains ? – Pragnesh Karia May 30 '18 at 08:25
  • @Jim Yes, by restarting the server completely it will of course read the configuration files again when it starts back up. – BadHorsie Sep 19 '18 at 12:00
11

Seems like graceful and reload are the same for apache2

In /etc/init.d/apache2:

graceful | reload | force-reload)
# rest of the script
ahong
  • 1,041
  • 2
  • 10
  • 22