debian init: refactor stopping loop to a separate function