server: improve pidfile and log handling