def start_agent_service(self, agent_run_method, quiet, fork=True):
        """Start the daemon process by forking a new process.

        This method will invoke the agent_run_method that was passed in when initializing this object.
        """
        self._log_init_debug('Starting agent %s' % scalyr_util.get_pid_tid())

        # noinspection PyUnusedLocal
        def handle_terminate(signal_num, frame):
            if self.__termination_handler is not None:
                self.__termination_handler()

        # noinspection PyUnusedLocal
        def handle_interrupt(signal_num, frame):
            if self.__status_handler is not None:
                self.__status_handler()

        # Start the daemon by forking off a new process.  When it returns, we are either the original process
        # or the new forked one.  If it are the original process, then we just return.
        if fork:
            if not self.__daemonize():
                return
        else:
            # we are not a fork, so write the pid to a file
            if not self.__write_pidfile():
                raise AgentAlreadyRunning('The pidfile %s exists and indicates it is running pid=%s' % (
                    self.__pidfile, str(self.__read_pidfile())))

        # Register for the TERM and INT signals.  If we get a TERM, we terminate the process.  If we
        # get a INT, then we write a status file.. this is what a process will send us when the command
        # scalyr-agent-2 status -v is invoked.
        original_term = signal.signal(signal.SIGTERM, handle_terminate)
        original_interrupt = signal.signal(signal.SIGINT, handle_interrupt)

        try:
            self.__is_initializing = False
            result = agent_run_method(self)

            if result is not None:
                sys.exit(result)
            else:
                sys.exit(99)

        finally:
            signal.signal(signal.SIGTERM, original_term)
            signal.signal(signal.SIGINT, original_interrupt)
dataset/ETHPy150Open scalyr/scalyr-agent-2/scalyr_agent/platform_posix.py/PosixPlatformController.start_agent_service/original