Operating System - HP-UX
1844882 Members
1558 Online
110233 Solutions
New Discussion

Re: Startup scripting problem

 
SOLVED
Go to solution
Robin King_1
Regular Advisor

Startup scripting problem

I'm attempting to create the startup script necessary to start the Patrol agent everytime the server boots. I'm having a bit of a problem with it though.

I have created /sbin/init.d/patrol. I used /sbin/init.d/template to create it, and have attached a copy of the file.
I have a link /sbin/rc3.d/S991patrol, and I have a file /etc/rc.config.d/patrol, that contains the line PATROL_AGENT=1.
The patrol agent doesn't seem to be working during startup, I've checked the permissions, and ownership of all the files.

I can use the scripts to manually start the agent, but I have to export the variable PATROL_AGENT=1 for the script to work.

Can anyone suggest why it's not working?

Thanks
16 REPLIES 16
Mark Grant
Honored Contributor

Re: Startup scripting problem

Does the "patrolagent" application itself require that $PATROL_AGENT is set to 1? If so then the startup script should export this variable before starting the application.

Do you get the message echo "Starting the patrol agent" when you boot?

I also assume you run, by default, in run level 3

Never preceed any demonstration with anything more predictive than "watch this"
MarkSyder
Honored Contributor

Re: Startup scripting problem

I think there's a typo in your script. The script is looking for /etc/rc.config/patrol, but your posting says the directory is /etc/rc.config.d

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Mark Grant
Honored Contributor

Re: Startup scripting problem

Good spot mark :)
Never preceed any demonstration with anything more predictive than "watch this"
Hoefnix
Honored Contributor

Re: Startup scripting problem

You could find the error message that your script generates also in the /etc/rc.log file.
Grep on patrol.

You say it starts when using the /sbin/init.d/patrol script? I would expect the typo mark found was also generating an error on the screen.

Regards,

Peter
MarkSyder
Honored Contributor

Re: Startup scripting problem

Thanks Mark.

Too many Marks in this thread! It's getting confusing!

Mark (Syder that is)
The triumph of evil requires only that good men do nothing
Robin King_1
Regular Advisor

Re: Startup scripting problem

Yep, very good spot Mark. It's one of those "I've been looking at this for too long" problems. I wouldn't have spotted that in a month of Sundays. The script works manually with out any problems. I'll try a test reboot to check everything is ggod.
Robin King_1
Regular Advisor

Re: Startup scripting problem

It works perfectly now running it manually, but it won't start during boot up.
A. Clay Stephenson
Acclaimed Contributor

Re: Startup scripting problem

If it works fine manually now then this must be an environment problem. You need to make certain that your init.d script sets and exports any needed environment variables including PATH. Typically, needed environment vars are placed in the rc.config.d file but could easily be set in the start) and stop) sections of your init.d script.
If it ain't broke, I can fix that.
Robin King_1
Regular Advisor

Re: Startup scripting problem

I'm not sure what variables it could need. I have the full path in the script for the executable.
Tom Smith_9
Frequent Advisor

Re: Startup scripting problem

Are you starting Patrol with a "nohup" from the startup script?

I have been burned by that one in the past.

MarkSyder
Honored Contributor

Re: Startup scripting problem

Have you set up an error log?

Let us say your error log is in the /tmp directory and has the imaginative name of error.log (that's what I'd call it anyway!). After every if statement put 2 > /tmp/error.log e.g.

if condition > /dev/null 2>/tmp/error.log
then

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
UNIXTEK
Frequent Advisor
Solution

Re: Startup scripting problem

Try this start/stop script

#!/bin/sh
#
# PatrolAgent - PATROL Agent startup script for all shell users.

PATH=${PATH}:/bin
TMP_PATROL=/tmp/patrol3411
export TMP_PATROL
case "$1" in
'start_msg')
echo "Start Patrol Agent version 3.4.11"
;;
'stop_msg')
echo "Stop Patrol Agent"
;;
'start')
BASEPATH=/usr/users/patrol/3.4.11
cd $BASEPATH
. ./patrolrc.sh
if [ ! -d "${HOME-}" ]
then
HOME=$PATROL_HOME
export HOME
if [ ! -d "$HOME" ]
then
mkdir $HOME
fi
fi
PATH=$PATROL_HOME/bin:$PATH
cd $PATROL_HOME/bin
nohup PatrolAgent -p 3182 &
;;
'stop')
pid=`/bin/ps -e | grep PatrolAgent | grep -v grep | sed -e 's/^ *//' -e 's/ .*//' | head -1`
kill -9 $pid
;;
*)
echo "usage: $0 {start|stop}"
;;
esac
Bill Hassell
Honored Contributor

Re: Startup scripting problem

If Patrol starts from a shell prompt, the problem is environment. Do not assume that $PATH and any Patrol-specific variables are set. Intstead, put this at the start of your script:

export PATH=/usr/bin

Amd if you know of any Patrol variables, define them too. Now try the script from a shell prompt. To see error messages and scripting problems, use -x as in:

sh -x /sbin/init.d/patrol start

(I assume that you have already tested the 4 parameters: start stop start_msg stop_msg). Now you can see everything as the shell traces execution. You should also look in /eetc/rc.log for the results of all startup scripts. To debug during a real startup, put the command:

set -x

in your startup script at the top. All the trace output will go to /etc/rc.log.


Bill Hassell, sysadmin
Robin King_1
Regular Advisor

Re: Startup scripting problem

Steve

Thanks very much, that script worked great. I'll have a look through and will try and work out what I was missing.
Daryl Much
Frequent Advisor

Re: Startup scripting problem

just wanted to add to this thread that I was having similar problem, patrol would start manually (via change to init level or by directly executing the /sbin/init.d script) but it would not start upon reboot. Info would be writen to /etc/rc.log with no apparent errors. Once I put 'nohup' in init script it starts at reboot properly. This seems to have broken after I installed a patch bundle (but I'm not certain)

HTH,

Chuck Davis
Bill Hassell
Honored Contributor

Re: Startup scripting problem

This symptom (ie, requires nohup) means that the patrol code is not running as a daemon, that is, it does not detach itself from the current parent. What is happening is that once all the rc scripts are run, the parent rc process terminates and all children are automatically killed. nohup essentially 'absorbs' the kill signal, thus protecting patrol. The Patrol documents should talk about how to start the program at bootup and get it attached to init. They might tell you to put the startup script into inittab with a run-once option at the desired run level.


Bill Hassell, sysadmin