developer's blog
Ubuntu 16.04 hang on reboot.
January 15, 2017 by Adam Pajkert

Ubuntu 16.04 hangs on reboot.

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...

Let's fix it!

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:

# /etc/systemd/system.conf


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 ):

# successfully stopped some
# other services, but never
# stopped ... rc.local ...
         Stopping ... rc.local ...
         Stopping nginx...
         Stopping transmission-daemon...
[  OK  ] Stopped nginx.
[  OK  ] Stopped transmission-daemon.
# hanged there.

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...

#!/bin/sh -e
# rc.local
# ...

uwsgi --ini /etc/uwsgi/emperor.ini  --touch-reload=/home/django/sac-webapp/reload.ini &

exit 0

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!

Now it works like a charm!

But hey... what about UWSGI? It must be started automatically. Quick Google session -> cron @reboot! Cool, so I've created script called in my "~/tools" directory with uwsgi start command, and finally added crontab entry. Remember about correct access rights to script file!

# /home/pajadam/tools/
uwsgi --ini /etc/uwsgi/emperor.ini  --touch-reload=/home/django/sac-webapp/reload.ini &

# sudo crontab -l
@reboot '/home/pajadam/tools/'

Moving from Disqus to self-hosted solution