Shell script

pilpelet

Verified User
Joined
Oct 12, 2003
Messages
108
Hi to all ,


Can someone post a shell script that checks if bind service is currently running ,

Basicly its not for DA server , i upgraded the server from 8 to 9 then it stoped working at startup , also cant seem to work
with rndc even when the rndc configured ok , so ill do something else for now by checking if named is running if not run
named -u named

So it will all work for now .

I ill put a cron to run named -u named every say half hour it will creat new procces each time .

Pathetic i know .

Thanks in advance ,


<>
EDIT

Iv also run :
chkconfig --level 2345 named reset
chkconfig --level 2345 named on

Not starting after the server boots ,
Its only runs after running named or named -u named etc ..

Any ideas ,
 
Last edited:
Once it starts, does it stay running, or does it shut down?

Do you have a file at /etc/rc.d/init.d/named ?

Do you have a file at /etc/rc.d/rc3.d/S??named ?

Do you have a file at /etc/rc.d/rc3.d/K??named ?

(where ?? is replaced by two digits)

This post really belongs on a BIND specific forum, but let's see if we can find a simple answer.

Jeff
 
> Do you have a file at /etc/rc.d/init.d/named ?

Yes

> Do you have a file at /etc/rc.d/rc3.d/S??named ?

s55named exist

> Do you have a file at /etc/rc.d/rc3.d/K??named ?

k??named is not there

After starting named it works great without interuptions .

Thanks for trying to help ill describe it ferther ,

rndc doesnt work , i gave up on this , ill get to that later
for now its a second DNS so i just need it fully functional .

Service named start , doesnt work all the time ,
Service named stop , stops the service ,

the only command that starts it though is named or with u - g etc .


Thanks ,
 
Jhon hi ,

By looking at it , its looks like something i allready have ,
Basicly by looking at the code it uses "rndc" to start , reload etc ,
but rndc for some resone doesnt function currectly .
So basicly i need to go arroung this and not use rndc at all .

some function(as cron) to just check if the server runs , if not and only then will run named , couse if ill configure the command named to run as a cron it will start a new proccess each time , after a day there will be 100 named proccesses , iv allready checked this option .

Thanks ,

<>
Edit

Also named installed in /usr/local/sbin and not /usr/sbin


<>>>>>>>>>>>>>>>>>>


Will this be ok :


#!/bin/bash

. /etc/rc.d/init.d/functions

. /etc/sysconfig/network

RETVAL=0
prog="named"

start() {
# Start daemons.
if [ -n "`/sbin/pidof named`" ]; then
echo -n $"$prog: already running"
return 1
fi
echo -n $"Starting $prog: "
if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then
OPTIONS="${OPTIONS} -t ${ROOTDIR}"
fi
# Since named doesn't return proper exit codes at the moment
# (won't be fixed before 9.2), we can't use daemon here - emulate
# its functionality
base=$prog
named -u named ${OPTIONS}
RETVAL=$?
usleep 100000
if [ -z "`/sbin/pidof named`" ]; then
# The child processes have died after fork()ing, e.g.
# because of a broken config file
RETVAL=1
fi
[ $RETVAL -ne 0 ] && failure $"$base startup"
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/named && success $"$base startup"
echo
return $RETVAL
}


exit $?


As hourly cron till rndc function .

The perpose is to check if it not running and only if then start it .

Thanks ,
 
Last edited:
Hi ,

I managed to fix the cron with the shell jhon posted (it was there in the fiest place) andajusting named path, now it checkes if named runs ok , if not it start it .

For the start up problem , it still doesnt start , in case it will help resolve it this is a message im getting to root :

<>>>>>>>>>

Starting named: /bin/bash: line 45: emulate: command not found
/bin/bash: line 57: success: command not found
/bin/bash: line 58: named startup: command not found

