Run the supervisor loop, restarting the child on non-zero exit.
The supervisor will:
- Execute the child command.
- Exit if the child returns 0.
- Otherwise wait delay0 seconds and restart, until max0 is reached.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real, | intent(in) | :: | delay0 | |||
| integer, | intent(in) | :: | max0 | |||
| character(len=*), | intent(in) | :: | exe0 |
subroutine supervisor_loop(delay0, max0, exe0) real, intent(in) :: delay0 integer, intent(in) :: max0 character(len=*), intent(in) :: exe0 character(len=:), allocatable :: child_cmd integer :: code, attempt real :: delay child_cmd = build_child_command(exe0) attempt = 0 delay = max(0.0, delay0) do code = 0 call execute_command_line(child_cmd, exitstat=code) if (code == 0) exit attempt = attempt + 1 if (max0 > 0 .and. attempt >= max0) then write(error_unit,'(a)') "fpm-watch: child exited with nonzero status; restart limit reached" stop code end if write(error_unit,'(a,i0,a,i0,a,f0.2,a)') "fpm-watch: child crashed/aborted (exit=", code, "), restart #", attempt, " in ", delay, "s" call sleep_seconds(delay) end do stop 0 end subroutine supervisor_loop