My VPS had a problem with shutdown and reboot for a long time. I tried to fix it earlier, unsuccessfully. Maybe Ubuntu 16.04 hanged when systemd was stopping services? I logged into DigitalOcean console and there was no errors. I had no clue why it does not work, so I've started digging...
First of all - logs. I checked all logs from time when I issued reboot command. Nothing special, no errors. I decided to stop all services installed by me manually ( e.g. nginx ) and tried reboot again - with no success. I thought that it may be caused by systemd waiting for service to stop. Last time I was waiting only 1 minute, till I forced server reboot, so next time I gave it more time. Additionally I've changed systemd stop timeout:
Now I was waiting 30 mins and nothing happens... again. But before forcing reboot, I looked at the console output and noticed something interesting... One line of the console output was strange. Normally systemd informs you when service stopped successfully or not. But this line was not followed by "[ OK ] Stopped" or even "[FAILED]" message. It was something like this ( may be inaccurate, I forgot to take a screenshot ):
It was a last clue... I needed to check what's going on in rc.local file. Let's find out what's in here...
There was a startup script for my UWSGI server. Nothing special, I was wondering how it could prevent my server reboot. I removed this line and tried to reboot... Fail. Ubuntu hangs out again... I decided to give it a last try, just to make sure... and BOOM! Reboot complete correctly in less than 30s! Problem solved!
But hey... what about UWSGI? It must be started automatically. Quick Google session -> cron @reboot! Cool, so I've created script called boot.sh in my "~/tools" directory with uwsgi start command, and finally added crontab entry. Remember about correct access rights to script file!