monex
Version:
Execute one or multiple scripts, interactively or in daemon mode, and restart them whenever they crash or a watched file changes.
34 lines (17 loc) • 592 B
JavaScript
/* IMPORT */
import {spawn} from 'node:child_process';
import process from 'node:process';
/* MAIN */
console.log ( 'Child started...', Date.now () );
spawn ( 'while sleep 1; do echo "Subchild echoing..."; done', { stdio: 'inherit', shell: true } );
setInterval ( () => {
if ( Math.random () < .1 ) {
console.log ( 'Child about to throw...', Date.now () );
throw new Error ();
}
if ( Math.random () < .1 ) {
console.log ( 'Child about to crash...', Date.now () );
process.exit ( 1 );
}
console.log ( 'Child still alive...', Date.now () );
}, 1000 );