service: refactor code for checking if a service is managed by systemd