Include $PGPORT when looking for port. Set isRunning when started first time