Skip to content

Commit 0dd3029

Browse files
committed
restart bot if it crashes during restart (only when pcntl_exec is not available)
1 parent cae1fad commit 0dd3029

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/NovaGram/Bot.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ public function stop(int $signo = null)
237237
else{
238238
$this->running = false;
239239
$pool = $this->getDispatcher()->getPool();
240-
$pool->checkChilds();
241240
if($pool->hasChilds() || $pool->hasQueue()){
242241
print("Waiting for handlers to finish...".PHP_EOL);
243242
$pool->wait();
@@ -257,8 +256,14 @@ protected function restartOnChanges(){
257256
}
258257
else{
259258
@cli_set_process_title("NovaGram: died process ({$this->getUsername()})");
260-
shell_exec(PHP_BINARY." $path");
259+
system(PHP_BINARY." $path");
260+
for ($i = 0; $i < 100; $i++){
261+
$this->logger->error('Bot crashed, trying to restart');
262+
system(PHP_BINARY." $path");
263+
sleep(2);
264+
}
261265
}
266+
$this->logger->critical('Bot crashed 100 times, stopped');
262267
exit();
263268
}
264269
}

0 commit comments

Comments
 (0)