コード例 #1
0
ファイル: manager.py プロジェクト: Willtech/swift
    def spawn(self, conf_file, once=False, wait=True, daemon=True, **kwargs):
        """Launch a subprocess for this server.

        :param conf_file: path to conf_file to use as first arg
        :param once: boolean, add once argument to command
        :param wait: boolean, if true capture stdout with a pipe
        :param daemon: boolean, if true ask server to log to console

        :returns : the pid of the spawned process
        """
        args = [self.cmd, conf_file]
        if once:
            args.append('once')
        if not daemon:
            # ask the server to log to console
            args.append('verbose')

        # figure out what we're going to do with stdio
        if not daemon:
            # do nothing, this process is open until the spawns close anyway
            re_out = None
            re_err = None
        else:
            re_err = subprocess.STDOUT
            if wait:
                # we're going to need to block on this...
                re_out = subprocess.PIPE
            else:
                re_out = open(os.devnull, 'w+b')
        proc = subprocess.Popen(args, stdout=re_out, stderr=re_err)
        pid_file = self.get_pid_file_name(conf_file)
        write_file(pid_file, proc.pid)
        self.procs.append(proc)
        return proc.pid
コード例 #2
0
ファイル: manager.py プロジェクト: kvite/swift
    def spawn(self, conf_file, once=False, wait=True, daemon=True, **kwargs):
        """Launch a subprocess for this server.

        :param conf_file: path to conf_file to use as first arg
        :param once: boolean, add once argument to command
        :param wait: boolean, if true capture stdout with a pipe
        :param daemon: boolean, if false ask server to log to console

        :returns : the pid of the spawned process
        """
        args = [self.cmd, conf_file]
        if once:
            args.append('once')
        if not daemon:
            # ask the server to log to console
            args.append('verbose')

        # figure out what we're going to do with stdio
        if not daemon:
            # do nothing, this process is open until the spawns close anyway
            re_out = None
            re_err = None
        else:
            re_err = subprocess.STDOUT
            if wait:
                # we're going to need to block on this...
                re_out = subprocess.PIPE
            else:
                re_out = open(os.devnull, 'w+b')
        proc = subprocess.Popen(args, stdout=re_out, stderr=re_err)
        pid_file = self.get_pid_file_name(conf_file)
        write_file(pid_file, proc.pid)
        self.procs.append(proc)
        return proc.pid
コード例 #3
0
    def spawn(self,
              conf_file,
              once=False,
              wait=True,
              daemon=True,
              additional_args=None,
              **kwargs):
        """Launch a subprocess for this server.

        :param conf_file: path to conf_file to use as first arg
        :param once: boolean, add once argument to command
        :param wait: boolean, if true capture stdout with a pipe
        :param daemon: boolean, if false ask server to log to console
        :param additional_args: list of additional arguments to pass
                                on the command line

        :returns: the pid of the spawned process
        """
        args = [self.cmd, conf_file]
        if once:
            args.append('once')
        if not daemon:
            # ask the server to log to console
            args.append('verbose')
        if additional_args:
            if isinstance(additional_args, str):
                additional_args = [additional_args]
            args.extend(additional_args)

        # figure out what we're going to do with stdio
        if not daemon:
            # do nothing, this process is open until the spawns close anyway
            re_out = None
            re_err = None
        else:
            re_err = subprocess.STDOUT
            if wait:
                # we're going to need to block on this...
                re_out = subprocess.PIPE
            else:
                re_out = open(os.devnull, 'w+b')
        # 创建并返回一个子进程,args[0],可执行文件名,args[1:]是参数
        # args = ['swift-**-server', '/etc/swift/**-server.conf']
        proc = subprocess.Popen(args, stdout=re_out, stderr=re_err)
        # 获取 pid_file 路径,eg: /var/run/swift/***-server.pid
        pid_file = self.get_pid_file_name(conf_file)
        # 将 proc.pid 写入到 pid_file
        write_file(pid_file, proc.pid)
        self.procs.append(proc)
        return proc.pid
コード例 #4
0
ファイル: test_utils.py プロジェクト: noodley/swift
 def test_write_file(self):
     with temptree([]) as t:
         file_name = os.path.join(t, 'test')
         utils.write_file(file_name, 'test')
         with open(file_name, 'r') as f:
             contents = f.read()
         self.assertEquals(contents, 'test')
         # and also subdirs
         file_name = os.path.join(t, 'subdir/test2')
         utils.write_file(file_name, 'test2')
         with open(file_name, 'r') as f:
             contents = f.read()
         self.assertEquals(contents, 'test2')
         # but can't over-write files
         file_name = os.path.join(t, 'subdir/test2/test3')
         self.assertRaises(IOError, utils.write_file, file_name, 'test3')
コード例 #5
0
ファイル: test_utils.py プロジェクト: colecrawford/swift
 def test_write_file(self):
     with temptree([]) as t:
         file_name = os.path.join(t, "test")
         utils.write_file(file_name, "test")
         with open(file_name, "r") as f:
             contents = f.read()
         self.assertEquals(contents, "test")
         # and also subdirs
         file_name = os.path.join(t, "subdir/test2")
         utils.write_file(file_name, "test2")
         with open(file_name, "r") as f:
             contents = f.read()
         self.assertEquals(contents, "test2")
         # but can't over-write files
         file_name = os.path.join(t, "subdir/test2/test3")
         self.assertRaises(IOError, utils.write_file, file_name, "test3")