diff --git a/back/services/cron.ts b/back/services/cron.ts index 23fc0941..fbccceaf 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -211,17 +211,18 @@ export default class CronService { cmdStr = `${cmdStr} now`; } - const cp = exec(cmdStr, (err, stdout, stderr) => { + const cp = spawn(cmdStr, { shell: true, detached: true }); + this.cronDb.update( + { _id }, + { $set: { status: CrontabStatus.running, pid: cp.pid } }, + ); + cp.on('close', (code) => { this.cronDb.update( { _id }, { $set: { status: CrontabStatus.idle }, $unset: { pid: true } }, ); resolve(); }); - this.cronDb.update( - { _id }, - { $set: { status: CrontabStatus.running, pid: cp.pid } }, - ); }); }