?
Solved

Restarting name server

Posted on 1998-07-20
15
Medium Priority
?
181 Views
Last Modified: 2010-03-05
I am trying to create a web interface for adding new domain names to a name server.  Creating the files and transferring them to the server is relatively easy using Cold Fusion but I am not sure how I could restart the name server after the process has been completed.  Is it possible to use a Perl script, called from the web browser, to restart the name server?
0
Comment
Question by:bsufs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +3
15 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1208530
Is it possible to restart the name server without perl?
0
 

Author Comment

by:bsufs
ID: 1208531
To restart the name server you have to find out its process ID and send a kill -HUP signal.  I was wondering if it is possible to send this signal using a perl script.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1208532
Perl has a kill function.
Does the name server accept kills from the user under which the http sertver runs scripts?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:bsufs
ID: 1208533
I don't know.  Could you tell me a bit more about the Perl kill function?
0
 
LVL 84

Expert Comment

by:ozo
ID: 1208534
perldoc perlfunc
 . . . .
                 kill LIST
                         Sends  a signal to a list of processes.  The first
                         element of the list must be the  signal  to  send.
                         Returns   the  number  of  processes  successfully
                         signaled.
                             $cnt = kill 1, $child1, $child2;
                             kill 9, @goners;

                         Unlike in the shell, in  Perl  if  the  SIGNAL  is
                         negative,  it  kills  process  groups  instead  of
                         processes.   (On  System  V,  a  negative  PROCESS
                         number  will  also kill process groups, but that's
                         not portable.)  That means you usually want to use
                         positive not negative signals.  You may also use a
                         signal name in quotes.  See the section on Signals
                         in the perlipc manpage for details.

0
 
LVL 2

Expert Comment

by:JYoungman
ID: 1208535
Most versions of named come with a "named.restart" script, which is installed in /usr/sbin on my system here.  It contains:-

exec /usr/sbin/ndc restart

It's better top call named.restart than "ndc", I think.

0
 

Author Comment

by:bsufs
ID: 1208536
How would I call the named.restart script from a web browser?
0
 
LVL 84

Expert Comment

by:ozo
ID: 1208537
system('/usr/sbin/named.restart');
0
 

Expert Comment

by:bjornh
ID: 1208538
Be careful with this solution because the suid bit on named.restart must be on and I think exploits exist for some versions. Also, some webservers do not execute (root)-suid scripts, because of the potential security problems.

I choose to place a semaphore in a directory. A cronscript checks periodically and calls named.restart (and removes the sem) if the sem is there.
0
 

Author Comment

by:bsufs
ID: 1208539
Thanks very much, bjornh.  This would seem the best way to do it.  I would be very grateful if you could provide me with more details about the semaphore and the cronscript (I am not an expert on Unix).

Thanks very much.
0
 

Expert Comment

by:bjornh
ID: 1208540
This is the cronscript, it runs every minute:

#!/usr/bin/perl
if (-f "/tmp/named.restart")
{
        system ("/usr/sbin/named.restart");
        unlink ("/tmp/named.restart");
        open (TEMP, ">/tmp/named.restarted");
        close <TEMP>;
        system ("chown <webserveruser> /tmp/named.restarted");
}

Dont forget to chown the sem to the webserver-user otherwise the script wont be able to delete the named.restarted semaphore.

The cgi-script:

open (RESTART, ">/tmp/named.restart");
close (RESTART);

until ( -f "/tmp/named.restarted") {
        sleep 1
}

unlink ("/tmp/named.restarted");
unlink ("/tmp/named.restart");

Good luck, Bjorn
0
 
LVL 3

Expert Comment

by:marcelofr
ID: 1208541
bjornh, I hope you don't have users in your linux box... what if someone does:

while :;do rm -f /tmp/restart;done &

Don't use /tmp. Preferably set a 700 directory somewhere else and give it to <webserveruser> ...
0
 
LVL 3

Expert Comment

by:marcelofr
ID: 1208542
bjornh, I hope you don't have users in your linux box... what if someone does:

while :;do rm -f /tmp/restart;done &

Don't use /tmp. Preferably set a 700 directory somewhere else and give it to <webserveruser> ...
0
 

Expert Comment

by:bjornh
ID: 1208543
You are right. /tmp is open for everybody. We dont have much shellusers on this machine but it still is dangerous.

Thanks!
0
 

Accepted Solution

by:
hedj earned 400 total points
ID: 1208544
I would use the qx command to pipe out a command to the operating system.  For example:

#First, call the system and gain the process ID
$process = qx{"ps -aux | grep named"}

# Then cut out unnecessary data

# Next send a HUP signal to the named process
$results = qx{"kill -HUP ".$process}

That should send a restart signal to the named server.  If you need to start it from scratch, just do a

$results = qx{"/usr/sbin/named"}


0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question