Created
September 13, 2023 04:56
-
-
Save sudo-barun/16f7ec661de4f241638a78b407d1a82b to your computer and use it in GitHub Desktop.
run Apache server in foreground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This runs Apache server in foreground. | |
// Usage: | |
// sudo $(which node) apache-foreground.js | |
const child_process = require('child_process'); | |
// SIGTERM listener has been set because Apache process can emit SIGTERM in parent process | |
// and by setting SIGTERM listener the default behavior of exiting the process is overridden | |
process.on('SIGTERM', () => { | |
}); | |
// user can press Ctrl+C to close the program | |
process.on('SIGINT', () => { | |
process.exit(0); | |
}); | |
let apacheProc; | |
function startApacheServer() | |
{ | |
apacheProc = child_process.spawn( | |
'apache2ctl', ['-D', 'FOREGROUND'], | |
{ | |
stdio: [0,0,0], | |
} | |
); | |
apacheProc.on('close', () => { | |
console.log('\nRestarting Apache server\n'); | |
startApacheServer(); | |
}); | |
} | |
startApacheServer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment