- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: automatic service startup while booting
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2003 02:50 AM
11-19-2003 02:50 AM
I try to start a deamon process (written in perl) during system startup. On my linux machines I'm using the following code in one of my startup scripts:
#!/bin/sh
#
...
...
...
if [ "$START_NOVAD" -eq 1 -a -x $novad ]; then
if [ $debugfile != "syslog" ];then
$novad 1>$debugfile 2>&1 &
else
$novad | /bin/logger -i -t novad &
fi
set_return
echo "$productname $programname starting up"
set_pid
else
rval=3
fi
...
...
...
On my Linux machines the process starts and logs every message to either syslog (via /bin/logger) or in the logfile.
Under HP-UX this seems not to work! Can you help me within these two questions?
1. If I use exactly this code the process stops emediately after starting. :-( Manually executing the startscript as root works fine. Why?
2. I modified the code and tried to start the deamon with "/bin/nohup $novad". That works! The deamon starts but only if I _don't_ use " | /bin/logger...". It works fine while executing it manually as root - also with "| /bin/logger...". Why?
Regards
Marco
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2003 03:11 AM
11-19-2003 03:11 AM
Re: automatic service startup while booting
How do you start this during startup? A guess would be that the startup script that you placed this in has completed, and closed it's shell.
You could place this script in one of the rc directories and have it start as a daemon during boot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2003 09:21 AM
11-19-2003 09:21 AM
Re: automatic service startup while booting
> If nohup makes it work then the shell that > starts the process is exiting, killing all > shell processes (nohup's excepted)
Yes, sounds good - but: It works under Linux this way. Why not in HP-UX?
> How do you start this during startup? A
> guess would be that the startup script
> that you placed this in has completed,
> and closed it's shell.
I have a script /sbin/init.d/novad which is linked to /sbin/rc3.d/S990novad. This script contains my posted lines.
So if you mean the only way to start my daemon during bootup is doing it via nohup, could you tell me why my daemon won't work completely when piping it through logger? I cannot! ;-)
I think I should post a summary for the moment:
1. $novad: does not work during bootup
2. nohup $novad: works during startup
3. nohup $novad | logger: does not work during bootup
-> But every of the three versions of the script are working fine while executing them as logged in root user.
I'm confused
Marco
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2003 02:02 PM
11-19-2003 02:02 PM
Re: automatic service startup while booting
1. Startup is a VERY different environment from a login. At startup, there is no controlling terminal and the env values are quite different. Startup scripts require 4 separate parameter tests and are required to reject anything else. The file /sbin/init.d/template gives you the details. Startup scripts must also handle shutdown properly, ideally terminating the process(es). In the template, you'll see that start,stop,star_msg,stop_msg must be handled and that return codes 0,1,2,3,4 must be handled. Pay particular attention to return code 4 in the beginning comments of the template.
But it's important to understand that all startup scripts must run to completion in a short period. If it did not, the machine would take a very long time to bootup.
2. You must use nohup to protect your process that you put into the background. If you do not, then the end of the script (which is the parent) will kill the process. However, in your example, you used nohup to protect your porcess but then connected it with a pipe to logger and put logger into the background. You need to put the entire command pipe into a subshell so it is treated as a single entity:
nohup ($novad | /bin/logger -i -t novad) &
A couple of scripting notes:
Using fullpaths is good but makes scripts hard to read. A shorter method to protect scripts from bad PATH values is to replace PATH in the script:
export PATH=/usr/bin
Another note is that HP-UX has followed the V.4 filesystem layout standard for more than a decade. There is no /bin or /lib directory. The correct location is /usr/bin and /usr/lib. Your script works because HP has included transition links (man tlinstall) that point legacy directories and filenames to the V.4 standard names. There is no guarentee that any HP-UX system has the links installed (man tlremove) and at some future revision, the default will be no transition links.
And to answer the last question about Linux versus HP-UX: when it comes to startup, shutdown, I/O and system configuration, there are very few standards so assume nothing is common between systems in those areas and you won't be disappointed. Although HP-UX started shipping in the mid-1980's, I doubt that Linus Torvalds consulted HP or HP-UX manuals when he designed Linux back in the early 1990's.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2003 08:46 PM
11-19-2003 08:46 PM
Re: automatic service startup while booting
> 1. ... The file /sbin/init.d/template gives you the details. Startup scripts
I know this script and tried to write mine the same way.
> must also handle shutdown properly, ideally terminating the process(es).
Yes, I also have the other sections in my script. I haven't posted them because they're working fine. ;-)
> 2. You must use nohup to protect your process that you put into the
> background. If you do not, then the end of the script (which is the parent)
> will kill the process.
That was new for me. I've written many scripts for linux and thought I can do it on HP-UX the same way.
> However, in your example, you used nohup to protect your porcess but then
> connected it with a pipe to logger and put logger into
> the background. You need to put the entire command pipe into a subshell
> so it is treated as a single entity:
Sounds very good! I'll try that.
> nohup ($novad | /bin/logger -i -t novad) &
I've tried it, but I got a "syntax error: "(" is not expected"
> A couple of scripting notes:
> ... There is no /bin or /lib directory. The correct
> location is /usr/bin and /usr/lib. Your script works because HP has included
> transition links (man tlinstall) that point legacy directories and filenames
> to the V.4 standard names. There is no guarentee that any HP-UX system has
> the links installed (man tlremove) and at some future revision, the default will
> be no transition links.
Oops, thanks for this hint!
Marco
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2003 02:02 AM
11-20-2003 02:02 AM
Re: automatic service startup while booting
- It is frequently desirable to apply nohup to pipelines or lists of commands. This can be done only by placing pipelines and command lists in a single file, called a shell script. To run the script using nohup:
nohup sh file
Do they mean it is possible to execute "nohup (command1; command2)" wihich is shown in the man page but quits with a synthax error, but not "nohup (command1 | command2)"? I can't belive it. :-(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2003 04:59 AM
11-20-2003 04:59 AM
Solutionconcerning the 'nohup' - problem, you can try something like this:
nohup sh -c "$novad | logger ..."
This should work.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2003 05:14 AM
11-20-2003 05:14 AM
Re: automatic service startup while booting
Attached is a example of a daemon; don't be concerned about what it does but just examine the section of code around the fork(). Note that the real work of the daemon is done by the child process after the fork() and the parent simply exits so that the process (your rc.d stuff) does not hang.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2003 09:25 AM
11-22-2003 09:25 AM
Re: automatic service startup while booting
That is exactly what I was searching for! It works fine and so I do not need another script to execute the two commands. Thank you!
@A. Clay Stephenson:
Yes, you're right. The daemon isn't written by myself and I'm not a real good "perler". But I forwarded the thread to the company the maintain the daemon for us. So they'll say me what to do to let the daemon act like a real daemon. :-)
@all:
Thanks for all your suggestions. Never found a forum like this! Go on with your good hints!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2007 12:09 AM
03-08-2007 12:09 AM