The init module starts key service processes during system startup. If you would like to add a system service that automatically starts upon system startup, you can add a configuration file named in the **xxx.cfg** format. The system automatically analyzes the **.cfg** file and starts the corresponding service.
The init module starts key service processes during system startup. If you would like to add a system service that automatically starts upon system startup, you can add a configuration file named in the **xxx.cfg** format. The system automatically analyzes the **.cfg** file and starts the corresponding service.
- Configuration File of the init Module<aname="section56901555917"></a>
- Configuration file of the init module<aname="section56901555917"></a>
The configuration file of the init module, that is, **init.cfg**, contains service names, executable file paths, permissions, and other information of all key system services that need to be started by the init process. The file can be found in **/etc/** after burning is complete. The file is in JSON format, and its size cannot exceed 100 KB.
The configuration file of the init module, that is, **init.cfg**, contains service names, executable file paths, permissions, and other information of all key system services that need to be started by the init process. The file can be found in **/etc/** after burning is complete. The file is in JSON format, and its size cannot exceed 100 KB.
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
If you need to add a key service to a module, you can also add the **.cfg** file of the module. During compilation, copy the file to the **/system/etc/init** directory. The init process will parse the **.cfg** file and starts the corresponding service.
If you need to add a key service to a module, you can also add the **.cfg** file of the module. During compilation, copy the file to the **/system/etc/init** directory. The init process will parse the **.cfg** file and starts the corresponding service.
- init Service Startup Control (for Standard System or Higher)<aname="section56901555918"></a>
- init service startup control (for standard system or higher)<aname="section56901555918"></a>
The init process classifies services into three types based on service configurations and starts the services in different phases.
The init process classifies services into three types based on service configurations and starts the services in different phases.
...
@@ -44,7 +44,7 @@
...
@@ -44,7 +44,7 @@
},
},
```
```
- init Service Parallel Service Control (for Standard System or Higher)<aname="section56901555919"></a>
- init parallel service control (for standard system or higher)<aname="section56901555919"></a>
The init module provides the parallel service processing function, which allows services to execute jobs in different phases.
The init module provides the parallel service processing function, which allows services to execute jobs in different phases.
...
@@ -52,7 +52,7 @@
...
@@ -52,7 +52,7 @@
-**on-stop**: a job executed when the service is stopped.
-**on-stop**: a job executed when the service is stopped.
-**on-restart**: a job executed when the service is restarted.
-**on-restart**: a job executed when the service is restarted.
- init On-Demand Startup (for Standard System or Higher)<aname="section56901555920"></a>
- init on-demand startup (for standard system or higher)<aname="section56901555920"></a>
Services managed by the init process can be started on demand. Such services are not automatically started during system startup. Instead, they are started by the init process only when a certain event occurs. Typical events that trigger service startup are as follows: Messages are sent over the socket listened by the init process. The samgr process receives a request from the client and needs to start the SA service.
Services managed by the init process can be started on demand. Such services are not automatically started during system startup. Instead, they are started by the init process only when a certain event occurs. Typical events that trigger service startup are as follows: Messages are sent over the socket listened by the init process. The samgr process receives a request from the client and needs to start the SA service.
...
@@ -70,7 +70,7 @@
...
@@ -70,7 +70,7 @@
- Hot-swap service process on-demand startup
- Hot-swap service process on-demand startup
<br>  The hot-swap service process can be started to process hot swap events based on system parameter changes.
<br>  The hot-swap service process can be started to process hot swap events based on system parameter changes.
- Enhanced init Process Startup and Recycling<aname="section56901555921"></a>
- Enhanced init process startup and recycling<aname="section56901555921"></a>
The CPU core binding, priority, MAC address, and AccessToken information of the service process can be configured in the configuration file during process startup.
The CPU core binding, priority, MAC address, and AccessToken information of the service process can be configured in the configuration file during process startup.
...
@@ -79,9 +79,9 @@
...
@@ -79,9 +79,9 @@
- Support of AccessToken setting for service processes and distributed capability setting for system service processes (through modification of the **.cfg** file)
- Support of AccessToken setting for service processes and distributed capability setting for system service processes (through modification of the **.cfg** file)
- Support of the suppression mechanism for service processes (through modification of the **.cfg** file)
- Support of the suppression mechanism for service processes (through modification of the **.cfg** file)
- init FD Proxy (for Standard System or Higher)<aname="section56901555922"></a>
- init fd proxy (for standard system or higher)<aname="section56901555922"></a>
FD proxy is an extended mechanism for on-demand startup. It can ensure that the fd state handle is not lost before the service process exits. Specifically, a service process sends the fd to the init process before it exits, and then reclaims the fd from the init process when it is started again.
fd proxy is an extended mechanism for on-demand startup. It can ensure that the fd state handle is not lost before the service process exits. Specifically, a service process sends the fd to the init process before it exits, and then reclaims the fd from the init process when it is started again.
This mechanism is implemented using the API provided by the init process. Before a service process exits, it can call the related API to send the fd to the init process over the socket that supports IPC communication. After the service process is restarted, the init process returns the corresponding fd handle to it in the same way.
This mechanism is implemented using the API provided by the init process. Before a service process exits, it can call the related API to send the fd to the init process over the socket that supports IPC communication. After the service process is restarted, the init process returns the corresponding fd handle to it in the same way.
<tdclass="cellrowborder"valign="top"width="86.6%"headers="mcps1.2.3.1.2 "><pid="p18116016285"><aname="p18116016285"></a><aname="p18116016285"></a>Job that is finally executed. Operations (for example, mounting the device after the driver initialization) required after the process startup are executed in this job. A single job can hold a maximum of 30 commands (Only **start**, **mkdir**, **chmod**, **chown**, **mount**, and **loadcfg** are supported currently). The command name and parameters (128 bytes or less) must be separated by only one space.</p>
<tdclass="cellrowborder"valign="top"width="86.6%"headers="mcps1.2.3.1.2 "><pid="p18116016285"><aname="p18116016285"></a><aname="p18116016285"></a>Job that is finally executed. Operations (for example, mounting the device after the driver initialization) required after the process startup are executed in this job. A single job can hold a maximum of 30 commands (Only <strong>start</strong>, <strong>mkdir</strong>, <strong>chmod</strong>, <strong>chown</strong>, <strong>mount</strong>, and <strong>loadcfg</strong> are supported currently). The command name and parameters (128 bytes or less) must be separated by only one space.</p>
<tdclass="cellrowborder"valign="top"width="83.36%"headers="mcps1.2.3.1.2 "><pid="p166448210816"><aname="p166448210816"></a><aname="p166448210816"></a>Standard system:<br>Priority of a service process. The value ranges from **-20** to **19**.<br>Small system:<br>**0**: non-critical process<br>**1**: critical process</p>
<tdclass="cellrowborder"valign="top"width="83.36%"headers="mcps1.2.3.1.2 "><pid="p166448210816"><aname="p166448210816"></a><aname="p166448210816"></a>Standard system:<br>Priority of a service process. The value ranges from <strong>-20</strong> to <strong>19</strong>.<br>Small system:<br><strong>0</strong>: non-critical process<br><strong>1</strong>: critical process</p>
<tdclass="cellrowborder"valign="top"width="83.36%"headers="mcps1.2.3.1.2 "><pid="p489313618173"><aname="p489313618173"></a><aname="p489313618173"></a>Whether to enable system restarting when a critical service fails to be restarted for a specified number of times. If this field is enabled, the critical service will be started in M seconds. If the restarting fails for N times, the system will be restarted. The default value of N is **4** and that of M is **20**. (Only for standard system or higher. Configuration: [0, 2, 10], in int array.)<aname="section56901555917"></a><aname="section56901555917"></a></p>
<tdclass="cellrowborder"valign="top"width="83.36%"headers="mcps1.2.3.1.2 "><pid="p489313618173"><aname="p489313618173"></a><aname="p489313618173"></a>Whether to enable system restarting when a critical service fails to be restarted for a specified number of times. If this field is enabled, the critical service will be started in M seconds. If the restarting fails for N times, the system will be restarted. The default value of N is <strong>4</strong> and that of M is <strong>20</strong>. (Only for standard system or higher. Configuration: [0, 2, 10], in int array.)<aname="section56901555917"></a><aname="section56901555917"></a></p>
<tdclass="cellrowborder"valign="top"width="83.36%"headers="mcps1.2.3.1.2 "><pid="p489313618173"><aname="p489313618173"></a><aname="p489313618173"></a>Ability privilege level: **system_core**, **normal**, or **system_basic**. The default value is **system_core**. (Only for the standard system or higher).<aname="section56901555917"></a><aname="section56901555917"></a></p>
<tdclass="cellrowborder"valign="top"width="83.36%"headers="mcps1.2.3.1.2 "><pid="p489313618173"><aname="p489313618173"></a><aname="p489313618173"></a>Ability privilege level: <strong>system_core</strong>, <strong>normal</strong>, or <strong>system_basic</strong>. The default value is <strong>system_core</strong>. (Only for the standard system or higher).<aname="section56901555917"></a><aname="section56901555917"></a></p>
@@ -432,4 +432,4 @@ After the configuration is complete, compile the package to burn the board.
...
@@ -432,4 +432,4 @@ After the configuration is complete, compile the package to burn the board.
   The kernel log is printed by the init process. After a code review on the init process, it is found that **ondemand** is not configured for the service.
   The kernel log is printed by the init process. After a code review on the init process, it is found that **ondemand** is not configured for the service.
 **Solution**<br>
 **Solution**<br>
   Correct the service configuration in the **.cfg"" file as follows: "ondemand" : true
   Correct the service configuration in the **.cfg** file as follows: "ondemand" : true