Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

Restarting name server

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
bsufs
Asked:
bsufs
  • 4
  • 4
  • 3
  • +3
1 Solution
 
ozoCommented:
Is it possible to restart the name server without perl?
0
 
bsufsAuthor Commented:
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
 
ozoCommented:
Perl has a kill function.
Does the name server accept kills from the user under which the http sertver runs scripts?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
bsufsAuthor Commented:
I don't know.  Could you tell me a bit more about the Perl kill function?
0
 
ozoCommented:
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
 
JYoungmanCommented:
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
 
bsufsAuthor Commented:
How would I call the named.restart script from a web browser?
0
 
ozoCommented:
system('/usr/sbin/named.restart');
0
 
bjornhCommented:
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
 
bsufsAuthor Commented:
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
 
bjornhCommented:
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
 
marcelofrCommented:
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
 
marcelofrCommented:
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
 
bjornhCommented:
You are right. /tmp is open for everybody. We dont have much shellusers on this machine but it still is dangerous.

Thanks!
0
 
hedjCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 4
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now