In my php script I use line like that to execute some script:
exec('sudo -u USERNAME ./script.sh', $result)
The script is executed correctly by user USERNAME but if I stop apache or it get crashed the script also get killed. How to execute that script as user USERNAME and turn off apache without killing the script?