Re: Apache Control : Starting and Stopping Apache from foreign application

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi ,

I am not running apache as a service.
I am running it from another application in a sort of way similar to launching apache from the command line

Regards,
asif

On Fri, Sep 19, 2008 at 2:13 PM, Foo JH <jhfoo-ml@xxxxxxxxxxxxxx> wrote:
If all you wand to do is start and stop the Apache service, why don't you simply do the following on the command line:
net start Apache2
net stop Apache2


Asif M wrote:
Hi all,

I have the following problem :-

I wrote a Apache Control Program in Visual Studio 2003, which does the following
1>. Starts Apache with CreateProcess Call. I run Apache on the command interpreter but not as a service.
2>. Redirects all standard input / output of Apache to the Apache Control Program so that the Apache cmd-line output actually appears in the log window of the control program
3>. Stops Apache

#3 has some problem.
When I try to stop Apache, I try the following
1>. Send a control-C control event to the process the CreateProcess call returns
2>. Close the input pipe which I passed on to Apache during the CreateProcess
3>. Do an TerminateProcess on the process id returned by the CreateProcess call

When I run Apache from the command line, a ctrl+c stops both the running httpd process. However programmatically #1 does not have any effect. It feels that Apache has not received the Ctrl+C I send.

#2 does not have any impact on the running Apache Process either

#3 only kills the primary httpd process running. It does not kill the second process.

Here is the code excerpt :-

/////////////  STARTING APACHE //////////////////////
_tcscpy(_pszCmdLine,m_szApacheBaseDir);
   _tcscat(_pszCmdLine,_T("\\bin\\httpd.exe"));
   _tcscat(_pszCmdLine,_T(" -f "));
   _tcscat(_pszCmdLine,m_szApacheCfgFile);
   _tcscat(_pszCmdLine,_T(" -e debug"));

//..  code to create input/output/error pipes and replicate the handles in the si structure

if (!::CreateProcess(
       NULL,
       (LPTSTR)pszCmdLine,
       NULL, NULL,
       TRUE,
       CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP,
       NULL, NULL,
       &si,
       &pi))
   {
       int n = GetLastError();
       return FALSE;
   }


///////////////////// STOPPING APACHE ///////////////////////
   int j = _tcslen(ctrlC);
   WriteFile(m_hStdinWrite, (LPCTSTR)ctrlC,2, &dwWritten, NULL);
     if ( !GenerateConsoleCtrlEvent(CTRL_C_EVENT,m_dwProcessGroupId))
       j = GetLastError();

   CloseHandle(m_hStdinWrite);
   CloseHandle(m_hStdinRead);

   if (m_dwProcessGroupId)
   {
       _hProcessHandle = OpenProcess(PROCESS_ALL_ACCESS,FALSE,m_dwProcessGroupId);
       if (_hProcessHandle)
       {
           GetExitCodeProcess(_hProcessHandle,&_dwExitCode);
           int n = GetLastError();
           TerminateProcess(_hProcessHandle,1);
       }
       int n = GetLastError();
   }



I would like to know how to send a Ctrl+C event to apache so that I can cleanly / gracefully shutdown Apache.
Any pointers will be extremely appreciated?

Thanks in Advance,
Asif



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux