WO2012167529A1 - 在Linux容器中启动应用程序的方法和系统 - Google Patents

在Linux容器中启动应用程序的方法和系统 Download PDF

Info

Publication number
WO2012167529A1
WO2012167529A1 PCT/CN2011/081168 CN2011081168W WO2012167529A1 WO 2012167529 A1 WO2012167529 A1 WO 2012167529A1 CN 2011081168 W CN2011081168 W CN 2011081168W WO 2012167529 A1 WO2012167529 A1 WO 2012167529A1
Authority
WO
WIPO (PCT)
Prior art keywords
container
application
startup process
processes
application startup
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
PCT/CN2011/081168
Other languages
English (en)
French (fr)
Inventor
张洪辉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN201180002154.9A priority Critical patent/CN102439564B/zh
Priority to PCT/CN2011/081168 priority patent/WO2012167529A1/zh
Priority to EP11867148.6A priority patent/EP2746936A4/en
Publication of WO2012167529A1 publication Critical patent/WO2012167529A1/zh
Priority to US14/258,168 priority patent/US9183008B2/en
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/4401Bootstrapping
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines

Definitions

  • the present invention relates to the field of operating system technologies, and in particular, to a method for launching an application in a Linux container and a Linux system.
  • containers provide lightweight virtualization to isolate processes and resources.
  • Containers can effectively partition resources managed by a single operating system into isolated groups to better balance conflicting resource usage requirements between isolated groups. Compared to other virtualization solutions, neither instruction-level simulation nor on-the-fly compilation is required.
  • the container can run instructions locally on the core central processing unit (CPU) without any special interpretation mechanism. The complexity of paravirtualization and system call substitution is avoided.
  • the Linux operating system can make applications run as if they were on separate machines, but can share many of the underlying resources. While providing isolation, containers also save overhead by sharing resources, which are much less expensive than true virtualization.
  • Linux Container Linux Container, LXC
  • ⁇ port lxc-start ... [command] the process: 3 ⁇ 4 port:
  • the container startup process creates a new container and exists as a daemon for the container; the container startup process creates an application startup process, and puts the application startup process into a container, and then the application starts the process according to the command line entered by the user.
  • Parameter initialization container ;
  • the application startup process starts an application within the container based on a command that the user passes from the command line, which is the initial (init) process in the container;
  • the container daemon After the container destroy command is invoked, the container daemon exists as a container destroy process.
  • the container daemon obtains the group identifier (Identity, ID) of the process group in the container through socket communication, and uses the kill() system call to the process group in the container. Send a SIGKILL signal to terminate the process group in the container; After the daemon detects that the init process in the container has died, the container daemon exits, destroying the container.
  • the above existing method of launching an application in a Linux container can only start one application when the container is created. If another application needs to be started in the container, the application needs to be started outside the container, and then The application's process is executed in the container, which is cumbersome and changes the execution environment of the application during the operation. Further, if the application to be additionally started is a multi-process application, it is necessary to obtain the PID of all processes of the application, and manually write the current application process PID into the control file, which requires the system administrator of the container to use The familiarity with the application can complete the above operations, the operation is complicated, and the probability of error is high. In addition, when the application part of the process is inside the container and part of the process is outside the container, the application itself may be faulty due to the isolation of the container itself.
  • Embodiments of the present invention provide a method for launching an application in a Linux container and a Linux system, which can start multiple applications when the container is created.
  • a method of launching an application in a Linux container including:
  • the container startup process creates a container according to a command entered by the user, and then the container startup process exists as a container daemon of the container;
  • the container startup process creates a first application startup process, and places the first application startup process into the container for execution;
  • the first application startup process acquires the number N of applications to be started according to the command input by the user, and creates N-1 second application startup processes, where N is a positive integer not less than 2;
  • the first application startup process and the N-1 second application startup processes start the N to-be-launched applications in the container, where each first or second application startup process starts a to-be-launched s application.
  • a Linux system including a central processing unit, wherein the central processing unit includes: a container startup process unit, a first application startup process unit, and a second application startup process;
  • the container startup process unit is configured to create a container according to a command input by a user, and then exist as a container daemon unit, create the first application startup process unit, and put the first application startup process unit into the container Execution
  • the first application startup process unit is configured to acquire the number N of applications to be started according to a command input by the user, and create N-1 second application startup process units, where N is a positive integer not less than 2. ;
  • the first application startup process unit is configured to start an application to be launched by each second application startup process unit.
  • the first application startup process is first created, and the first application startup process creates one or more second application startup processes, and then each application startup process starts an application technical solution, so that the container is in the container.
  • you create you can launch multiple applications at the same time with a single command.
  • FIG. 1 is a flow chart of a conventional method of launching an application in a Linux container
  • FIG. 2 is a flowchart of a method for launching an application in a Linux container according to Embodiment 1 of the present invention
  • FIG. 3 is a flowchart of a method for launching an application in a Linux container according to Embodiment 2 of the present invention
  • the embodiment of the invention provides a method for starting an application in a Linux container, which is to create a plurality of application startup processes when the container is created, and each application startup process starts an application technical solution, so that the container can be created simultaneously Start multiple applications. The details are described below.
  • an embodiment of the present invention provides a method for starting an application in a Linux container, including:
  • Step 101 The container startup process creates a container according to a command input by the user, and then the container startup process exists as a container daemon of the container;
  • the user can create a container in the Linux container and launch the application in the created container by entering commands on the command line.
  • the command can be lxc-stard... [command].
  • the command line parameters of the command include the following: the name of the container to be created, the name of the application path to be started, the number of applications, and the name of the configuration file path. .
  • the container name and application path name are necessary, the application path name includes multiple, the number of applications and the configuration file path name are optional.
  • the current process in the OS After obtaining the command entered by the user, the current process in the OS, that is, the life used to perform user input
  • the process that causes the process to start as a container creates a container based on the command line arguments.
  • Creating a container is associating a container name with a configuration file.
  • the configuration file is used to specify the attributes of the container, such as the host name of the container, the network, the root file system, etc., and the configuration file is pre-established. If the path name of the configuration file is not included in the command line parameter, the container startup process can create a container according to the default configuration file. If the command line parameter includes the path name of the configuration file, the container startup process can be created according to the specified configuration file. container.
  • Step 102 The container startup process creates a first application startup process, and puts the first application startup process into the container for execution.
  • the container startup process and the first application startup process have a synchronization process, in which two processes negotiate each other's information interaction formats to transfer information to each other. Then, the container startup process puts the first application startup process into the container, and in the container, the two processes can cooperate with each other and wait for each other.
  • the first application startup process is the first process executed within the container and can be called an init process.
  • the first application startup process may initialize the container according to a command input by a user.
  • the initialization includes: configuring the container resource attribute according to the container configuration option input by the user on the command line, for example: configuring the CPU node binding limit of the container and the like.
  • Step 103 The first application startup process acquires the number N of applications to be started according to the command input by the user, and creates N-1 second application startup processes, where N is an integer not less than 2.
  • the command line parameters entered by the user may include the number N of applications for the first application process to obtain from the command line parameters. If the command line parameter does not include the number N of applications, the first application process can parse the command line parameters, count the number of application path names included in the command line, and obtain the number N of applications. In order to start the N programs, the first application launch process additionally creates N-1 second application launch processes in the container.
  • the first application startup process can use the fork() system call to create N second application startup processes, and fork() is a kernel interface of the Linux system for creating child processes.
  • Step 104 The first application startup process and the N-1 second application startup processes start the N to be started applications in the container, where each first or second application startup process starts. An application to be launched.
  • N application startup processes can use the execvpO system call to launch the application, execvp() Another kernel interface for Linux systems that is used to launch an application with a given path name.
  • the N application startup processes start the N applications in the container, which may include: N application startup processes start the corresponding application according to the set correspondence relationship, where the correspondence relationship is the correspondence between the application startup process and the application, for example, You can associate the PID of the application startup process with the order in which the application path name is entered in the command line argument.
  • the N application startup processes may be corresponding to the input N applications according to the PID from large to small, so that the application startup process with the largest PID starts the first application, and the application startup process with the smallest PID starts the Nth.
  • the application; or, the application startup process that minimizes the PID starts the first application, and the application startup process with the largest PID starts the Nth application; of course, other correspondences may also be used.
  • the method may further include:
  • the container daemon After the container daemon obtains the container destruction command input by the user, all the process groups in the container are terminated; after the container daemon detects that the initial process in the container is terminated, the container is destroyed. During this process, the container daemon exists as a container destruction process. It is worth noting that the container startup process, container daemon, and container destruction process mentioned in this article are essentially the same process.
  • the container daemon can obtain the group ID of the process group in the container through socket communication, and then use the kill() system call to send a SIGKILL signal to the process group in the container to terminate all processes in the container; the container daemon can also Get the ID of all processes in the container, send the SIGKILL signal directly to all processes, and terminate all processes in the container.
  • the process group is a combination of processes in the container, including a first application startup process and N-1 second application startup processes.
  • the embodiment of the present invention provides a method for starting an application in a Linux container, where a second application startup process is created by the first application startup process when the container is created, where each application startup process starts an application.
  • the technical solution of the program enables multiple applications to be executed in the container at the same time when the container is created, and multiple applications are started simultaneously by one command.
  • the technical solution encapsulates the startup steps of the application, and does not change the execution environment of the application during the startup process, especially when starting the multi-process application, the user does not need to know which processes are included in the multi-process application, and the multi-process application There is also no problem that part of the process is inside the container and part of the process is outside the container, and it will not cause a failure.
  • the method provided in this embodiment is further described in detail below with reference to FIG. 3:
  • the user By entering commands on the command line, the user creates a container and launches multiple applications in the created container, where only one command is required.
  • the method provided by the embodiment of the present invention is described below by using a container startup process and an application startup process as execution entities, respectively.
  • the container startup process creates a container based on the commands entered by the user and creates a first application startup process in the container, and the subsequent container startup process exists as the container daemon for the container.
  • the container startup process synchronizes with the first application startup process to negotiate the information interaction format. Then, the container startup process puts the first application startup process into the created container for execution.
  • the container starts the process execution function Poll, and the function is to hang the current file pointer to the waiting defined by the device.
  • the internal waiting is defined as waiting for the container destruction command.
  • the container daemon destroys the container.
  • the first application startup process After the first application startup process is created, it synchronizes with the container startup process to negotiate the information interaction format.
  • the first application launch process initializes the container according to a command input by the user.
  • the first application startup process acquires the number N of applications to be started according to the command input by the user, and creates N-1 second application startup processes, where N is an integer not less than 2.
  • the first application startup process and the N-1 second application startup processes start the N to-be-launched applications in the container, wherein the first or second application startup process starts an application to be started .
  • an embodiment of the present invention provides a method for launching an application in a Linux container.
  • a user can simultaneously launch multiple applications in a container by using a command, which facilitates the container.
  • Management and use enhanced container availability and manageability.
  • an embodiment of the present invention further provides a Linux system, including a central processing unit, where the central processing unit includes:
  • a container startup process unit configured to create a container according to a command input by the user, and then exist as a container daemon unit, creating the first Applying a startup process unit, and placing the first application startup process unit into the container for execution;
  • the first application startup process unit is configured to acquire the number N of applications to be started according to a command input by the user, and create N-1 second application startup process units, where N is a positive integer not less than 2.
  • the first application startup process unit and each second application startup process unit are used to launch an application to be launched.
  • the container startup process unit may include:
  • a container creation subunit configured to acquire a command input by the user, and create a container according to the container name and the configuration file path name, where the container name is specified in the command, and the configuration file path name is specified in the command or Is the default.
  • first or second application startup process unit may be specifically configured to start a corresponding application to be started according to the set correspondence relationship, where the correspondence relationship is a correspondence between an application startup process and an application to be started. .
  • the container daemon unit may be further configured to: after receiving the container destruction command, terminate all processes in the container, and after detecting that the initial process in the container is terminated, destroy the container.
  • the SIGKILL signal either sends a SIGKILL signal to all processes in the container, terminating all processes in the container.
  • the embodiment of the present invention provides a Linux system, which can simultaneously launch multiple applications in a container, which facilitates the management and use of the container, and enhances the availability and manageability of the container.
  • a person skilled in the art can understand that all or part of the steps of the foregoing embodiments can be completed by a program to instruct related hardware, and the program can be stored in a computer readable storage medium, and the storage medium can include: Read memory, random read memory, disk or CD, etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

