----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files.  Don't make us guess your problem!!!
----------------------------------------------------------------


My MAIN OBJECTIVE is to RESTART the apache web server through a servlet.
(web interface).Is it possible ?

My solution is as follows

I have written a servlet which invokes a script to restart the web server.

The Script which i have Written and want to invoke does the foll functions
1)StopServer
           #!/usr/local/bin/perl -w
          my $PIDValue = `cat /usr/apache-d/logs/httpd.pid` ;
          my $KillResult = `kill -TERM $PIDValue` ;
2)sleep 10
3)StartServer
 /usr/local/apache/bin/httpd -f /usr/apache-d/conf/httpd.conf.

Like Fernando and kevin had suggested , I had to change the
permission of the files I wanted to access through the servlets.
The ordinary commands like rm,cp,mv ,sleep etc will work fine when
you have given the permissions  to the files you are using as arguments in
the above commands.
But in my case the ordinary user has to execute a command to delete a
process(kill)
ie httpd(StartServer) which was created by the root.
This someone told me that ,it is generally not possible but for the use of
setuid.
I tried using setuid with StopServer and then also the error reported was
Permission denied for Kill.I am using Solaris OS and someone told me that
Sun OS ie ksh      does not support   setuid


Please tell me whether there is any alternate solution or is there any
solution to
the way i have implemented it.

regards
Hiren

-----Original Message-----
From: Kevin Macclay <[EMAIL PROTECTED]>
To: Java Apache Users <[EMAIL PROTECTED]>
Date: Thursday, April 13, 2000 10:18 PM
Subject: Re: Batch Script running problem in apache


