<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def on_master_missing(self):
        '''
        Tries to spawn a master agency if the slave agency failed to connect
        for several times. To avoid several slave agencies spawning the master
        agency a file lock is used
        '''
        self.info("We could not contact the master agency, starting a new one")
        if self._starting_master:
            self.info("Master already starting, waiting for it")
            return
        if self._shutdown_task is not None:
            self.info("Not spwaning master because we are about to terminate "
                      "ourselves")
            return
        if self._startup_task is not None:
            raise error.FeatError("Standalone started without a previous "
                                  "master agency already running, terminating "
                                  "it")

        # Try the get an exclusive lock on the master agency startup
        if self._acquire_lock():
            self._starting_master = True
            # Allow restarting a master if we didn't succeed after 10 seconds
            self._release_lock_cl = time.callLater(10, self._release_lock)
            return self._spawn_agency('master')