一种在Linux容器中启动应用程序的方法,包括:容器启动进程根据用户输入的命令创建容器,创建第一应用启动进程,并将所述第一应用启动进程放入所述容器中执行;所述第一应用启动进程根据用户输入的命令获取待启动的应用程序的个数N,并创建N-1个第二应用启动进程,N为不小于2正整数;所述的第一应用启动进程和N-1个第二应用启动进程在所述容器中启动所述的N个应用程序,其中每个应用启动进程启动一个应用程序。本发明实施例还提供相应的Linux系统。本发明技术方案采用在容器创建时,创建多个应用启动进程,每个应用启动进程启动一个应用程序的技术方案,使得在容器创建时可以同时启动多个应用程序。

Description

在 Linux容器中启动应用程序的方法和系统 技术领域
本发明涉及操作系统技术领域,具体涉及一种在 Linux容器中启动应用程 序的方法和一种 Linux系统。
背景技术
Linux系统中, 容器(Container )可以提供轻量级的虚拟化, 以便隔离进 程和资源。 容器可以有效地将由单个操作系统管理的资源划分到孤立的组中, 以更好地在孤立的组之间平衡有沖突的资源使用需求。 与其他虚拟化方案相 比, 既不需要指令级模拟, 也不需要即时编译。 容器可以在核心中央处理器 ( CPU ) 本地运行指令, 不需要任何专门的解释机制。 避免了准虚拟化 ( paravirtualization )和系统调用替换中的复杂性。
通过提供一种创建和进入容器的方式, Linux操作系统可以让应用程序就 像在独立的机器上运行一样,但又能共享很多底层的资源。容器在提供隔离的 同时, 还通过共享资源节省开销, 容器比真正的虚拟化的开销要小得多。
请参考图 1 , Linux容器(Linux Container, LXC )根据用户输入的命令, ^口 lxc-start ... [command] , 启动应用程序, ;巟程: ¾口下:
容器启动进程创建一个新的容器, 同时作为该容器的守护进程存在; 容器启动进程创建一个应用启动进程,并将该应用启动进程放入容器中执 行, 然后该应用启动进程根据用户输入的命令行参数初始化容器;
应用启动进程根据用户从命令行传递的命令, 在容器内启动应用程序, 该 应用程序进程是容器中的初始 (init )进程;
当需要将其他应用程序放入容器中执行的时候,首先需要在容器外将该应 用程序启动, 并获得该应用程序的进程标识符( Process IDentity, PID )列表, 然后将当前进程 PID写入控制文件中使进程执行环境向容器中迁移,使得该应 用程序在容器中执行, 且每次是以进程为粒度执行;
当调用容器销毁命令后, 容器守护进程作为容器销毁进程存在, 容器守护 进程通过套接字通信获取容器中进程组的组标识符(Identity, ID ), 通过 kill() 系统调用向容器内进程组发送 SIGKILL信号, 将容器中的进程组终止; 容器 守护进程检测到容器中的 init进程已经死亡终止后, 该容器守护进程退出, 实 现将容器销毁。
上述现有的在 Linux容器中启动应用程序的方法,在容器创建时只能启动 一个应用程序,如果需要在容器中启动另外的应用程序, 则需要先在容器外部 将应用程序启动, 然后再将应用程序的进程放入容器中执行, 操作较为繁瑣, 且操作过程中改变了应用程序的执行环境。进一步的,如果需要另外启动的应 用程序是多进程应用, 则需要获取该应用程序所有进程的 PID, 分多次手动将 当前应用进程 PID写入控制文件,这就要求使用容器的系统管理员必须对应用 程序比较熟悉才能完成上述操作, 操作复杂, 出错概率高。 另外, 当应用程序 部分进程处于容器内部, 部分进程处于容器外部时, 由于容器本身的隔离性, 可能会导致应用程序故障。
发明内容
本发明实施例提供一种在 Linux容器中启动应用程序的方法和一种 Linux 系统, 可以在容器创建时启动多个应用程序。
一种在 Linux容器中启动应用程序的方法, 包括:
容器启动进程根据用户输入的命令创建容器,随后所述容器启动进程作为 所述容器的容器守护进程存在;
所述容器启动进程创建第一应用启动进程,并将所述第一应用启动进程放 入所述容器中执行;
所述第一应用启动进程根据用户输入的命令获取待启动的应用程序的个 数 N, 并创建 N-1个第二应用启动进程, N为不小于 2的正整数;
所述的第一应用启动进程和 N- 1个第二应用启动进程在所述容器中启动所 述的 N个待启动的应用程序, 其中每个第一或第二应用启动进程启动一个待启 动的应用程序。
一种 Linux系统, 包括中央处理器, 其特征在于, 所述中央处理器包括: 容器启动进程单元, 第一应用启动进程单元, 和第二应用启动进程;
所述容器启动进程单元, 用于根据用户输入的命令创建容器, 随后作为容 器守护进程单元存在,创建所述第一应用启动进程单元, 并将所述第一应用启 动进程单元放入所述容器中执行; 所述第一应用启动进程单元,用于根据用户输入的命令获取待启动的应用 程序的个数 N, 并创建 N-1个所述第二应用启动进程单元, N为不小于 2的正整 数;
所述第一应用启动进程单元每个第二应用启动进程单元用于启动一个待 启动的应用程序。
本发明实施例采用在容器创建时,先创建第一应用启动进程, 由第一应用 启动进程创建一个以上第二应用启动进程,然后每个应用启动进程启动一个应 用程序的技术方案, 使得在容器创建时, 通过一条命令, 就可以同时启动多个 应用程序。
附图说明
图 1是现有的在 Linux容器中启动应用程序的方法的流程图;
图 2是本发明实施例一的在 Linux容器中启动应用程序的方法的流程图; 图 3是本发明实施例二的在 Linux容器中启动应用程序的方法的流程图; 图 4是本发明实施例提供的 Linux系统的示意图。
具体实施方式
本发明实施例提供一种在 Linux容器中启动应用程序的方法,采用在容器 创建时,创建多个应用启动进程,每个应用启动进程启动一个应用程序的技术 方案, 使得在容器创建时可以同时启动多个应用程序。 以下进行详细说明。
请参考图 2 , 本发明实施例提供一种在 Linux容器中启动应用程序的方法, 包括:
步骤 101、 容器启动进程根据用户输入的命令创建容器, 随后所述容器启 动进程作为所述容器的容器守护进程存在;
对于 Linux操纵系统( operating system, OS ), 用户可以通过在命令行输入 命令, 实现在 Linux容器中创建容器和在创建的容器中启动应用程序。 所说的 命令可以是 lxc-stard... [command] ,该命令的命令行参数中包括以下内容:待创 建的容器名称、待启动的应用程序路径名称、应用程序个数和配置文件路径名 称。 其中, 容器名称和应用程序路径名称是必要的, 应用程序路径名称包括多 个, 应用程序个数和配置文件路径名称则是可选的。
获取用户输入的命令后, OS中的当前进程, 即, 用于执行用户输入的命 令的进程, 作为容器启动进程, 根据命令行参数创建一个容器。 创建容器就是 将一个容器名称与一个配置文件关联起来。 所述配置文件用于指定容器的属 性, 例如容器的主机名、 网络、 root文件系统等, 该配置文件是预先建立的。 若命令行参数中没有包括配置文件的路径名称,容器启动进程可以根据默认的 配置文件创建容器; 若命令行参数中包括了配置文件的路径名称, 则容器启动 进程可以根据该指定的配置文件创建容器。
步骤 102、 容器启动进程创建第一应用启动进程, 并将所述第一应用启动 进程放入所述容器中执行。
容器启动进程创建第一应用启动进程后,所述容器启动进程与第一应用启 动进程会有一个同步的过程, 该过程中两个进程协商彼此的信息交互格式, 以 便相互传递信息。 然后, 容器启动进程将第一应用启动进程放入所述容器中执 行, 在容器中, 这两个进程可以互相合作、 互相等待。 第一应用启动进程是容 器内执行的第一个进程, 可以称为初始 (init )进程。
可选的, 所述第一应用启动进程可以根据用户输入的命令初始化所述容 器。 所述初始化包括: 根据用户在命令行输入的容器配置选项, 完成对容器资 源属性的配置, 例如: 配置容器的 CPU节点绑定限制等信息。
步骤 103、 所述第一应用启动进程根据用户输入的命令获取待启动的应用 程序的个数 N, 并创建 N-1个第二应用启动进程, N为不小于 2的整数。
用户输入的命令行参数中可以包括应用程序的个数 N , 供第一应用进程从 命令行参数中获取。 若命令行参数中没有包括应用程序的个数 N, 则第一应用 进程可以解析命令行参数, 统计其中包括的应用程序路径名称的个数, 获取应 用程序的个数 N。 为了启动该 N个程序, 第一应用启动进程在容器中另外创建 N- 1个第二应用启动进程。 第一应用启动进程可以利用 fork()系统调用来创建 N 个第二应用启动进程, fork()是 Linux系统的一种内核接口, 用于创建子进程。
步骤 104、所述的第一应用启动进程和 N-1个第二应用启动进程在所述容 器中启动所述的 N个待启动的应用程序, 其中每个第一或第二应用启动进程 启动一个待启动的应用程序。
这 N个应用启动进程可以利用 execvpO系统调用来启动应用程序, execvp() 为 Linux系统的另一种内核接口,用于启动给定路径名称的应用程序。 N个应用 启动进程在容器中启动 N个应用程序具体可以包括: N个应用启动进程按照设 定的对应关系启动相应的应用程序,所述对应关系为应用启动进程与应用程序 的对应关系, 例如, 可以将应用启动进程的 PID与命令行参数中输入应用程序 路径名称的顺序相对应。 具体的, 可以按照 PID从大到小的顺序将 N个应用启 动进程与输入 N个应用程序对应,使得 PID最大的应用启动进程启动第 1个应用 程序, PID最小的应用启动进程启动第 N个应用程序; 或者, 使 PID最小的应用 启动进程启动第 1个应用程序, PID最大的应用启动进程启动第 N个应用程序; 当然, 也可以按照其它的对应关系。
可选的, 步骤 104之后还可以包括:
容器守护进程获取用户输入的容器销毁命令后, 终止容器中的所有进程 组; 所述容器守护进程检测到所述容器中的初始进程被终止后,将所述容器销 毁。 此过程中, 容器守护进程作为容器销毁进程存在。 值得说明的是, 本文中 提到的容器启动进程、 容器守护进程和容器销毁进程实质是同一个进程。
其中,容器守护进程可以通过套接字通信获取容器中进程组的组 ID, 然后 利用 kill()系统调用向容器内的进程组发送 SIGKILL信号,将容器中的所有进程 终止; 容器守护进程也可以获取容器中所有进程的 ID,直接向所有进程分別发 送 SIGKILL信号, 将容器中的所有进程终止。 所说的进程组是容器中进程的组 合, 包括了第一应用启动进程和 N-1个第二应用启动进程。
以上, 本发明实施例提供了一种在 Linux容器中启动应用程序的方法, 采 用在容器创建时, 由第一应用启动进程创建多个第二应用启动进程, 其中每个 应用启动进程启动一个应用程序的技术方案,使得在容器创建时可以同时启动 多个应用程序在容器中执行, 实现了通过一条命令同时启动多个应用程序。 该 技术方案筒化了应用程序的启动步骤, 在启动过程中, 不会改变应用程序的执 行环境, 尤其在启动多进程应用时, 用户不需要知道多进程应用程序具体包括 哪些进程, 多进程应用也不会发生部分进程处于容器内部、部分进程处于容器 外部的问题, 不会因此导致故障。
下面结合图 3进行对本实施例提供的方法做进一步详细的说明: 用户通过在命令行输入命令,实现创建一个容器并在创建的容器中启动多 个应用程序, 其中, 只需要输入一条命令即可。 下面分別以容器启动进程和应 用启动进程作为执行主体, 对本发明实施例提供的方法进行说明:
一、 对于容器启动进程:
容器启动进程根据用户输入的命令创建一个容器,并在容器中创建一个第 一应用启动进程, 后续容器启动进程作为该容器的容器守护进程存在。
然后, 容器启动进程和第一应用启动进程进行同步, 协商信息交互格式。 然后, 容器启动进程将第一应用启动进程放入创建的容器中执行。
然后, 容器启动进程执行函数 Poll, 作用是把当前的文件指针挂到设备内 部定义的等待, 本实施例中定义内部的等待为等待容器销毁命令。
然后, 当用户调用容器销毁命令后, 容器守护进程销毁该容器。
二、 对于应用启动进程:
第一应用启动进程被创建后,先与容器启动进程进行同步,协商信息交互 格式。
然后, 第一应用启动进程根据用户输入的命令初始化所述容器。
然后,第一应用启动进程获取根据用户输入的命令获取待启动的应用程序 的个数 N, 并创建 N-1个第二应用启动进程, N为不小于 2的整数。
然后,第一应用启动进程和 N- 1个第二应用启动进程在容器中启动所述的 N个待启动的应用程序,其中第一或第二每个应用启动进程启动一个待启动的 应用程序。
综上, 本发明实施例提供了一种在 Linux容器中启动应用程序的方法, 采 用该技术方案, 用户可以在创建容器时,通过一条命令在容器中同时启动多个 应用程序, 方便了容器的管理和使用, 增强了容器的可用性和可管理性。
请参考图 4, 本发明实施例还提供一种 Linux系统, 包括中央处理器, 所 述中央处理器包括:
容器启动进程单元, 第一应用启动进程单元, 和第二应用启动进程单元; 所述容器启动进程单元, 用于根据用户输入的命令创建容器, 随后作为容 器守护进程单元存在,创建所述第一应用启动进程单元, 并将所述第一应用启 动进程单元放入所述容器中执行; 所述第一应用启动进程单元,用于根据用户输入的命令获取待启动的应用 程序的个数 N, 并创建 N-1个所述第二应用启动进程单元, N为不小于 2的正整 数;所述第一应用启动进程单元和每个第二应用启动进程单元用于启动一个待 启动的应用程序。
进一步的, 所述容器启动进程单元可以包括:
容器创建子单元, 用于获取用户输入的命令,根据容器名称和配置文件路 径名称创建容器, 所述容器名称是所述命令中指定的, 所述配置文件路径名称 是所述命令中指定的或者是默认的。
进一步的,所述第一或第二应用启动进程单元可以具体用于按照设定的对 应关系启动相应的待启动的应用程序,所述对应关系为应用启动进程与待启动 的应用程序的对应关系。
再进一步的, 所述容器守护进程单元还可以用于收到容器销毁命令后, 终 止所述容器中的所有进程,检测到所述容器中的初始进程终止后,将所述容器 销毁。
SIGKILL信号或者向容器内的所有进程分別发送 SIGKILL信号, 将容器中的所 有进程终止。
综上, 本发明实施例提供了一种在 Linux系统, 该系统可以在容器中同时 启动多个应用程序, 方便了容器的管理和使用,增强了容器的可用性和可管理 性。 本领域普通技术人员可以理解上述实施例的各种方法中的全部或部分步 骤是可以通过程序来指令相关的硬件完成,该程序可以存储于一计算机可读存 储介质中,存储介质可以包括: 只读存储器、 随机读取存储器、磁盘或光盘等。
以上对本发明实施例所提供的在 Linux 容器中启动应用程序的方法和相 应的 Linux系统进行了详细介绍,但以上实施例的说明只是用于帮助理解本发 明的方法及其核心思想, 不应理解为对本发明的限制。

