Re: [PHP] Start/Stop Service from program php

2008-07-27 Thread Daniel Brown
On Sat, Jul 26, 2008 at 11:48 PM, Micah Gersten [EMAIL PROTECTED] wrote:
 Generally, apache runs as www-data.  What was the output of the command?

Actually, Apache generally runs (in order) as nobody, apache,
httpd, or daemon.  Some distros (such as Ubuntu) or control panel
installations (such as Plesk) change this default.  For example,
Ubuntu Feisty uses 'www-data', and Plesk uses a group of 'psacln'.

From PHP, if system access (i.e. - exec(), passthru(), etc.) is
allowed, the easiest way to find out which user you are with Apache on
*NIX is to run this file in a browser:

?php
echo `whoami`;
?

-- 
/Daniel P. Brown
Better prices on dedicated servers:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Start/Stop Service from program php

2008-07-26 Thread Micah Gersten
Generally, apache runs as www-data.  What was the output of the command?

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com


I need write a script execute some command, but try start or stop service
like named, network this don't work

I edit visudo and add the next lines

User_Alias MYGROUP = apache, xyz


[EMAIL PROTECTED] wrote:
 Hi

 I try execute unsucesfull the next code from web page

 ?php
 $cmd1 = shell_exec (sudo /sbin/service named stop);
 echo $cmd1;
 ?

 I need write a script execute some command, but try start or stop service
 like named, network this don't work

 I edit visudo and add the next lines

 User_Alias MYGROUP = apache, xyz
 Cmnd_Alias MYCOMMAND = /sbin/service
 %MYGROUP ALL = MYCOMMAND
 %MYGROUP ALL=(ALL) NOPASSWD: ALL

 But don't work.

 Suggest? Thanks ...

   

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Start/stop daemon using php

2008-02-27 Thread Jochem Maas

David Sveningsson schreef:
Hi, I've written an application in c which I would like to start/stop as 
a daemon in gnu/linux.


The application has the argument --daemon which forks the process and 
exits the parent. Then it setups a SIGQUIT signal handler to properly 
cleanup and terminate. It also maintains a lockfile (with the pid) so 
only one instance is allowed.


So, to start this application I created a php site that calls 
exec(/path/to/binary --daemon  /dev/null 2 /dev/null).


Everything is working so far, but I cannot get the application to 
receive the SIGQUIT when I start using php and exec. Not even manually 
using kill in the shell. It works correctly if I start manually thought.


So, is this possible to do? Doesn't exec allow applications with signal 
handlers? Is there some other way to terminate the application?


there is nothing special about exec that makes working with the kill command
different to anything else, though you might take a look at the posix_kill()
command instead. e.g. posix_kill(`cat /path/to/pidfile`, SIGQUIT);

you say you can't even send SIGQUIT to the daemon using kill on the command 
line,
this suggests the problem lies in the fact that the daemon's signal handler is
not actually working (when the process is daemonized).





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Start/stop daemon using php

2008-02-27 Thread Per Jessen
David Sveningsson wrote:

 Hi, I've written an application in c which I would like to start/stop
 as a daemon in gnu/linux.
 
 The application has the argument --daemon which forks the process
 and exits the parent. Then it setups a SIGQUIT signal handler to
 properly cleanup and terminate. It also maintains a lockfile (with the
 pid) so only one instance is allowed.
 
 So, to start this application I created a php site that calls
 exec(/path/to/binary --daemon  /dev/null 2 /dev/null).
 
 Everything is working so far, but I cannot get the application to
 receive the SIGQUIT when I start using php and exec. Not even manually
 using kill in the shell. It works correctly if I start manually
 thought.

So obviously something is catching the SIGQUIT before it gets to your
daemon.  You mention a php site, so I take it you're running apache. 
In an apache process you then do an exec(something).  I think apache is
probably taking care of the SIGQUIT.

 So, is this possible to do? Doesn't exec allow applications with
 signal handlers? Is there some other way to terminate the application?

Why do you have to kill it with an explicit signal - why not not have a
way of communicating with the process that'll make it terminate when
you raise a flag or send it a message or something. 


/Per Jessen, Zürich

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Start/stop daemon using php

2008-02-27 Thread @4u
Hi,

You might consider D-BUS for your application and the D-BUS PHP binding
which is available since some days too. This would allow you to start /
stop your C application in a far more secure way than the suggested one.

