Hung Shell Command

From Cfwiki

Jump to: navigation, search

A tip for fixing shell commands that hang and never exit. This may help with child processes that have turned into zombies.

Some shell commands leave file descriptors open that prevent cfengine from exiting.

Try:

"shellcommand < /dev/null > /dev/null 2>&1"

To make sure all descriptors are closed in your scripts.

Also:

I've been experiencing the process restart hang under Gentoo linux for all of the init scripts, and have found a novel workaround I thought I'd share in case someone else has the problem.

Past posts have indicated that the daemon itself is at fault, and if the useshell options weren't helping, the only way to correct the issue was to fix the daemon.

Past post: http://www.geocrawler.com/archives/3/374/2000/1/0/3068970/

The workaround involves explicitly using a shell, and then forcing the shell to exit regardless of open files left by the daemon.

Here's a sample entry for syslog-ng under Gentoo:

processes:

  "/usr/sbin/syslog-ng"
     restart "/etc/init.d/syslog-ng zap start 2<&-"
     matches=1
     useshell=true

The key is "2<&-" which forces stderr to close, freeing the shell to exit. A more severe option is to use "0<&- 1<&- 2<&-" forcing stdin, stdout, and stderr to close. Closing stdin is sufficient to kill the shell under normal circumstances.

Link to Gentoo Forums posts: http://forums.gentoo.org/viewtopic.php?t=87904&highlight=

Enjoy!

RussellAdams

Personal tools