Claims

权 利 要 求
1、 一种在 Linux容器中启动应用程序的方法, 其特征在于, 包括: 容器启动进程根据用户输入的命令创建容器,随后所述容器启动进程作为 所述容器的容器守护进程存在;
所述容器启动进程创建第一应用启动进程,并将所述第一应用启动进程放 入所述容器中执行;
所述第一应用启动进程根据用户输入的命令获取待启动的应用程序的个 数 N, 并创建 N-1个第二应用启动进程, N为不小于 2的正整数;
所述的第一应用启动进程和 N- 1个第二应用启动进程在所述容器中启动所 述的 N个待启动的应用程序, 其中每个第一或第二应用启动进程启动一个待启 动的应用程序。
2、根据权利要求 1所述的方法, 其特征在于, 所述容器启动进程根据用户 输入的命令创建容器还包括:
容器启动进程获取用户输入的命令;
根据容器名称和配置文件路径名称创建容器,所述容器名称是所述命令中 指定的, 所述配置文件路径名称是所述命令中指定的或者是默认的。
3、根据权利要求 1所述的方法, 其特征在于, 所述的第一应用启动进程和 N-1个第二应用启动进程在所述容器中启动所述的 N个待启动的应用程序包 括:
所述第一或第二应用启动进程按照设定的对应关系启动相应的待启动的 应用程序, 所述对应关系为应用启动进程与待启动的应用程序的对应关系。
4、 根据权利要求 1至 3中任一所述的方法, 其特征在于, 所述的第一应用 启动进程和 N-1个第二应用启动进程在所述容器中启动所述的 N个待启动的应 用程序之后还包括:
所述容器守护进程收到容器销毁命令后, 终止所述容器中的所有进程; 所述容器守护进程检测到所述容器中的初始进程终止后, 将所述容器销 毁。
5、根据权利要求 4所述的方法, 其特征在于, 所述终止所述容器中的所有 进程包括:
向容器内的进程组发送 SIGKILL信号或者向容器内的所有进程分別发送 SIGKILL信号, 将容器中的所有进程终止。
6、一种 Linux系统, 包括中央处理器, 其特征在于, 所述中央处理器包括: 容器启动进程单元, 第一应用启动进程单元, 和第二应用启动进程;
所述容器启动进程单元, 用于根据用户输入的命令创建容器, 随后作为容 器守护进程单元存在,创建所述第一应用启动进程单元, 并将所述第一应用启 动进程单元放入所述容器中执行;
所述第一应用启动进程单元,用于根据用户输入的命令获取待启动的应用 程序的个数 N, 并创建 N-1个所述第二应用启动进程单元, N为不小于 2的正整 数;
所述第一应用启动进程单元和每个第二应用启动进程单元用于启动一个 待启动的应用程序。
7、根据权利要求 6所述的方法,其特征在于,所述容器启动进程单元包括: 容器创建子单元, 用于获取用户输入的命令,根据容器名称和配置文件路 径名称创建容器, 所述容器名称是所述命令中指定的, 所述配置文件路径名称 是所述命令中指定的或者是默认的。
8、 根据权利要求 6所述的方法, 其特征在于:
所述第一或第二应用启动进程单元具体用于按照设定的对应关系启动相 应的待启动的应用程序,所述对应关系为应用启动进程与待启动的应用程序的 对应关系。
9、 根据权利要求 6至 8中任一所述的方法, 其特征在于:
所述容器守护进程单元还用于收到容器销毁命令后,终止所述容器中的所 有进程, 检测到所述容器中的初始进程终止后, 将所述容器销毁。
10、 根据权利要求 9所述的方法, 其特征在于: 者向容器内的所有进程分別发送 SIGKILL信号, 将容器中的所有进程终止。
PCT/CN2011/081168 2011-10-24 2011-10-24 在Linux容器中启动应用程序的方法和系统 Ceased WO2012167529A1 (zh)

Priority Applications (4)

Application Number Priority Date Filing Date Title
CN201180002154.9A CN102439564B (zh) 2011-10-24 2011-10-24 在Linux容器中启动应用程序的方法和系统
PCT/CN2011/081168 WO2012167529A1 (zh) 2011-10-24 2011-10-24 在Linux容器中启动应用程序的方法和系统
EP11867148.6A EP2746936A4 (en) 2011-10-24 2011-10-24 METHOD AND SYSTEM FOR STARTING AN APPLICATION IN A LINUX CONTAINER
US14/258,168 US9183008B2 (en) 2011-10-24 2014-04-22 Method and system for starting application program in Linux container

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2011/081168 WO2012167529A1 (zh) 2011-10-24 2011-10-24 在Linux容器中启动应用程序的方法和系统

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US14/258,168 Continuation US9183008B2 (en) 2011-10-24 2014-04-22 Method and system for starting application program in Linux container

Publications (1)

Publication Number Publication Date
WO2012167529A1 true WO2012167529A1 (zh) 2012-12-13

Family

ID=45986235

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2011/081168 Ceased WO2012167529A1 (zh) 2011-10-24 2011-10-24 在Linux容器中启动应用程序的方法和系统

Country Status (4)

Country Link
US (1) US9183008B2 (zh)
EP (1) EP2746936A4 (zh)
CN (1) CN102439564B (zh)
WO (1) WO2012167529A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115878223A (zh) * 2022-12-29 2023-03-31 天翼电信终端有限公司 一种双系统云安全手机双容器启动方法

Families Citing this family (44)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9860274B2 (en) 2006-09-13 2018-01-02 Sophos Limited Policy management
CN102707990B (zh) * 2012-05-14 2015-04-08 华为技术有限公司 基于容器的处理方法和装置
CN103678203A (zh) * 2013-12-13 2014-03-26 国家计算机网络与信息安全管理中心 一种实现网卡零拷贝方法及装置
CN104270317B (zh) * 2014-09-12 2018-01-16 普联技术有限公司 一种路由器运行应用程序的控制方法、系统及路由器
US9256467B1 (en) 2014-11-11 2016-02-09 Amazon Technologies, Inc. System for managing and scheduling containers
CN105786334A (zh) * 2014-12-18 2016-07-20 宇龙计算机通信科技(深圳)有限公司 程序操作方法、程序操作装置和终端
CN106326226B (zh) * 2015-06-16 2019-05-07 苏宁易购集团股份有限公司 一种公有云上启动数据库服务的方法及系统
CN104899068A (zh) * 2015-06-30 2015-09-09 北京奇虎科技有限公司 使用容器进行多进程启动的方法及装置
CN104915239B (zh) * 2015-06-30 2018-10-09 北京奇虎科技有限公司 使用容器进行多进程启动的方法及装置
CN105204925A (zh) * 2015-08-26 2015-12-30 北京元心科技有限公司 在多操作系统中管理音视频设备的方法及装置
CN105045669A (zh) * 2015-08-26 2015-11-11 北京元心科技有限公司 容器系统的管理服务方法以及智能终端
US10152330B2 (en) * 2015-09-21 2018-12-11 Bae Systems Information And Electronic Systems Integration Inc. Memory protection using a tagged architecture
CN105357256B (zh) * 2015-09-28 2018-10-30 深信服网络科技(深圳)有限公司 管理移动设备的方法及服务器
US10133590B2 (en) * 2015-09-29 2018-11-20 International Business Machines Corporation Container runtime support
CN105871580A (zh) * 2015-11-02 2016-08-17 乐视致新电子科技(天津)有限公司 跨集群自动化部署运维系统及方法
US10157003B1 (en) * 2015-12-17 2018-12-18 EMC IP Holding Company LLC Storage system with distributed tiered parallel file system comprising software-defined unified memory cluster
KR102057269B1 (ko) 2016-01-15 2020-01-22 구글 엘엘씨 애플리케이션 컨테이너를 사용한 코드 및 종속 데이터의 전달 관리
US9817648B2 (en) 2016-01-15 2017-11-14 Google Inc. Application containers with dynamic sub-package loading
CN107196982B (zh) * 2016-03-14 2021-01-22 阿里巴巴集团控股有限公司 一种用户请求的处理方法和装置
CN107193577B (zh) 2016-03-15 2021-08-03 斑马智行网络(香港)有限公司 一种应用启动方法、装置和智能终端
US10157136B2 (en) * 2016-03-31 2018-12-18 Intel Corporation Pipelined prefetcher for parallel advancement of multiple data streams
US10069869B2 (en) 2016-05-17 2018-09-04 Amazon Technologies, Inc. Versatile autoscaling
CN106155778A (zh) * 2016-07-07 2016-11-23 中国科学院声学研究所 一种应用容器的启动方法及系统
US10375111B2 (en) 2016-11-12 2019-08-06 Microsoft Technology Licensing, Llc Anonymous containers
US10409642B1 (en) 2016-11-22 2019-09-10 Amazon Technologies, Inc. Customer resource monitoring for versatile scaling service scaling policy recommendations
CN107025135B (zh) * 2017-03-03 2020-02-21 网易(杭州)网络有限公司 Docker容器内应用进程管理方法、装置和介质
US11017102B2 (en) 2017-09-12 2021-05-25 Sophos Limited Communicating application information to a firewall
CN109947553B (zh) * 2017-12-21 2022-04-26 中国电信股份有限公司 容器的进程调度方法、装置和计算机可读存储介质
WO2019127399A1 (zh) * 2017-12-29 2019-07-04 浙江大学 Linux容器的细粒度沙盒策略执行方法
CN110134454B (zh) * 2018-02-09 2022-06-14 聚好看科技股份有限公司 一种启动应用程序的方法及其装置
US10977066B2 (en) 2018-04-06 2021-04-13 Red Hat, Inc. Virtual machine to container conversion and optimization
US20190347127A1 (en) * 2018-05-09 2019-11-14 Red Hat, Inc. Service provisioning and orchestration for virtual machine to container migration
US10996973B2 (en) 2018-11-13 2021-05-04 International Business Machines Corporation Executing commands in a virtual environment
CN111324385A (zh) * 2018-12-12 2020-06-23 中兴通讯股份有限公司 应用模块的启动方法、容器、控制设备及可读存储介质
CN110427248B (zh) * 2019-07-12 2021-10-01 中国人民解放军国防科技大学 一种基于容器的轻量级用户环境构建方法、系统及介质
US11669365B1 (en) 2019-08-26 2023-06-06 Amazon Technologies, Inc. Task pool for managed compute instances
CN112527403B (zh) * 2019-09-19 2022-07-05 荣耀终端有限公司 一种应用启动方法及电子设备
CN110674043B (zh) * 2019-09-24 2023-09-12 聚好看科技股份有限公司 应用调试的处理方法及服务器
CN111414256B (zh) * 2020-03-27 2022-10-04 中国人民解放军国防科技大学 基于麒麟移动操作系统的应用程序进程派生方法、系统及介质
CN112817492B (zh) * 2021-01-12 2024-09-27 山东高速信联科技股份有限公司 移动终端中应用程序管理方法及系统
US12192214B2 (en) 2021-05-05 2025-01-07 Sophos Limited Mitigating threats associated with tampering attempts
US12572370B2 (en) * 2021-07-27 2026-03-10 Hangzhou Jindoutengyun Technologies Co., Ltd. Application platform and application management method
CN113296868B (zh) * 2021-07-27 2021-11-23 杭州筋斗腾云科技有限公司 应用平台及应用管理方法
CN117632074A (zh) * 2022-08-16 2024-03-01 华为技术有限公司 一种音频数据处理方法、装置及存储介质

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1890643A (zh) * 2003-12-02 2007-01-03 甲骨文国际公司 异构型计算机系统间的复杂计算
CN101178662A (zh) * 2006-11-08 2008-05-14 中兴通讯股份有限公司 一种嵌入式linux应用进程的监控方法
CN101639787A (zh) * 2009-09-07 2010-02-03 中兴通讯股份有限公司 应用程序启动方法及装置

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4741292B2 (ja) * 2005-06-09 2011-08-03 株式会社日立製作所 デバイス管理システム
JP4815938B2 (ja) * 2005-08-16 2011-11-16 ソニー株式会社 情報処理装置および方法、並びにプログラム
US9378066B2 (en) * 2008-02-25 2016-06-28 Sap Se Dynamic resizing of applications running on virtual machines
US9098698B2 (en) * 2008-09-12 2015-08-04 George Mason Research Foundation, Inc. Methods and apparatus for application isolation

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1890643A (zh) * 2003-12-02 2007-01-03 甲骨文国际公司 异构型计算机系统间的复杂计算
CN101178662A (zh) * 2006-11-08 2008-05-14 中兴通讯股份有限公司 一种嵌入式linux应用进程的监控方法
CN101639787A (zh) * 2009-09-07 2010-02-03 中兴通讯股份有限公司 应用程序启动方法及装置

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115878223A (zh) * 2022-12-29 2023-03-31 天翼电信终端有限公司 一种双系统云安全手机双容器启动方法