Please have a look at my original release annoucement at the D-BUS
mailing list:

http://lists.freedesktop.org/archives/dbus/2008-February/009363.html

as well as the download URL:

https://sourceforge.net/project/showfiles.php?group_id=17176package_id=68954

Even if the application runs on Windows you might be able to use D-BUS
for communication.

Daniel Brown schrieb:
 On Wed, Feb 27, 2008 at 7:51 AM, David Sveningsson [EMAIL PROTECTED] wrote:
 Hi, I've written an application in c which I would like to start/stop as
  a daemon in gnu/linux.

  The application has the argument --daemon which forks the process and
  exits the parent. Then it setups a SIGQUIT signal handler to properly
  cleanup and terminate. It also maintains a lockfile (with the pid) so
  only one instance is allowed.

  So, to start this application I created a php site that calls
  exec(/path/to/binary --daemon  /dev/null 2 /dev/null).
 
 You can (and should) write this out like so:
 ?
 exec(/path/to/binary --daemon  /dev/nul 21,$ret,$err);
 ?
 
 The  means to append to the end of a file.  You can use  on
 /dev/null, since it's not a file, but just a black hole, but you may
 want to get into the habit of redirecting and appending.  The 21
 redirects channel 2 (STDERR) to channel 1 (STDOUT) so that all output
 in this case is sent to /dev/null.  For any output that would
 otherwise be generated, $ret will hold STDOUT data, and $err will hold
 the STDERR code.
 
  Everything is working so far, but I cannot get the application to
  receive the SIGQUIT when I start using php and exec. Not even manually
  using kill in the shell. It works correctly if I start manually thought.

  So, is this possible to do? Doesn't exec allow applications with signal
  handlers? Is there some other way to terminate the application?
 
 You may want to launch it from a BASh script.  I had written out
 an example for someone on this list at the beginning of the month.
 Feel free to check it out and use it, or use any part of it:
 
 [Download] http://pilotpig.net/code-library/daemonize.sh
 [View Source] http://pilotpig.net/code-library/source.php?f=daemonize.sh
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Start/stop daemon using php

2008-02-27 Thread Daniel Brown
On Wed, Feb 27, 2008 at 7:51 AM, David Sveningsson [EMAIL PROTECTED] wrote:
 Hi, I've written an application in c which I would like to start/stop as
  a daemon in gnu/linux.

  The application has the argument --daemon which forks the process and
  exits the parent. Then it setups a SIGQUIT signal handler to properly
  cleanup and terminate. It also maintains a lockfile (with the pid) so
  only one instance is allowed.

  So, to start this application I created a php site that calls
  exec(/path/to/binary --daemon  /dev/null 2 /dev/null).

You can (and should) write this out like so:
?
exec(/path/to/binary --daemon  /dev/nul 21,$ret,$err);
?

The  means to append to the end of a file.  You can use  on
/dev/null, since it's not a file, but just a black hole, but you may
want to get into the habit of redirecting and appending.  The 21
redirects channel 2 (STDERR) to channel 1 (STDOUT) so that all output
in this case is sent to /dev/null.  For any output that would
otherwise be generated, $ret will hold STDOUT data, and $err will hold
the STDERR code.

  Everything is working so far, but I cannot get the application to
  receive the SIGQUIT when I start using php and exec. Not even manually
  using kill in the shell. It works correctly if I start manually thought.

  So, is this possible to do? Doesn't exec allow applications with signal
  handlers? Is there some other way to terminate the application?

You may want to launch it from a BASh script.  I had written out
an example for someone on this list at the beginning of the month.
Feel free to check it out and use it, or use any part of it:

[Download] http://pilotpig.net/code-library/daemonize.sh
[View Source] http://pilotpig.net/code-library/source.php?f=daemonize.sh

-- 
/Dan

Daniel P. Brown
Senior Unix Geek
? while(1) { $me = $mind--; sleep(86400); } ?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Start/stop daemon using php

2008-02-27 Thread David Sveningsson

@4u skrev:

Hi,

You might consider D-BUS for your application and the D-BUS PHP binding
which is available since some days too. This would allow you to start /
stop your C application in a far more secure way than the suggested one.

Please have a look at my original release annoucement at the D-BUS
mailing list:

http://lists.freedesktop.org/archives/dbus/2008-February/009363.html

as well as the download URL:

