Ubuntu can't shutdown and the log-out screen just freezes

This is the question I already have an answer, but answering for others. I have been having a problem, whenever I try to shutdown, suspend or restart Ubuntu or Gnome 3, the shut-down screen just freezes, and it didn't shut down.

The question is how to find a cause and how to fix?


The answer for this one was: After I have clicked on a button shutdown and the log-out screen has shown, I pressed the esc key and I could see the error text messages, and I have found the message:

Waiting for Redis to shutdown ...

After finding out what script is used to shutdown Redis, I have found out it is:

/etc/init.d/redis_6379

When I tried manually to shutdown manually from console running a command:

sudo /etc/init.d/redis_6379 stop

I got the same error message. I was one step closer to the solution. Even though maybe the solution was not as perfect as it could be, but I managed to solve my problem. I have edited the file:

sudo gedit /etc/init.d/redis_6379

And found the:

echo "Waiting for Redis to shutdown ..."

Edited the surrounding code (commented out some lines and added one other command to shutdown the Redis server)

/etc/init.d/redis-server stop
#while [ -x /proc/${PID} ]
#do
  echo "Waiting for Redis to shutdown ..."
  #sleep 1
#done

And whola! The Ubuntu now will not stuck in an infinite loop, and now I could shutdown, suspend and restart again! :)