Also Published As

Publication number Publication date
EP2746936A4 (en) 2015-03-11
EP2746936A1 (en) 2014-06-25
US20140229951A1 (en) 2014-08-14
CN102439564A (zh) 2012-05-02
US9183008B2 (en) 2015-11-10
CN102439564B (zh) 2014-03-26

Similar Documents

Publication Publication Date Title
WO2012167529A1 (zh) 在Linux容器中启动应用程序的方法和系统
US10862982B2 (en) Cloud-scale heterogeneous datacenter management infrastructure
TWI533213B (zh) 儲存和恢復應用程式運行時間狀態
US9672060B2 (en) Managing virtual machine migration
US10228964B2 (en) Storage layer based orchestration method for virtual machine migration across disparate virtualization environments
CN104094231B (zh) 用于支持无限带网络中的虚拟机的动态迁移的系统和方法
US9658934B2 (en) Dynamic mechanism for fault injection for testing distributed systems
EP3913859B1 (en) Vnf life cycle management method and apparatus
WO2021129733A1 (zh) 云操作系统的管理方法、装置、服务器、管理系统及介质
US10620856B2 (en) Input/output (I/O) fencing with persistent reservation information in shared virtual storage environments
CN107111530B (zh) 一种容灾方法、系统和装置
CN104113574A (zh) 一种广域网可信虚拟机的安全迁移方法及系统
US10164835B2 (en) Accessing peripheral devices from a container within virtual machines running on different host computing systems
US10552225B2 (en) Virtual device migration or cloning based on device profiles
US10474394B2 (en) Persistent reservation emulation in shared virtual storage environments
US11080079B2 (en) Autonomously reproducing and destructing virtual machines
CN103699444A (zh) 中央处理器热插拔的实现方法及装置
CN113326098B (zh) 支持kvm虚拟化与容器虚拟化的云管平台
CN110442351A (zh) 一种物理机网卡绑定方法与装置
US10776148B1 (en) System and method for utilizing computational power of a server farm
CN106557386A (zh) 基于kvm部署备份虚拟网卡虚拟机的方法、装置及系统
CN120144233B (zh) 一种Docker内集成密码模块的方法、装置、电子设备及介质
US12210893B2 (en) Establishing process connections utilizing an intermediary broker
WO2021003729A1 (zh) 配置方法、物理设备、服务器及计算机可读存储介质

Legal Events

Date Code Title Description
WWE Wipo information: entry into national phase

Ref document number: 201180002154.9

Country of ref document: CN

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 11867148

Country of ref document: EP

Kind code of ref document: A1

REEP Request for entry into the european phase

Ref document number: 2011867148

Country of ref document: EP

WWE Wipo information: entry into national phase

Ref document number: 2011867148

Country of ref document: EP

NENP Non-entry into the national phase

Ref country code: DE