Reputation: 3740
I am doing a system maintenance script that is checking the status of various services (memcached, sphinx, etc)
I would like to start the service from php script if it is down...
I managed to do it for memcache like this:
$command = 'memcached -d -m 800 -l 127.0.0.1 -p 11211 -u root start';
$dummy = system($command, $retval);
it is working GREAT...
now I'd like to do the same thing for SphinxSearch service
I tried
$command = 'service searchd start';
but got no result... and I read that I need sudo for this, so I did
$command = 'sudo service searchd start';
and even
$command = '/usr/bin/sudo /usr/bin/searchd';
but nothing worked.
Any suggestions?
Upvotes: 3
Views: 1743
Reputation: 2583
Users need permission to run sudo
. Specifically, the user your PHP script is running as needs to be in the sudoers file. See man sudoers
for information about the file. Use visudo
to edit the sudoers file. Be very careful about giving your php/apache user permission to run sudo. It is a potential security issue that can allow your PHP scripts to do anything.
Upvotes: 1