Operating System - HP-UX
1822037 Members
3404 Online
109639 Solutions
New Discussion юеВ

Re: rc scripts starting background processes?

 
SOLVED
Go to solution
Eric Buckner
Regular Advisor

rc scripts starting background processes?

Hi everyone. I think I know the answer to this but can not find anything online about it. Is it possible or needed to have an RC script to launch a program in the background. I currently have a shell script that I want to start and stop w/ rc. Of course I don't want it hold the current session if I stop/start it via /sbin/init.d/myscript. On system startup doesn't the rc/init in a sense put everything in the background? And if my start section in my init script does a myscript.sh & Is that going to be an issue and cause the job not to run?

Thanks,
Eric
Time is not a test of the truth.
8 REPLIES 8
harry d brown jr
Honored Contributor

Re: rc scripts starting background processes?

Yes you can. I used nohup with &.


live free or die
harry
Live Free or Die
Robin Wakefield
Honored Contributor

Re: rc scripts starting background processes?

Hi Eric,

A number of startup scripts run commands in the background, e.g. omni,cmcluster. Try typing:

grep ' &$' /sbin/init.d/*

to see examples. As long as your scripts are not interactive or need to be attached to a device, you should be OK.

Rgds, Robin.
Eric Buckner
Regular Advisor

Re: rc scripts starting background processes?

Is the nohup required in the init/rc scripts?

I have 2 processes currently that according to the rc.log attempt to start but not actually start. Both of these are shell scripts, one running a disk archive ever 5 seconds, and the other is used to launch BigBrother. Neither of these start up. But the ones I have added that actually launch a daemon application work just fine.

Thanks
Time is not a test of the truth.
James R. Ferguson
Acclaimed Contributor
Solution

Re: rc scripts starting background processes?

Hi Eric:

Launch your script like this:

# nohup $MY.SH > ${MY.SH}.nohup 2>&1 &

Regards!

...JRF...
harry d brown jr
Honored Contributor

Re: rc scripts starting background processes?

If the daemon can spawn a process without nohup, then that is better. Cron does it even from the command line. You could also put it into inittab.

live free or die
harry
Live Free or Die
A. Clay Stephenson
Acclaimed Contributor

Re: rc scripts starting background processes?

Hi Eric:

If your script runs to completion and then exits there is no need to '&' or nohup it.
You do need to make certain that no interactive input is expected. You also need to make certain that you handle stdout and stderr correctly and return expected status to rc. However, if you are setting up a daemon, then you probably need to put in trap statements to ignore or properly handle signals. e.g. what do you want your daemon to do when it receives a kill -1? Die or reread some configuration file.
If it ain't broke, I can fix that.
Roger Baptiste
Honored Contributor

Re: rc scripts starting background processes?

Hi,

yes, you can start rc
scripts as backgroupd processes. For an example
here are couple of scripts
in the /sbin/init.d which
use nohup and & for
doing it:
*****
hparamgr:
nohup ${ARRAY_STARTUP_FILE} >> ${HPARAMGR_OUTPUT} 2>&1 &
hparray:
nohup ${ARRAY_STARTUP_FILE} >> ${ARRAYSCAN_OUTPUT} 2>&1 &
slsd: nohup /usr/bin/X11/SLSd_daemon 1> /dev/null 2>&1 &
spa: # Use nohup so getkinfo is allowed to keep running after the
spa: nice -5 nohup /usr/sam/lbin/getkinfo -b >/dev/null 2>&1 &
*****************

So, yes you can use
the same format as above
for running your script.

Regarding your other question, whether the rc scripts start off in background automatically -
No, it basically depends on the commands. For instance most of the rc scripts either do immediate tasks (mount fs ..) or start of daemons (nfs ..) . So, they didnt
need nohup or & . Whereas
if you want to some script as a background which should not die, you need to set it up
as a nohup bg process.

HTH
raj
Take it easy.
Eric Buckner
Regular Advisor

Re: rc scripts starting background processes?

Thanks everyone for the rapid replies. One script was running to completion and did not need to be launched in the background. However, the other is a shell script daemon and I have added the nohup and will see how that goes next reboot.

Again thanks for the assistance!
Time is not a test of the truth.