Operating System - Linux
1827466 Members
3176 Online
109965 Solutions
New Discussion

Re: init.rc script fails because tty detach

 
SOLVED
Go to solution
manoj_pu
Regular Advisor

init.rc script fails because tty detach

we tried to set an init script to start an application on system boot using an init script (rc).

The process starts but is killed by the next inittab line: getty console.

Is there any way to "demonize" the process and then detach it from the console.

I tried to "nohup" the script but it fails to detach the process from console.


Manoj
Leave with out tense and try best you gets result
13 REPLIES 13
Sudeesh
Respected Contributor

Re: init.rc script fails because tty detach

I couldn't understand why you want to start the script using inittab entry, is it a specific requirement?

May be your script is starting the process too early (that means at a point where other necessary system process still to start) and thats why it is getting killed.

Try starting the script manually after the system is booted. If this works fine put your script in /sbin/init.d folder and then create a link from /sbin/rc2.d. Adjust the link name so as to run it at the last of run level 2. Link name should be in Sxxx format.


Hope this helps

Sudeesh
The most predictable thing in life is its unpredictability
Mel Burslan
Honored Contributor

Re: init.rc script fails because tty detach

does your process have a need for console access ? And why does it need to start before the console getty process ? Or is it getting killed because it is conflicting with getty for console resource ?

I am not sure what process needs to be started this early in the boot-up sequence but if you just time the start of your program, and run it on the background with nohup, there should not be any problems.
________________________________
UNIX because I majored in cryptology...
Stuart Browne
Honored Contributor

Re: init.rc script fails because tty detach

So doing a 'nohup &' doesn't work?

What are you trying to daemonize anyway?
One long-haired git at your service...
Stuart Browne
Honored Contributor

Re: init.rc script fails because tty detach

Oh, I should probably expand on that a bit further.

Some applications grab STDIN, STDOUT and STDERR rather firmly when they start, even if they are backgrounded. Sometimes you need to force thse file-descripters to go elsewhere, i.e.:

nohup processname < /dev/null > /dev/null 2>&1 &

But tell us what you're trying to background like this in the RC scripts, and we'll see if there's a better way.
One long-haired git at your service...
Devender Khatana
Honored Contributor

Re: init.rc script fails because tty detach

Hi,

Could delaying the script for sometime will help ? I would thought of giving it a try. Delay the script for atleast 10-20 secs for it to start before proceding to execute the next script.

But can not it be done by putting it somewhere in /sbin/init.d and link to required runlevel as Sudeesh mentioned. A brief desciption of what you are trying to achive will help us a bit to help you better.

HTH,
Devender
Impossible itself mentions "I m possible"
Eknath
Trusted Contributor

Re: init.rc script fails because tty detach

Hi Manoj,

As Sudeesh suggested the best way would be to try the script once the system is booted. If the script works fine the you can use the template in /sbin/init.d to customize your script. Then based on requirement of the script place it in either rc2.d/rc3.d/...

Cheers!!!
eknath
manoj_pu
Regular Advisor

Re: init.rc script fails because tty detach

I am trying to start xvfb (xserver) and mwm xserver manager by using init.rc in the system startup.

Same startup script works fine if I run manually.

startup script - /sbin/init.d/xvfb
and it is link to /sbin/rc3.d/S995xvfb

Now the problem is:
When system starts script starts xvfb and mwm, below is the process details

â root 4886 1 0 22:31:14 console 0:03 /usr/bin/X11/X :10 -ac -fbdir /var/X11/Xserverâ

â root 4890 1 0 22:31:44 console 0:00 /usr/bin/X11/mwm -display :10â

This process status remain same untill the system console login prompt comes.

After that xvfb remain running with below process status and mwm process automatically dies.

root 4886 1 0 22:31:14 ? 0:03 /usr/bin/X11/X :10 -ac -fbdir /var/X11/Xserver

Please tell me how to "demonize" the mwm process and then detach it from the console as what is happening with xvfb automatically.

Thanks and Regards

Manoj
Leave with out tense and try best you gets result
manoj_pu
Regular Advisor

Re: init.rc script fails because tty detach


Just repeating

xvfb & mwm process status

before system console login prompt comes

root 4886 1 0 22:31:14 console 0:03 /usr/bin/X11/X :10 -ac -fbdir /var/X11/Xserver

root 4890 1 0 22:31:44 console 0:00 /usr/bin/X11/mwm -display :10

After system console login prompt comes
only xvfb survive and mwm dies

root 4886 1 0 22:31:14 ? 0:03 /usr/bin/X11/X :10 -ac -fbdir /var/X11/Xserver


Regards

Manoj





Leave with out tense and try best you gets result
Mel Burslan
Honored Contributor

Re: init.rc script fails because tty detach

Manoj,

I am under the impression that you have not tried the nohup option yet. Did you ?

in your startup script, make sure you have somthing like this :

DISPLAY=`/usr/bin/hostname`:10; export DISPLAY
nohup sh -c '/usr/bin/X11/Xvfb :10 -ac \
-fbdir /var/X11/Xserver & ; \
sleep 5; /usr/bin/X11/xhost + ; \
/usr/bin/X11/mwm &' > /dev/null

________________________________
UNIX because I majored in cryptology...
manoj_pu
Regular Advisor

Re: init.rc script fails because tty detach

Burslan,

You are exactly right.

But that does not work to "demonize" the mwm process in the system startup.

Do you have any other catch on it???
Leave with out tense and try best you gets result
Mel Burslan
Honored Contributor

Re: init.rc script fails because tty detach

To the best that I know daemons are written, compiled and linked to be daemons. You can not just expect any executable to be run as a daemon in the full meaning of it. nohup and running it in the background as a detached process is the best thing you can do without re-writing the whole program yourself.

Some programs have the option of running themselves ad daemons, like sendmail, with proper command switches but a quick glance over mwm does not show anything close to this.

Also, running a process in the background, doing whatever you are expecting from it to do, is not much different than the actual daemon functionality, maybe with a bit of extra overhead due to shell handling etc. What else are you after by runnig it as a *true* daemon ?
________________________________
UNIX because I majored in cryptology...
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: init.rc script fails because tty detach

If you must daemonize a process using a scripting language then Perl is your best bet. It lets you use setsid() to detach the process from a controlling terminal. Try the attached Perl script and make your changes in the "exec" function. The idea is that the process forks() then the parent is allowed to exit; the child then sets up any signal handlers and does an exec(). It's also a good idea for all daemons to to a cd to / so that umounts won't fail with "device busy".
If it ain't broke, I can fix that.
manoj_pu
Regular Advisor

Re: init.rc script fails because tty detach

All,

Finally the the story end successfully!!!
Special thanks to Stephenson for wonderful perl script.

Thanks & Best Regards

Manoj
Leave with out tense and try best you gets result