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 the service to the **init.cfg** file.
## Configuration File of the init Module<a name="section56901555917"></a>
The configuration file **init.cfg** of the init module 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 is stored in the code repository **vendor/huawei/camera/init\_configs/**, and can be found in **/etc/** after burning is complete. The file is in JSON format, and its size cannot exceed 100 KB.
After the init process starts, it reads the **/etc/init.cfg** file, parses the content in JSON format, and loads system services in sequence based on the parsing result.
## How to Develop<a name="section15371931131117"></a>
## Development Guidelines<a name="section15371931131117"></a>
1. Configure the **jobs** array.
The init module completes the system startup in three phases:
- pre-init: operations required before system services are started, for example, mounting a file system, creating a folder, and modifying permissions.
- init: operations required for starting system services.
- post-init: operations required after system services are started.
- **pre-init**: operations required before system services are started, for example, mounting a file system, creating a folder, and modifying permissions.
- **init**: operations required for starting system services.
- **post-init**: operations required after system services are started.
Each of the preceding phases is represented by a job, which corresponds to a command set. The init module initializes the system by executing the commands in each job in sequence. pre-init job is executed first, then init job, and finally post-init job.
Each of the preceding phases is represented by a job, which corresponds to a command set. The init module initializes the system by executing the commands in each job in sequence. The **pre-init** job is executed first, then the **init** job, and finally the **post-init** job.
```
"jobs" : [{
...
...
@@ -43,10 +47,10 @@ After the init process starts, it reads the **/etc/init.cfg** file, parses the
<td class="cellrowborder" valign="top" width="86.6%" headers="mcps1.2.3.1.2 "><p id="p18115019284"><a name="p18115019284"></a><a name="p18115019284"></a>Job that is executed first. Operations (for example, creating a folder) required before the process startup are executed in this job.</p>
<td class="cellrowborder" valign="top" width="86.6%" headers="mcps1.2.3.1.2 "><p id="p18115019284"><a name="p18115019284"></a><a name="p18115019284"></a>Job that is executed first. Operations (for example, creating a folder) required before the process startup are executed in the pre-init job.</p>
@@ -70,7 +74,7 @@ After the init process starts, it reads the **/etc/init.cfg** file, parses the
</tbody>
</table>
A single job can hold a maximum of 30 commands \(only **start/mkdir/chmod/chown/mount/loadcfg** supported currently\). The command name and parameters \(128 bytes or less\) must be separated by only one space.
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.
**Table 2** Commands supported by a job
...
...
@@ -85,60 +89,61 @@ After the init process starts, it reads the **/etc/init.cfg** file, parses the
<td class="cellrowborder" valign="top" width="38.019999999999996%" headers="mcps1.2.4.1.3 "><p id="p56817536457"><a name="p56817536457"></a><a name="p56817536457"></a>Creates a folder. <strong id="b101229427189"><a name="b101229427189"></a><a name="b101229427189"></a>mkdir</strong> and the target folder must be separated by only one space.</p>
<td class="cellrowborder" valign="top" width="38.019999999999996%" headers="mcps1.2.4.1.3 "><p id="p56817536457"><a name="p56817536457"></a><a name="p56817536457"></a>Creates a folder. <strong>mkdir</strong> and the target folder must be separated by only one space.</p>
<td class="cellrowborder" valign="top" width="38.019999999999996%" headers="mcps1.2.4.1.3 "><p id="p2023822074614"><a name="p2023822074614"></a><a name="p2023822074614"></a>Modifies the permission, which must be in the <strong id="b89933155542"><a name="b89933155542"></a><a name="b89933155542"></a>0<em id="i297288205416"><a name="i297288205416"></a><a name="i297288205416"></a>xxx</em></strong> format. <strong id="b188781117192013"><a name="b188781117192013"></a><a name="b188781117192013"></a>chmod</strong>, <em id="i934619229207"><a name="i934619229207"></a><a name="i934619229207"></a>permission</em>, and <em id="i13800152722016"><a name="i13800152722016"></a><a name="i13800152722016"></a>target</em> must be separated by only one space.</p>
<td class="cellrowborder" valign="top" width="38.019999999999996%" headers="mcps1.2.4.1.3 "><p id="p2023822074614"><a name="p2023822074614"></a><a name="p2023822074614"></a>Modifies the permission, which must be in the <strong>0xxx</strong> format. <strong>chmod</strong>, <i>permission</i>, and <i>target</i> must be separated by only one space.</p>
<td class="cellrowborder" valign="top" width="38.019999999999996%" headers="mcps1.2.4.1.3 "><p id="p18408185817467"><a name="p18408185817467"></a><a name="p18408185817467"></a>Modifies the owner group. <strong id="b1792373220"><a name="b1792373220"></a><a name="b1792373220"></a>chown</strong>, <strong id="b884413283227"><a name="b884413283227"></a><a name="b884413283227"></a>uid</strong>, <strong id="b131043132218"><a name="b131043132218"></a><a name="b131043132218"></a>gid</strong>, and <em id="i91863268220"><a name="i91863268220"></a><a name="i91863268220"></a>target</em> must be separated by only one space.</p>
<td class="cellrowborder" valign="top" width="38.019999999999996%" headers="mcps1.2.4.1.3 "><p id="p18408185817467"><a name="p18408185817467"></a><a name="p18408185817467"></a>Modifies the owner group. <strong>chown</strong>, <strong>uid</strong>, <strong>gid</strong>, and <i>target</i> must be separated by only one space.</p>
<td class="cellrowborder" valign="top" width="38.019999999999996%" headers="mcps1.2.4.1.3 "><p id="p11976107144710"><a name="p11976107144710"></a><a name="p11976107144710"></a>Mounts devices. Every two parameters must be separated by only one space. Currently, supported flags include <strong id="b1638720366248"><a name="b1638720366248"></a><a name="b1638720366248"></a>nodev</strong>, <strong id="b18630134814249"><a name="b18630134814249"></a><a name="b18630134814249"></a>noexec</strong>, <strong id="b480755082413"><a name="b480755082413"></a><a name="b480755082413"></a>nosuid</strong>, <strong id="b13231145310245"><a name="b13231145310245"></a><a name="b13231145310245"></a>rdonly</strong>, and optionally <strong id="b13783109162812"><a name="b13783109162812"></a><a name="b13783109162812"></a>data</strong>.</p>
<td class="cellrowborder" valign="top" width="38.019999999999996%" headers="mcps1.2.4.1.3 "><p id="p11976107144710"><a name="p11976107144710"></a><a name="p11976107144710"></a>Mounts devices. Every two parameters must be separated by only one space. Currently, supported flags include <strong>nodev</strong>, <strong>noexec</strong>, <strong>nosuid</strong>, <strong>rdonly</strong>, and optionally <strong>data</strong>.</p>
<td class="cellrowborder" valign="top" width="38.019999999999996%" headers="mcps1.2.4.1.3 "><p id="p4350121915488"><a name="p4350121915488"></a><a name="p4350121915488"></a>Starts services. <em id="i79041657287"><a name="i79041657287"></a><a name="i79041657287"></a>serviceName</em> must be contained in the <strong id="b177231016182812"><a name="b177231016182812"></a><a name="b177231016182812"></a>services</strong> array.</p>
<td class="cellrowborder" valign="top" width="38.019999999999996%" headers="mcps1.2.4.1.3 "><p id="p4350121915488"><a name="p4350121915488"></a><a name="p4350121915488"></a>Starts services. <i>serviceName</i> must be contained in the <strong>services</strong> array.</p>
<td class="cellrowborder" valign="top" width="38.019999999999996%" headers="mcps1.2.4.1.3 "><p id="p13986141320510"><a name="p13986141320510"></a><a name="p13986141320510"></a>Loads other <strong id="b925984615280"><a name="b925984615280"></a><a name="b925984615280"></a>.cfg</strong> files. The maximum size of the target file (only <strong id="b922419224299"><a name="b922419224299"></a><a name="b922419224299"></a>/patch/fstab.cfg</strong> supported currently) is 50 KB. Each line in the <strong id="b36151249142918"><a name="b36151249142918"></a><a name="b36151249142918"></a>/patch/fstab.cfg</strong> file is a command. The command types and formats must comply with their respective requirements mentioned in this table. A maximum of 20 commands are allowed.</p>
<td class="cellrowborder" valign="top" width="38.019999999999996%" headers="mcps1.2.4.1.3 "><p id="p13986141320510"><a name="p13986141320510"></a><a name="p13986141320510"></a>Loads other <strong>.cfg</strong> files. The maximum size of the target file (only
<strong>/patch/fstab.cfg</strong> supported currently) is 50 KB. Each line in the <strong>/patch/fstab.cfg</strong> file is a command. The command types and formats must comply with their respective requirements mentioned in this table. A maximum of 20 commands are allowed.</p>
</td>
</tr>
</tbody>
</table>
2. Configure the **services** array, which holds all system services \(a maximum of 100\) that need to be started by the init process.
2. Configure the <strong>services</strong> array, which holds all system services (a maximum of 100) that need to be started by the init process.
```
"services" : [{
...
...
@@ -161,10 +166,10 @@ After the init process starts, it reads the **/etc/init.cfg** file, parses the
<td class="cellrowborder" valign="top" width="83.36%" headers="mcps1.2.3.1.2 "><p id="p18548317195715"><a name="p18548317195715"></a><a name="p18548317195715"></a>Whether the current service process is a one-off process.</p>
<p id="p103571840105812"><a name="p103571840105812"></a><a name="p103571840105812"></a><strong id="b12263228218"><a name="b12263228218"></a><a name="b12263228218"></a>1</strong>: The current service is a one-off process. If the process exits, the init process does not restart it.</p>
<p id="p5831191431116"><a name="p5831191431116"></a><a name="p5831191431116"></a><strong id="b637011193218"><a name="b637011193218"></a><a name="b637011193218"></a>0</strong>: The current service process is not a one-off process. If the process exits, the init process restarts it upon receiving the SIGCHLD signal.</p>
<p id="p103571840105812"><a name="p103571840105812"></a><a name="p103571840105812"></a><strong>1</strong>: The current service process is a one-off process. If the process exits, the init process does not restart it.</p>
<p id="p5831191431116"><a name="p5831191431116"></a><a name="p5831191431116"></a><strong>0</strong>: The current service process is not a one-off process. If the process exits, the init process restarts it upon receiving the SIGCHLD signal.</p>
<p id="p378912714010"><a name="p378912714010"></a><a name="p378912714010"></a>Note: If a non-one-off process exits for five consecutive times within four minutes, the init process will no longer restart it at the fifth exit.</p>
<td class="cellrowborder" valign="top" width="83.36%" headers="mcps1.2.3.1.2 "><p id="p166448210816"><a name="p166448210816"></a><a name="p166448210816"></a>Whether the current service process is a key system process.</p>
<p id="p8572182712811"><a name="p8572182712811"></a><a name="p8572182712811"></a><strong id="b2055716261523"><a name="b2055716261523"></a><a name="b2055716261523"></a>0</strong>: The current service process is not a key system process. If it exits, the init process does not reset or restart the system.</p>
<p id="p11861032111516"><a name="p11861032111516"></a><a name="p11861032111516"></a><strong id="b424817565220"><a name="b424817565220"></a><a name="b424817565220"></a>1</strong>: The current service process is a key system process. If it exits, the init process resets and restarts the system.</p>
<p id="p8572182712811"><a name="p8572182712811"></a><a name="p8572182712811"></a><strong>0</strong>: The current service process is not a key system process. If it exits, the init process does not reset or restart the system.</p>
<p id="p11861032111516"><a name="p11861032111516"></a><a name="p11861032111516"></a><strong>1</strong>: The current service process is a key system process. If it exits, the init process resets and restarts the system.</p>