I have been wondering if issuing a reboot command safely stops running LAMP processes like MySQL or Apache?
If it's installed as a service (most likely case), it should get the command to stop on the way down automatically.
If it's not, then you should stop them first.
Edit: Now that I have a few minutes at a computer, I'll expand on this a bit.
One way to view your available services is to use the service
command (typically /sbin/service
)
As root
(or using sudo
or a similar command) you can use the following:
# service --status-all
# service --status-all | grep httpd
# service --status-all | less
# service httpd status
You can also use the chkconfig
command (again as root
)
# chkconfig --list
# chkconfig | grep httpd
# chkconfig --list | less
If the applications were installed during OS installation or via yum
this will most likely by the case for you and they will stop when the OS is shutting down or rebooting.
If they were installed via some non-standard way and not as a service, then it would be best to stop them first, otherwise the OS will forcefully stop them before shutting down (killall
)
They don't need to be stopped per se, but they need to know that they have to flush all current writes to disk and switch to read-only. It just so happens that stopping them prevents them from writing any more to the disk by default (since they no longer exist). Most shutdown processes stop any running daemons.
Sometimes (not on Linux, though) there's a difference between a reboot initiated by reboot
command and orderly shutdown & reboot (shutdown -r
); the latter runs any shutdown scripts, the former doesn't and kernel simply terminates all running processes (forcibly with SIGKILL, if need be)
-
I know this is the case in older (over 10 years ago) Unix systems (hp-ux, Solaris, aix). I haven't work with the newer versions of them, is it still true? – pferate Jun 16 '13 at 21:12
-
I administer a mix of Linux, AIX, HPUX & BSD systems. As a matter of habit I always use shutdown -h and then manually restart. I only use reboot and poweroff if I know that no critical services are running, e.g. non-production systems, i.e. mostly when hacking on my own servers. – CyberFonic Apr 4 '17 at 8:57
-
@CyberFonic so which reboot params should I use before restarting working server with apache, mysql and php? Is there is a reboot command with params that will wait until processes will finish their task and then reboot? – Eryk Wróbel Aug 11 '20 at 10:13
-
@Eryk Wróbel, I can't answer your question directly because I don't use any of the subsystems you mention. If I was administering such a system, then I would simply write a script to directly stop those services and only then call reboot. Mind you, most of my servers go for months without a reboot. – CyberFonic Aug 13 '20 at 8:20