/bin/bash: line 60: return: can only `return' from a function or sourced script

<>

So i get it its something with bash , but its not ajustable ?

Thanks for any Ideas ,
 
It's not bash.

You uploaded the script incorrectly, and you've got line-endings that aren't in the original.

Match your uploaded script with the original for line endings.

Jeff
 
Jeff hello ,

Actually i didnt upload anything , like i said the script was there i just ajusted the path to bind and to rndc .

The rndc works now also the cron and the script , it just the startup issue wich get the error with bash i sent in the erly post .

Thanks ,

<>>>>>>>>>>
EDIT :

I mannged to fix it by adding a simple :

/etc/rc.d/init.d/named

to

/etc/rc.d/rc.local
wich run commands after the cinventional scripts starts .

Well a simple fix to that after all .

I posted the fix couse im quite sure this file can be of use by others that wants to start scripts at startup without hard codding the OS .

Tested on fedora only as for now .
 
Last edited:
Then perhaps your editing the file somehow munged the line endings.

These lines:
Code:
Starting named: /bin/bash: line 45: emulate: command not found
/bin/bash: line 57: success: command not found
/bin/bash: line 58: named startup: command not found
show that the system is expecting to find commands that don't exist.

If these words appear at the beginning of lines when the script is executed you'll get these errors.

On lines 45, 57, and 58.

If you can't find the lines in question then post the script here.

Thanks.

Jeff
 
Reading your edited post I get the impression you created a workaround because your /etc/rc.d/init.d/named file is broken.

If you'd rather do that than fix what's broken, and have a nonstandard distribution, that's fine as long as it works for you.

Note however that you've most likely started named as root (which is considered insecure), and haven't added any of the options the original startup method uses.

Jeff
 
Hi ,

The named script is not broken its starting it ok ,
It just not strating on os reload but with the fix its ok ,

It doesnt matter how it start it as long as it coming up on system boot . So its not realy leaving problems with the distro....

Its just starting bind .

Regarding the securty matter you mentioned , ofcourse ,

Name -u bind in jail root .

Thanks ,
 
You've got a script that's where it's supposed to be that's not doing what it's supposed to do.

You've created a workaround by putting code into another script.

So how can you say the first script isn't broken?

Jeff
 
Jeff hi ,

You tell me ,

By starting named via :
/etc/rc.d/init.d/named directly it starts

(isnt it the script that suppose to start it on system boot ?)
or there is another thing i should look into ?

So the script is ok , but its not starting automaticly unless
Using the fix wich is adding this acommand to rc.local

Im basicly an NT admin so its realy confusing to me all this enteries to just start a service on start up .
But i do like and work with linux .

It should be more clear i think .


Thanks ,
 
pilpelet said:
By starting named via :
/etc/rc.d/init.d/named directly it starts
I hope not. It shouldn't start unless you type:

# /etc/rc.d/init.d/named start

or on RedHat systems:

# service named start

(note that you don't type the "#"; it's just to show you that you have to do it as root)
(isnt it the script that suppose to start it on system boot ?)
or there is another thing i should look into ?
No, that's the script that will start it on system start.

Perhaps I'm misunderstanding you.

If you stop named, can you restart it with either of these commands? If so, then it should start automatically on system startup.
So the script is ok , but its not starting automaticly unless
Using the fix wich is adding this acommand to rc.local
Adding a line to rc.local isn't a fix for anything; it's just another way to start a program; one that happens after all the other startup scripts are run.

Starting named last means your startup may take a lot longer than it should; many other services look for named to be running as they start.
Im basicly an NT admin so its realy confusing to me all this enteries to just start a service on start up .
:rolleyes: Oh, why didn't you say so.

The scripts in /etc/rc.d/init.d/ are the scripts that the system starts itself automatically, wihtout you seeing them (for example, the script that starts the entire Windowing process on Windows NT).

rc.local is the equivalent of autoexec.bat; it runs last.

Jeff
 
Jeff Hi ,

I liked the autoexec.bat comparation ,

Let me get this stright a little :

Any script that exist in /etc/rc.d/init.d/ will lunch at startup as a service and will be availble to the command

service ... stop / start etc

E.g - if there is a file named test , it will try to start at boot
and will be avialble via service test start / stop .

Thanks ,
 
Back
Top