Move pid file check behind database setup (fixes #411)