Solved

Restarting name server

Posted on 1998-07-20
15
175 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
  • 4
  • 4
  • 3
  • +3
15 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Is it possible to restart the name server without perl?
0
 

Author Comment

by:bsufs
Comment Utility
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
Comment Utility
Perl has a kill function.
Does the name server accept kills from the user under which the http sertver runs scripts?
0
 

Author Comment

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

Expert Comment

by:ozo
Comment Utility
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
Comment Utility
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
Comment Utility
How would I call the named.restart script from a web browser?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 84

Expert Comment

by:ozo
Comment Utility
system('/usr/sbin/named.restart');
0
 

Expert Comment

by:bjornh
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 200 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Sending email via Perl on Windows 3 124
perl script help 5 229
PERL - Find newest folder 12 100
Formatting stings with pack and printf in perl 5 49
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now