1e41f4b71Sopenharmony_ci# init Configuration File 2e41f4b71Sopenharmony_ci## Overview 3e41f4b71Sopenharmony_ci### Function 4e41f4b71Sopenharmony_ciThe init configuration file is in JSON format and is used to configure commands and services required for system startup. Upon system startup, the Init process parses the init configuration file and runs the commands in it to start the corresponding services. 5e41f4b71Sopenharmony_ci### Basic Concepts 6e41f4b71Sopenharmony_ci1. Group configuration file: A group configuration file is named in the format of **device.xxxx.group.cfg**. It consists of three parts, **jobs**, **services**, and **groups**. It is available only for the standard system. Such a file is used to configure the jobs and services that can be executed. The partition that holds the file is determined based on the **bootgroup** attribute in cmdline. Currently, the following groups are supported: 7e41f4b71Sopenharmony_ci - **device.boot.group**: default configuration, which is used to trigger all jobs and services in the configuration file. 8e41f4b71Sopenharmony_ci - **device.charge.group**: charge mode, which is used to trigger only the allowed jobs and services in the configuration file. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci2. Startup configuration file: **init.cfg** file, which consists of three parts, **jobs**, **services**, and **import**. 11e41f4b71Sopenharmony_ci - **services** (for the Linux kernel only): native services supported by the system. For details about the service configuration, see [Service Management](subsys-boot-init-service.md). 12e41f4b71Sopenharmony_ci - **jobs**: collection of commands to be executed. For details about jobs, see [Job Management](subsys-boot-init-jobs.md). 13e41f4b71Sopenharmony_ci - **import** (for the Linux kernel only): command used to import **.cfg** files. It helps reduce the size of **.cfg** files for implementing different functions. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci### Constraints 16e41f4b71Sopenharmony_ciOnly the small system and standard system are supported. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci## How to Develop 19e41f4b71Sopenharmony_ci### Use Cases 20e41f4b71Sopenharmony_ciUpon startup, the init process first initializes the system and then parses the configuration file. The system classifies the configuration files into three types: 21e41f4b71Sopenharmony_ci1. <strong>init.cfg</strong>: default configuration file, which is defined by the init process and parsed first. 22e41f4b71Sopenharmony_ci2. <strong>/system/etc/init/*.cfg</strong>: configuration file defined by each subsystem. 23e41f4b71Sopenharmony_ci3. <strong>/vendor/etc/init/*.cfg</strong>: configuration file defined by vendors. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ciIf you need to add a configuration file, define its content as you want and copy it to the corresponding directory. 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci### How to Develop 28e41f4b71Sopenharmony_ci1. Define the configuration file. 29e41f4b71Sopenharmony_ci ``` 30e41f4b71Sopenharmony_ci { 31e41f4b71Sopenharmony_ci "import" : [ ], 32e41f4b71Sopenharmony_ci "jobs" : [ ], 33e41f4b71Sopenharmony_ci "services" : [ ] 34e41f4b71Sopenharmony_ci } 35e41f4b71Sopenharmony_ci ``` 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci2. Copy the configuration file to the corresponding directory based on the system type. 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci For the standard system: 40e41f4b71Sopenharmony_ci ``` 41e41f4b71Sopenharmony_ci ohos_prebuilt_etc("misc.cfg") { 42e41f4b71Sopenharmony_ci source = "//base/startup/init/services/etc/misc.cfg" 43e41f4b71Sopenharmony_ci relative_install_dir = "init" 44e41f4b71Sopenharmony_ci part_name = "init" 45e41f4b71Sopenharmony_ci } 46e41f4b71Sopenharmony_ci ``` 47e41f4b71Sopenharmony_ci For the small system: 48e41f4b71Sopenharmony_ci ``` 49e41f4b71Sopenharmony_ci copy("init_configs") { 50e41f4b71Sopenharmony_ci sources = [ "init_liteos_a_3516dv300.cfg" ] 51e41f4b71Sopenharmony_ci outputs = [ "$root_out_dir/config/init.cfg" ] 52e41f4b71Sopenharmony_ci } 53e41f4b71Sopenharmony_ci ``` 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci### Development Example 56e41f4b71Sopenharmony_ciThe following is a template for defining a **.cfg** file. 57e41f4b71Sopenharmony_ci``` 58e41f4b71Sopenharmony_ci{ 59e41f4b71Sopenharmony_ci "import" : [ 60e41f4b71Sopenharmony_ci "/etc/example1.cfg", 61e41f4b71Sopenharmony_ci "/etc/example2.cfg" 62e41f4b71Sopenharmony_ci ], 63e41f4b71Sopenharmony_ci "jobs" : [{ 64e41f4b71Sopenharmony_ci "name" : "jobName1", 65e41f4b71Sopenharmony_ci "cmds" : [ 66e41f4b71Sopenharmony_ci "start serviceName", 67e41f4b71Sopenharmony_ci "mkdir dir1" 68e41f4b71Sopenharmony_ci ] 69e41f4b71Sopenharmony_ci }, { 70e41f4b71Sopenharmony_ci "name" : "jobName2", 71e41f4b71Sopenharmony_ci "cmds" : [ 72e41f4b71Sopenharmony_ci "chmod 0755 dir1", 73e41f4b71Sopenharmony_ci "chown root root dir1" 74e41f4b71Sopenharmony_ci ] 75e41f4b71Sopenharmony_ci } 76e41f4b71Sopenharmony_ci ], 77e41f4b71Sopenharmony_ci "services" : [{ 78e41f4b71Sopenharmony_ci "name" : "serviceName", 79e41f4b71Sopenharmony_ci "path" : ["/system/bin/serviceName"] 80e41f4b71Sopenharmony_ci } 81e41f4b71Sopenharmony_ci ] 82e41f4b71Sopenharmony_ci} 83e41f4b71Sopenharmony_ci``` 84e41f4b71Sopenharmony_ci1. <strong>.cfg file</strong>: configuration file written in the JSON format. If the services or commands in it do not take effect, check whether the content format is correct. 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci2. <strong>import</strong>: command used to import **.cfg** files. The files are parsed immediately after their path is parsed. 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci3. <strong>example1.cfg</strong>: **.cfg** file to be imported. 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci4. <strong>serviceName</strong>: service name, which is user-defined. 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci5. <strong>/system/bin/serviceName</strong>: full path and parameters of the executable file of the current service, in array format. 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci6. <strong>jobName1</strong>: job name, which is user-defined. 95