0

I have an issue with apache and php.

I call this script in php:

exec("nohup sudo QUIET=y sh foo.sh > /home/tmp/log.txt 2>&1 & echo $!", $res);

Shortly after, the script foo.sh need to restart apache to include new configuration files:

/etc/init.d/apachectl restart

In command line, it works fine but in my php script the process is killed at the same time apache is restarted. Why? I thought nohup detach the processus of its parent.

(I point out that i can't change the sh script)

Any help would be greatly appreciated.

4 Answers4

3

You should use /etc/init.d/apachectl reload if the only thing you want is to reread configuration files.

Turgal
  • 527
  • 2
  • 12
  • I can't change the sh script (it belongs to the company), sorry :/, any other ideas? – user1883264 Apr 03 '13 at 15:17
  • 1
    @user1883264 If you cannot change the Shell script, because it belongs to the company.. And yo are on a project which actively uses this; then either submit a request the edit this file to your manager OR create a copy of this shell; give it a different name and change as you need – Daryl Gill Apr 03 '13 at 15:39
1
/etc/init.d/apachectl reload

This will not stop the service, but keep it running and refreshes the processes configuration.

Daryl Gill
  • 5,464
  • 9
  • 36
  • 69
0

Use /etc/init.d/apachectl reload instead if you dont want to kill the process.

castis
  • 8,154
  • 4
  • 41
  • 63
0

Since apache restart sends SIGTERM, not SIGHUP, you should handle SIGTERM from foo.sh

Chul-Woong Yang
  • 1,223
  • 10
  • 17