LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-31-2016, 06:08 PM   #1
nbritton
Member
 
Registered: Jun 2013
Location: Dubuque, IA
Distribution: Red Hat Enterprise Linux, Mac OS X, Ubuntu, Fedora, FreeBSD
Posts: 89

Rep: Reputation: Disabled
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
 
Old 11-01-2016, 02:31 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Which distro are you running, including version? The ones infected with systemd have trouble keeping processes alive if you don't hop through a lot of special hoops unique to systemd.

Edit: If that is indeed the problem than the work-around is something like this:
systemd-run --user --scope yourscript

more discussion here and other places:
https://bugs.debian.org/cgi-bin/bugr...cgi?bug=825394

Last edited by Turbocapitalist; 11-01-2016 at 04:28 AM.
 
Old 11-01-2016, 02:51 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
@OP: create a script and add debugging into it:
Code:
#!/bin/sh

set -xv

exec >>/tmp/somescript.log 2>&1

date

trap '' HUP

...
 
Old 11-01-2016, 02:58 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
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.
 
Old 11-15-2016, 01:47 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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...

Last edited by jpollard; 11-15-2016 at 01:48 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] running function in background and exit main script... masavini Programming 2 05-20-2012 03:42 PM
[SOLVED] Exit status of a piped-background process... acc_Wk Programming 2 09-12-2011 09:26 AM
[SOLVED] Best way to gracefully exit a background process? robertH Programming 1 06-07-2011 08:32 AM
Background job won't stay in the background! JMJ_coder Linux - General 1 03-17-2008 06:05 PM
Bash - background process and exit ?? michael_util Programming 4 01-05-2005 11:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration