I'm using raspbian stretch to run a simple Apache2 web server with a USB external hard drive (formatted ext4) connected as the public_html source for a low-traffic web server. Whenever I issue a sudo shutdown command, the next time I reboot, the external hard drive shows up as damaged and requires a fsck treatment before it can be rebooted successfully back into operation.
I CAN shutdown safely if I first stop Apache2 (sudo systemctl) then unmounting the external drive (sudo umount) and then shutting down, but shouldn't a standard sudo shutdown take care of this properly? I think something's wrong but I don't know what to look for. An older R-pi onsite that functions as a TimeMachine network server doesn't show this problem. I'm pretty sure that the drive corruption problem isn't because someone is actively accessing the web server every time I happen to request a shutdown.
As a band-aid solution, can I create a shell script that will take over for me and do these steps in sequence for me and then have that script invoked by the shutdown command?