Skip to content

Instantly share code, notes, and snippets.

@sudo-barun
Created September 13, 2023 04:56
Show Gist options
  • Save sudo-barun/16f7ec661de4f241638a78b407d1a82b to your computer and use it in GitHub Desktop.
Save sudo-barun/16f7ec661de4f241638a78b407d1a82b to your computer and use it in GitHub Desktop.
run Apache server in foreground
// 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