https://sourceforge.net/project/showfiles.php?group_id=17176package_id=68954


D-BUS sounds excellent, I will definitely try it out. I have never coded 
D-BUS myself but I don't think it would be too hard.




Even if the application runs on Windows you might be able to use D-BUS
for communication.



Currently neither the application or the frontend is planned to support 
windows as it is already full of very unix specific code.


--


//*David Sveningsson [eXt]*

Freelance coder | Game Development Student
http://sidvind.com

Thou shalt make thy program's purpose and structure clear to thy fellow 
man by using the One True Brace Style, even if thou likest it not, for 
thy creativity is better used in solving problems than in creating 
beautiful new impediments to understanding.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Start/stop daemon using php

2008-02-27 Thread David Sveningsson

Per Jessen skrev:

David Sveningsson wrote:


Hi, I've written an application in c which I would like to start/stop
as a daemon in gnu/linux.

The application has the argument --daemon which forks the process
and exits the parent. Then it setups a SIGQUIT signal handler to
properly cleanup and terminate. It also maintains a lockfile (with the
pid) so only one instance is allowed.

So, to start this application I created a php site that calls
exec(/path/to/binary --daemon  /dev/null 2 /dev/null).

Everything is working so far, but I cannot get the application to
receive the SIGQUIT when I start using php and exec. Not even manually
using kill in the shell. It works correctly if I start manually
thought.


So obviously something is catching the SIGQUIT before it gets to your
daemon.  You mention a php site, so I take it you're running apache. 
In an apache process you then do an exec(something).  I think apache is

probably taking care of the SIGQUIT.


Yes, I am using apache (forgot to mention it). Is there a way to stop 
apache from catching the signals?





So, is this possible to do? Doesn't exec allow applications with
signal handlers? Is there some other way to terminate the application?


Why do you have to kill it with an explicit signal - why not not have a
way of communicating with the process that'll make it terminate when
you raise a flag or send it a message or something. 


Currently I have no other way of communicating than a mysql database (it 
passes data that needs processing) so I thought it would be quick and 
easy to just raise a signal. I read in another mail about D-BUS which I 
think would be a better way of communication.





/Per Jessen, Zürich




--


//*David Sveningsson [eXt]*

Freelance coder | Game Development Student
http://sidvind.com

Thou shalt make thy program's purpose and structure clear to thy fellow 
man by using the One True Brace Style, even if thou likest it not, for 
thy creativity is better used in solving problems than in creating 
beautiful new impediments to understanding.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Start/stop daemon using php

2008-02-27 Thread Per Jessen
David Sveningsson wrote:

 Per Jessen skrev:
 So obviously something is catching the SIGQUIT before it gets to your
 daemon.  You mention a php site, so I take it you're running
 apache.
 In an apache process you then do an exec(something).  I think apache
 is probably taking care of the SIGQUIT.
 
 Yes, I am using apache (forgot to mention it). Is there a way to stop
 apache from catching the signals?

Hmm, when your daemon does a fork(), it should be perfectly capable of
installing its own signal handlers.  Is SIGQUIT enabled?  Check your
signal mask. 


/Per Jessen, Zürich

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] start/stop deamon

2004-04-08 Thread Jay Blanchard
[snip]


can some body tell me how to start/stop a deamon ( eg: dhcpd )
from php ?
and also can v apply that same method to start/stop a some
script by php ? 
 
[/snip]
 
http://www.php.net/exec 
 



RE: [PHP] Start / Stop

2002-06-24 Thread Bruce Karstedt

Timestamp it at the beginning and the end.

Bruce Karstedt
President
Technology Consulting Associates, Ltd.
Tel: 847-735-9488
Fax: 847-735-9474


-Original Message-
From: Chris Kay [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 24, 2002 6:57 PM
To: PHP General List
Subject: [PHP] Start / Stop
Importance: Low



Anyone have some tips on the best way to make a 

Script started @ 5:45pm

Script ended @ 5:50pm 

Script?

---
Chris Kay
Technical Support - Techex Communications 
Website: www.techex.com.au   Email: [EMAIL PROTECTED]
Telephone: 1300 88 111 2 - Fax: (02) 9970 5788 
Address: Suite 13, 5 Vuko Place, Warriewood, NSW 2102 
Platinum Channel Partner of the Year - Request DSL - Broadband for Business
---

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php