>----------------------------------------------------------------
>BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
>WHEN YOU POST, include all relevant version numbers, log files,
>and configuration files.  Don't make us guess your problem!!!
>----------------------------------------------------------------
>
>Keep in mind that when you execute a command in your code you are executing
>it as the user you started the JVM with.  If you have ApacheJServ in
>automatic mode, this will be the same user you started Apache as (usually
>user "nobody").  But if you start ApacheJServ in manual mode, it will be
the
>same user you ran your manual script as.  So to understand what's
happening,
>figure out which user/group JServ is running as based on this and in Unix,
>use chmod or chown to allow proper access to that user/group.  Use user
root
>to change these permissions from Unix and don't change them from inside
your
>code -- it could be that the user you're executing these commands as
doesn't
>have the access privilege to do a chmod on the file.
>
>Kevin
>
>-----Original Message-----
>From: Hiren Shah <[EMAIL PROTECTED]>
>To: Java Apache Users <[EMAIL PROTECTED]>
>Date: Thursday, April 13, 2000 11:44 AM
>Subject: Re: Batch Script running problem in apache
>
>
>>----------------------------------------------------------------
>>BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
>>WHEN YOU POST, include all relevant version numbers, log files,
>>and configuration files.  Don't make us guess your problem!!!
>>----------------------------------------------------------------
>>
>>Hi
>>
>>Fernando and youself Kevin were quite right on the permissions issue.
>>I implemented the code given by kevin and the error log showed that the
>>permission denied to the batch script.
>>
>>I have added the following code but stil it says that permission on t is
>>denied.
>>
>> sPath = new String("/usr/apache-d/htdocs/WebPages/Servlets/Admin");
>>
>> sPermForT = new String("chmod  2777" + sPath + "t");
>> iResult = myRuntime.exec(sPermForT).waitFor();
>>
>> sPermCommand = new String("chmod 2777" + sPath + "cop.bat");
>> iResult = myRuntime.exec(sPermCommand).waitFor();
>>
>>My test batch script is just
>>
>>mv  t   t1
>>
>>Is there any additional settings to be done in the jServ?
>>Please reply
>>
>>regards
>>Hiren
>>
>>-----Original Message-----
>>From: Kevin Macclay <[EMAIL PROTECTED]>
>>To: Java Apache Users <[EMAIL PROTECTED]>
>>Date: Thursday, April 13, 2000 7:15 PM
>>Subject: Re: Batch Script running problem in apache
>>
>>
>>>----------------------------------------------------------------
>>>BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
>>>WHEN YOU POST, include all relevant version numbers, log files,
>>>and configuration files.  Don't make us guess your problem!!!
>>>----------------------------------------------------------------
>>>
>>>I agree with Fernando, it's probably a permissions problem.  Often, I've
>>>found that capturing the output from the error stream of the process is
>>>helpful.  Otherwise you may be blind as to what the actual error is.
>Also,
>>>standard output may give you some useful messages.  Here is sample code
we
>>>use to execute a unix script and print out everything from the error
>>stream.
>>>
>>>                String command = { "/bin/csh", "-c",
>>>"/some/dir/scriptname" }
>>>                Process child = Runtime.getRuntime().exec(command);
>>>
>>>                // Wait for process to finish.
>>>                try {
>>>                    child.waitFor();
>>>                }
>>>                catch(InterruptedException e) {}
>>>
>>>                // Print out error messages.
>>>                BufferedReader childin = new BufferedReader(new
>>>InputStreamReader(child.getErrorStream()));
>>>
>>>                String line = "";
>>>                while ((line = childin.readLine()) != null)
>>>                    out.println(line + "<br>");
>>>
>>>                childin.close();
>>>
>>>Kevin
>>>
>>>-----Original Message-----
>>>From: Hiren Shah <[EMAIL PROTECTED]>
>>>To: [EMAIL PROTECTED]
>>><[EMAIL PROTECTED]>
>>>Date: Thursday, April 13, 2000 6:57 AM
>>>Subject: Batch Script running problem in apache
>>>
>>>
>>>>----------------------------------------------------------------
>>>>BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
>>>>WHEN YOU POST, include all relevant version numbers, log files,
>>>>and configuration files.  Don't make us guess your problem!!!
>>>>----------------------------------------------------------------
>>>>
>>>>Hi
>>>>
>>>>I am using Apache Web Server .One of my servlets needs to execute a
Batch
>>>>script(unix).The code for Invoking the batch script is as follows ie
>>>>
>>>> try{
>>>>
>>>> Runtime myRuntime = Runtime.getRuntime();
>>>> String sCommand,sPath;
>>>> sPath="/usr/apache-d/htdocs/WebPages/Servlets/Admin/";
>>>>
>>>> sCommand = new String("sh " + sPath + "restart.bat");
>>>> int iResult;
>>>>
>>>> iResult = myRuntime.exec(sCommand).waitFor();
>>>>  }
>>>> catch(Exception e)
>>>> {
>>>>     MyUtil.errorLog("Error in executing batch script");
>>>> }
>>>>
>>>>
>>>>where restart.bat is my shell script.
>>>>When i try the above code in a normal java problem without apache web
>>>server
>>>>it runs fine and executes the shell script.
>>>>
>>>>Please tell how to call the batch script from a servlet invoked by the
>>>>apache web server.
>>>>
>>>>regards
>>>>Hiren
>>>>
>>>>
>>>>
>>>>
>>>>--
>>>>--------------------------------------------------------------
>>>>Please read the FAQ! <http://java.apache.org/faq/>
>>>>To subscribe:        [EMAIL PROTECTED]
>>>>To unsubscribe:      [EMAIL PROTECTED]
>>>>Archives and Other:  <http://java.apache.org/main/mail.html>
>>>>Problems?:           [EMAIL PROTECTED]
>>>>
>>>
>>>
>>>
>>>--
>>>--------------------------------------------------------------
>>>Please read the FAQ! <http://java.apache.org/faq/>
>>>To subscribe:        [EMAIL PROTECTED]
>>>To unsubscribe:      [EMAIL PROTECTED]
>>>Archives and Other:  <http://java.apache.org/main/mail.html>
>>>Problems?:           [EMAIL PROTECTED]
>>>
>>>
>>
>>
>>
>>--
>>--------------------------------------------------------------
>>Please read the FAQ! <http://java.apache.org/faq/>
>>To subscribe:        [EMAIL PROTECTED]
>>To unsubscribe:      [EMAIL PROTECTED]
>>Archives and Other:  <http://java.apache.org/main/mail.html>
>>Problems?:           [EMAIL PROTECTED]
>>
>
>
>
>--
>--------------------------------------------------------------
>Please read the FAQ! <http://java.apache.org/faq/>
>To subscribe:        [EMAIL PROTECTED]
>To unsubscribe:      [EMAIL PROTECTED]
>Archives and Other:  <http://java.apache.org/main/mail.html>
>Problems?:           [EMAIL PROTECTED]
>



--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to