And hopefully really final edit: After upgrading to Mountain Lion, the issue seems fixed, hopefully permanently.
Final Edit: The problem doesn't happen all the time, sometimes I have to wait several days for it to occur. So it is hard to test under different conditions (i.e. safe mode or with some software disabled) and I've decided that it is not worth spending days truing different conditions in order to on fix this. Graham Perrin's suggestions were the most helpful for finding specific information about restart/reboot issues, not found in the general-purpose logs.
Some log entries are in Edit at the bottom:
Mid-2010 15in MacBook Pro, running OS X 10.7.4. Sometimes when trying to restart or shutdown the machine, it won't work -- the screen turns gray, the spinning wheel shows, but the machine doesn't power down so after several minutes I have to shut down the machine by pressing the power button.
It doesn't happen every time, and I can't relate any software used during the session with the problem. In fact, when testing this, sometimes this would happen when I try to shutdown the machine immediately after starting it.
How to check what is preventing the graceful shutdown/restart? I assume that I have to look in some log files, but I am not sure which ones and what to look for.
Edit: Added the verbose start/shutdown setting in the nvram as suggested by Graham Perrin, and eventually the machine got stuck on reboot. I saw some verbose entries on the screen and after rebooting found them in in /var/log/launchd-shutdown.log. It appears that WindowServer may have something to do with it. Below is the end of that log file with the first 3 columns removed (the first had some increasing integer numbers, the second had entries of "1" and the third -- "com.apple.launchd"):
234 com.apple.WindowServer Dispatching kevent callback.
234 com.apple.WindowServer Job has not died after being killed 2 seconds ago. Simulating exit.
234 com.apple.WindowServer Dispatching kevent callback.
234 com.apple.WindowServer EVFILT_PROC event for job.
1 com.apple.launchd KEVENT[0]: udata = 0x107827a90 data = 0x0 ident = 234 filter = EVFILT_PROC flags= 0x0 fflags = NOTE_EXIT
234 com.apple.WindowServer Reaping
234 com.apple.WindowServer Simulated exit: <rdar://problem/9359725>
234 com.apple.WindowServer Exited 22.016701 seconds after the first signal was sent
0 com.apple.WindowServer Exited while shutdown in progress. Processes remaining: 0/0
0 com.apple.WindowServer Job was last to exit during shutdown of: System.
0 com.apple.WindowServer Total rusage: utime 0.000000 stime 0.000000 maxrss 0 ixrss 0 idrss 0 isrss 0 minflt 0 majflt 0 nswap 0 inblock 0 oublock 0 msgsnd 0 msgrcv 0 nsignals 0 nvcsw 0 nivcsw 0
0 com.apple.WindowServer Closing receive right for com.apple.windowserver.active
0 com.apple.WindowServer Mach service deleted: com.apple.windowserver.active
0 com.apple.WindowServer Closing receive right for com.apple.windowserver
0 com.apple.WindowServer Mach service deleted: com.apple.windowserver
0 com.apple.WindowServer Removed
1 com.apple.launchd System: No submanagers left.
1 com.apple.launchd System: Removing.
1 com.apple.launchd System: Removing job manager.
1 com.apple.launchd System: Userspace shutdown finished at: Wed Aug 1 08:53:12 2012
1 com.apple.launchd System: Userspace shutdown took approximately 22 seconds.
1 com.apple.launchd VM statistics (now - orig): Free: 28472 Active: -21833 Inactive: -1038 Reactivations: 0 PageIns: 25 PageOuts: 0 Faults: 1654 COW-Faults: 335 Purgeable: -849 Purges: 0
1 com.apple.launchd System: Stray process at shutdown: PID 234 PPID 1 PGID 234 WindowServer
1 com.apple.launchd System: About to call: reboot(RB_HALT).
mount
command. Including the result in your question might help to narrow things down.