write pid file as late as possible incase of error and gmetad quits