Process won't stay running in the background after exit, even if nohuped or disowned.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Red Hat Enterprise Linux, Mac OS X, Ubuntu, Fedora, FreeBSD
Posts: 89
Rep:
Process won't stay running in the background after exit, even if nohuped or disowned.
I'm stumped, I've tried at least 20 incantations and all of them work when I run them manually, but when I run them via an ansible script they don't do anything.
I'm trying to kick off racadm serveraction powercycle from an ansible script. Ideally I want it to run as a daemon (first sleep for 10 seconds, then run) in the background and return control back to the script so it can exit in order to properly close the ssh connection. It doesn't seem to matter if I use disown, nohup, setsid, or detach all I/O. It works perfect if I run the script manually, but as soon as I have ansible kick it off it never runs. It enters the if control block, the echos work but forking it never does anything.
Code:
if [[ ${POWERCYCLE} == "1" ]] || test -f /tmp/POWERCYCLE; then
echo "The system must be power cycled for the new firmware changes to take effect.";
echo "racadm serveraction powercycle has been triggered, restarting in 10 seconds.";
#{ (sleep 10 && /opt/dell/srvadmin/sbin/racadm serveraction powercycle) &>/dev/null </dev/null & } 2>/dev/null;
#{ nohup sh -c '(sleep 10 && /opt/dell/srvadmin/sbin/racadm serveraction powercycle) &>/dev/null </dev/null' & } 2>/dev/null;
#(nohup /opt/dell/srvadmin/sbin/racadm serveraction powercycle </dev/null &>/dev/null &) 2>/dev/null;
#sh -c '( echo "Hello" &) & disown; exit' 2>/dev/null
sh -c '( /opt/dell/srvadmin/sbin/racadm serveraction powercycle </dev/null &>/dev/null &)' & disown 2>/dev/null;
fi
I would say the environment is not the same, so when you run it from ansible something was missing (most probably a library or environment variable).
I suggest you to check if there was an error message during execution. I would try to redirect stdout and stderr into files. Suppressing them is not a good idea (if you want to find the reason). Also it may have some log files.
It is possible you are running into a systemd issue - it tends to kill any user process during logout as part of cleaning up the session. And "nohup" doesn't help as it is also part of the session.
I understand there is supposed to be a configuration option to change this back to something more standard...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.