From 41fc1d0ede4575c7ad52df609baf0200002b6822 Mon Sep 17 00:00:00 2001 From: shawn_he Date: Wed, 24 Aug 2022 14:51:08 +0800 Subject: [PATCH] update doc Signed-off-by: shawn_he --- .../subsystems/subsys-boot-init-jobs.md | 901 ++---------------- .../subsystems/subsys-boot-init-plugin.md | 76 +- .../subsystems/subsys-boot-init-service.md | 264 +---- 3 files changed, 127 insertions(+), 1114 deletions(-) diff --git a/en/device-dev/subsystems/subsys-boot-init-jobs.md b/en/device-dev/subsystems/subsys-boot-init-jobs.md index 8bbbc1a8c0..6f2ac0146f 100644 --- a/en/device-dev/subsystems/subsys-boot-init-jobs.md +++ b/en/device-dev/subsystems/subsys-boot-init-jobs.md @@ -1,11 +1,11 @@ # Job Management ## Overview -### Function +### Kconfig Visual Configuration A job is a set of commands in the **.cfg** file of the init module. A maximum of 4096 jobs can be added. Jobs can be configured in the [.cfg file](subsys-boot-init-cfg.md). Generally, jobs are executed during initialization to serve the normal startup of services or the initialization of specific basic functions. ### Basic Concepts A job can be configured in the **init.cfg** file or the custom **.cfg** file of the module. The parser of the init process aggregates commands of the jobs with the same name into one job. For jobs with the same name, the init process only ensures that the commands in the **init.cfg** file are executed in preference. It does not guarantee the execution sequence of commands in other **.cfg** files. -- Common job +- Basic job A job executed in a fixed phase during init process startup, for example, pre-init, init, or post-init. - pre-init: pre-initialization phase. Key services on which other services depend, such as ueventd, watchdog, and hilogd, are started in this phase. The mounting of data partitions is also done in this phase. @@ -32,848 +32,75 @@ A job is a command set, where you can manage the commands to be executed. A maxi ### Parameters **Table 1** Command set description - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Command - - - Format and Example - - - Description - - - Supported System Type - -
- mkdir - - mkdir target folder [mode] [owner] [group]
Example:
mkdir /storage/myDirectory
mkdir /storage/myDirectory 0755 root root -
- Creates a folder. mkdir and the target folder must be separated by only one space. Folders cannot be created recursively. - - Small and standard systems -
- chmod - - chmod permission target
Example:
chmod 0600 /storage/myFile.txt
chmod 0750 /storage/myDir -
- Modifies the permission, which must be in the 0xxx format. chmod, permission, and target must be separated by only one space. - - Small and standard systems -
- chown - - chown uid gid target
Example:
chown 900 800 /storage/myDir
chown 100 100 /storage/myFile.txt -
- Modifies the owner group. chown, uid, gid, and target must be separated by only one space. - - Small and standard systems -
- mount - - mount fileSystemType src dst flags data
Example:
mount vfat /dev/mmcblk0 /sdc rw,umask=000
mount jffs2 /dev/mtdblock3 /storage nosuid -
- Mounts devices. Every two parameters must be separated by only one space.
For details about flags, see the mountFlagMap[] array of the mountFlagMap function in base/startup/init_lite/services/init/init_common_cmds.c. The data field is optional. -
- Small and standard systems -
- start - - start serviceName
Example:
start foundationstart -
- Starts services. serviceName must be contained in the services array. - - Small and standard systems -
- export - - export key value
Example:
export TEST /data/test -
- Sets environment variables. key and value respectively indicate the environment variable and its value. - - Small and standard systems -
- rm - - rm filename
Example:
rm /data/testfile -
- Deletes a file. filename indicates the absolute file path. - - Small and standard systems -
- rmdir - - rmdir dirname
Example:
rmdir /data/testdir -
- Deletes a directory. dirname indicates the absolute path of the directory. - - Small and standard systems -
- stop - - stop servicename
Example:
stop console -
- Stops a service. servicename indicates the name of the service to stop. - - Small and standard systems -
- copy - - copy oldfile newfile
Example:
copy /data/old /data/new -
- Copies a file. oldfile and newfile respectively indicate the old and new absolute file paths. - - Small and standard systems -
- reset - - reset servicename
Example:
reset console -
- Resets a service. servicename indicates the name of the service to reset. If the service has not been started, this command will start the service. If the service is running, the command will stop the service and then restart it. - - Small and standard systems -
- reboot - - reboot subsystem
Example:
reboot updater -
- Restarts the system. subsystem is optional. If it is not specified, the device enters the current system upon restarting. If it is specified, the device enters the corresponding subsystem upon restarting. For example, if you run reboot updater, the device enters the updater subsystem upon restarting. - - Small and standard systems -
- sleep - - sleep time
Example:
sleep 5 -
- Enters the sleep mode. time indicates the sleep time.
To avoid impact on services, exercise caution when running this command. -
- Small and standard systems -
- domainname - - domainname name
Example:
domainname localdomain -
- Sets the domain name. - - Small and standard systems -
- hostname - - hostname name
Example:
hostname localhost -
- Sets the host name. - - Small and standard systems -
- wait - - wait filepath
Example:
wait /data/testfile or wait /data/testfile 5 -
- Waits for commands. The waiting time must not exceed 5 seconds. - - Small and standard systems -
- setrlimit - - setrlimit resource curValue maxValue
Example:
setrlimit RLIMIT_CPU 10 100 -
- Sets resource usage restrictions.
For details, see the resource[] array of the DoSetrlimit function in base/startup/init_lite/services/init/init_common_cmds.c. -
- Small and standard systems -
- exec - - exec Path of the executable file Parameters passed by the executable file
Example:
exec /system/bin/udevadm trigger -
- Runs an executable file. The command must not contain more than 10 parameters. - - Small and standard systems -
- mknode - - mknod name { b | c } Major Minor
Example:
mknod path b 0644 1 9 -
- Creates an index node corresponding to a directory entry and a special file. - - Standard system -
- makedev - - makedev major minor
Example:
makedev -v update -
- Creates a static device node, which is usually in the /dev directory. - - Standard system -
- symlink - - symlink target link_name
Example
symlink /proc/self/fd/0 /dev/stdin -
- Creates a symbolic link. - - Standard system -
- trigger - - trigger jobName
Example
trigger early-fs -
- Triggers a job. - - Standard system -
- insmod - - insmod [-f] [options]
Example
insmod xxx.ko -
- Loads a kernel module file. - - Standard system -
- setparam - - setparam paramname paramvalue
Example:
setparam sys.usb.config hdc -
- Sets system parameters. - - Standard system -
- load_persist_params - - load persist params
Example:
load_persist_params  -
- Loads persist parameters. There must be one and only one space after the load_persist_params command. - - Standard system -
- load_param - - load params
Example:
load_param /data/test.normal.para -
- Loads the parameters from a file to the memory. - - Standard system -
- load_access_token_id - - load_access_token_id  - - Writes the access token to the data/service/el0/access_token/nativetoken.json file. There is one and only one space after load_access_token_id. - - Standard system -
- ifup - - ifup NIC
Example:
ifup eth0 -
- Activates the specified NIC. - - Standard system -
- mount_fstab - - mount_fstab fstab.test
Example:
mount_fstab /vendor/etc/fstab.test -
- Mounts partitions based on the fstab file. - - Standard system -
- umount_fstab - - umount_fstab fstab.test
Example:
umount_fstab /vendor/etc/fstab.test -
- Unmounts partitions based on the fstab file. - - Standard system -
- restorecon - - restorecon file or dir
Example:
restorecon /file -
- Reloads the SELinux context. - - Standard system -
- stopAllServices - - stopAllServices [bool]
Example:
stopAllServices false
stopAllServices -
- Stops all services. - - Standard system -
- umount - - umount path
Example:
umount /vendor -
- Unmounts a mounted device. - - Standard system -
- sync - - sync  - - Writes data to the disk synchronously. There is only one and only one space after sync. - - Standard system -
- timer_start - - timer_start serviceName
Example:
timer_start console -
- Starts the service timer. - - Standard system -
- timer_stop - - timer_stop serviceName
Example:
timer_stop console -
- Stops the service timer. - - Standard system -
- init_global_key - - init_global_key path
Example:
init_global_key /data -
- Initializes the encryption key of the data partition file. - - Standard system -
- init_main_user - - init_main_user - - Encrypts the main user directory. - - Standard system -
- mkswap - - mkswap file
Example:
mkswap /swapfile1 -
- Creates a swap partition on a file or device. - - Standard system -
- swapon - - swapon file
Example:
swapon /swapfile1 -
- Activates the swap space. - - Standard system -
- mksandbox - - mksandbox fileName
Example:
mksandbox system -
- Creates a sandbox. - - Standard system -
- loadcfg - - loadcfg filePath
Example:
loadcfg /patch/fstab.cfg -
- Loads other .cfg files. The maximum size of the target file (only /patch/fstab.cfg supported currently) is 50 KB. Each line in the /patch/fstab.cfg 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. - - Small system -
+ | Command| Format and Example| Description| + | -------- | -------- | -------- | + | mkdir | mkdir target folder [mode] [owner] [group]
Example:
mkdir /storage/myDirectory
mkdir /storage/myDirectory 0755 root root| Creates a folder. mkdir and the target folder must be separated by only one space.
System type: small system and standard system| + | chmod | chmod permission target
Example:
chmod 0600 /storage/myFile.txt
chmod 0750 /storage/myDir | Modifies the permission, which must be in the 0xxx format. chmod, permission, and target must be separated by only one space.
System type: small system and standard system| + | chown | chown uid gid target
Example:
chown 900 800 /storage/myDir
chown 100 100 /storage/myFile.txt | Modifies the owner group. chown, uid, gid, and target must be separated by only one space.
System type: small system and standard system| + | mount | mount fileSystemType src dst flags data
Example:
mount vfat /dev/mmcblk0 /sdc rw,umask=000
mount jffs2 /dev/mtdblock3 /storage nosuid| Mounts devices. Every two parameters must be separated by only one space. For details about flags, see the mountFlagMap[] function in base/startup/init_lite/services/init/init_common_cmds.c. The data field is optional.
System type: small system and standard system| + | start | start serviceName
Example: start foundation| Starts services. serviceName must be contained in the services array.
System type: small system and standard system| + | export | export key value
Example:
export TEST /data/test| Sets environment variables. key and value respectively indicate the environment variable and its value.
System type: small system and standard system| + | rm | rm filename
Example:
rm /data/testfile| Deletes a file. filename indicates the absolute file path.
System type: small system and standard system| + | rmdir | rmdir dirname
Example:
rmdir /data/testdir| Deletes a directory. dirname indicates the absolute path of the directory.
System type: small system and standard system| + | write | write filename value
Example:
write /data/testfile 0| Writes a file. filename and value respectively indicate the absolute file path and the string to write.
System type: small system and standard system| + | stop | stop serviceName
Example:
stop console| Stops a service. servicenamei> indicates the name of the service to stop.
System type: small system and standard system| + | copy | copy oldfile newfile
Example:
copy /data/old /data/new| Copies a file. oldfile and newfile respectively indicate the old and new absolute file paths.
System type: small system and standard system| + | reset | reset serviceName
Example:
reset console| Resets a service. servicename indicates the name of the service to reset. If the service has not been started, this command will start the service. If the service is running, the command will stop the service and then restart it.
System type: small system and standard system| + | reboot | reboot [subsystem]
Example:
reboot updater| Restarts the system. subsystem is optional. If it is not specified, the device enters the current system upon restarting. If it is specified, the device enters the corresponding subsystem upon restarting. For example, if you run reboot updater, the device enters the updater subsystem upon restarting.
System type: small system and standard system| + | sleep | sleep time
Example:
sleep 5| Enters the sleep mode. time indicates the sleep time, which must not exceed 5 seconds.
To avoid impact on services, exercise caution when running this command.
System type: small system and standard system| + | domainname | domainname name
Example:
domainname localdomain| Sets the domain name.
System type: small system and standard system| + | hostname | hostname name
Example:
hostname localhost| Sets the host name.
System type: small system and standard system| + | wait | wait filepath [time]
Example:
wait /data/testfile or wait /data/testfile 5| Waits for commands. time indicates the waiting time, which must not exceed 5 seconds.
System type: small system and standard system| + | setrlimit | setrlimit resource curValue maxValue
Example:
setrlimit RLIMIT_CPU 10 100| Sets resource usage restrictions.
System type: small system and standard system| + | write | write path content
Example:
write /proc/sys/kernel/sysrq 0| Writes a file.
System type: small system and standard system| + | exec | exec Path of the executable file Parameters passed by the executable file
Example:
exec /system/bin/mkdir /data/test.txt| Runs an executable file. This command is called by the system.
System type: small system and standard system| + | syncexec | syncexec Path of the executable file Parameters passed by the executable file
Example:
syncexec /system/bin/udevadm trigger| Runs an executable file synchronously. The **wait** function will be called to wait for the child process to end. The command must not contain more than 10 parameters.
System type: standard system + | mknode |mknod name { b \| c } Major Minor
Example:
mknod path b 0644 1 9| Creates an index node corresponding to a directory entry and a special file.
System type: standard system| + | makedev | makedev major minor
Example:
makedev -v update| Creates a static device node, which is usually in the /dev directory.
System type: standard system| + | symlink | symlink target link_name
Example:
symlink /proc/self/fd/0 /dev/stdin| Creates a symbolic link.
System type: standard system| + | trigger | trigger jobName
Example:
trigger early-fs| Triggers a job.
System type: standard system| + | insmod | insmod [-f] [options]
Example:
insmod xxx.ko| Loads a kernel module file.
System type: standard system| + | setparam | setparam paramName paramValue
Example:
setparam sys.usb.config hdc| Sets system parameters.
System type: standard system| + | load_persist_params | load persist params
Example:
load_persist_params | Loads persist parameters. There must be one and only one space after the load_persist_params command.
System type: standard system| + | load_param | load params
Example:
load_param /data/test.normal.para| Loads the parameters from a file to the memory.
System type: standard system| + | load_access_token_id | load_access_token_id | Writes the access token to the data/service/el0/access_token/nativetoken.json file. There is one and only one space after load_access_token_id.
System type: standard system| + | ifup | ifup NIC
Example:
ifup eth0| Activates the specified NIC.
System type: standard system| + | mount_fstab | mount_fstab fstab.test
Example:
mount_fstab /vendor/etc/fstab.test| Mounts partitions based on the fstab file.
System type: standard system| + | umount_fstab | umount_fstab fstab.test
Example:
umount_fstab /vendor/etc/fstab.test| Unmounts partitions based on the fstab file.
System type: standard system| + | restorecon | restorecon file or dir
Example:
restorecon /file| Reloads the SELinux context.
System type: standard system| + | stopAllServices | stopAllServices [bool]
Example:
stopAllServices false or stopAllServices| Stops all services. The maximum response time is 10 ms by default.
System type: standard system| + | umount |umount path
Example:
umount /vendor| Unmounts a mounted device.
System type: standard system| + | sync | sync | Writes data to the disk synchronously. There is only one and only one space after sync.
System type: standard system| + | timer_start | timer_start serviceName
Example:
timer_start console| Starts the service timer.
System type: standard system| + | timer_stop | timer_stop serviceName
Example:
timer_stop console| Stops a service timer.
System type: standard system| + | init_global_key | init_global_key path
Example:
init_global_key /data| Initializes the encryption key of the data partition file.
System type: standard system| + | init_main_user | init_main_user| Encrypts the main user directory.
System type: standard system| + | mkswap | mkswap file
Example:
mkswap /swapfile1| Creates a swap partition on a file or device.
System type: standard system| + | swapon | swapon file
Example:
swapon /swapfile1| Activates the swap space.
System type: standard system| + | mksandbox | mksandbox fileName
Example:
mksandbox system| Creates a sandbox.
System type: standard system| + | loadcfg | loadcfg filePath
Example:
loadcfg /patch/fstab.cfg| Loads other .cfg files. The maximum size of the target file (only /patch/fstab.cfg supported currently) is 50 KB. Each line in the /patch/fstab.cfg 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.
System type: small system| ### Available APIs Job management is a part of the init startup process. It is a process-based function that completely serves the init startup process. It does not provide any functional APIs for other modules. It works in a way similar to command group management and does not provide help for other types of management. The following describes the job management APIs. **Table 2** Description of job parsing APIs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- API - - Input Parameter - - Return Value - - Description - - Supported System Type -
- void ParseAllJobs(const cJSON *fileRoot) - - const cJSON *fileRoot - - void - - Provides the general entry for parsing jobs. - - Small and standard systems -
- static void ParseJob(const cJSON  *jobItem, Job *resJob) - - const cJSON *jobItem, Job *resJob - - void - - Checks whether a job exists and parses cmds in it. - - Small system -
- int GetCmdLinesFromJson(const cJSON *root, CmdLines **cmdLines) - - const cJSON *root, CmdLines **cmdLines - - int - - Parses cmds in the job. This API is used for the small system. It does not apply to the standard system because the trigger command and condition attribute are involved. - - Small and standard systems -
- int ParseTriggerConfig(const cJSON *fileRoot, int (*checkJobValid)(const char *jobName)) - - const cJSON *fileRoot, int (*checkJobValid)(const char *jobName) - - int - - Parses the trigger command in the job. - - Standard system -
- static int ParseTrigger_(const TriggerWorkSpace *workSpace, const cJSON *triggerItem, int (*checkJobValid)(const char *jobName)) - - const TriggerWorkSpace *workSpace, const cJSON *triggerItem, int (*checkJobValid)(const char *jobName) - - int - - Obtains the job name, condition attribute, and cmds command group. Jobs are stored in a hash table, and commands are stored in a queue structure. - - Standard system -
+| API| Description| Supported System Type| +|:--------|:-----|:------| +|void ParseAllJobs(const cJSON *fileRoot)|Provides the general entry for parsing jobs.| Small and standard systems| +|static void ParseJob(const cJSON *jobItem, Job *resJob)|Checks whether a job exists and parses cmds in it.| Small system| +|int GetCmdLinesFromJson(const cJSON *root, CmdLines **cmdLines)| Parses cmds in the job. This API is used for the small system.
It does not apply to the standard system because the trigger command and condition attribute are involved.| Small and standard systems| +|int ParseTriggerConfig(const cJSON *fileRoot,
int (*checkJobValid)(const char *jobName))|Parses the trigger command in the job.| Standard System| +|static int ParseTrigger_(const TriggerWorkSpace *workSpace,
const cJSON *triggerItem,
int (*checkJobValid)(const char *jobName))|Obtains the job name, condition attribute, and cmds command group.
Jobs are stored in a hash table, and commands are stored in a queue structure.| Standard system| **Table 3** Description of the job triggering APIs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- API - - Input Parameter - - Return Value - - Description - - Supported System Type -
- void PostTrigger(EventType type, const char *content, uint32_t contentLen) - - EventType type, const char *content, uint32_t contentLen - - void - - Verifies the validity of the job name and sends a job triggering event. - - Standard system -
- static void SendTriggerEvent(int type, const char *content, uint32_t contentLen) - - int type, const char *content, uint32_t contentLen - - void - - Performs functions such as system control and starting or stopping of services based on system parameters. - - Standard system -
- static void DoTriggerCmd(const struct CmdArgs *ctx) - - const struct CmdArgs *ctx - - void - - Executes the trigger command. - - Standard system -
- void DoTriggerExec(const char *triggerName) - - const char *triggerName - - void - - Finds a command group based on the job name and pushes the commands in the command group to the execution queue. This API is available only for the standard system. - - Standard system -
- void DoJob(const char *jobName) - - const char *jobName - - void - - Matches a job based on the job name and invokes DoCmdByIndex to execute the commands in the job. - - Small system -
- void DoCmdByIndex(int index, const char *cmdContent) - - int index, const char *cmdContent - - void - - Combines parameters and commands. - - Small and standard systems -
+| API| Description| Supported System Type| +|:--------|:-----|:------| +|void PostTrigger(EventType type, const char *content, uint32_t contentLen)|Verifies the validity of the job name and sends a job triggering event.| Standard system| +|static void SendTriggerEvent(int type, const char *content, uint32_t contentLen)|Performs functions such as system control and starting or stopping of services based on system parameters.| Standard system| +|static void DoTriggerCmd(const struct CmdArgs *ctx)|Executes the trigger command.| Standard system| +|void DoTriggerExec(const char *triggerName)| Finds a command group based on the job name and pushes the commands in the command group to the execution queue.| Standard system| +|void DoJob(const char *jobName)|Matches a job based on the job name and invokes DoCmdByIndex
to execute the commands in the job.| Small system| +|void DoCmdByIndex(int index, const char *cmdContent)|Combines parameters and commands.| Small and standard systems| ### Development Example The following is the template for configuring jobs in the .cfg file. You can use it to verify the job management function. diff --git a/en/device-dev/subsystems/subsys-boot-init-plugin.md b/en/device-dev/subsystems/subsys-boot-init-plugin.md index aeb47c97c0..2cb75ad293 100644 --- a/en/device-dev/subsystems/subsys-boot-init-plugin.md +++ b/en/device-dev/subsystems/subsys-boot-init-plugin.md @@ -2,47 +2,43 @@ ## Overview ### Basic Concepts - - - begetctl - - For details about begetctl, see [begetctl Commands](#table14737791480). - + - Introduction to begetctl + For details, see [Description of begetctl Commands](#table14737791480). - bootchart plug-in - The bootchart plug-in is an open source tool used to evaluate system performance during Linux startup. It automatically collects information such as the CPU usage, disk throughput, and process status, and displays the evaluation result in graphics to facilitate system startup optimization. ### Constraints bootchart is available only for the standard system, and begetctl is available for both the small system and the standard system. -## How to Develop +## Development Guidelines ### Parameters - **Table 1** Description of begetctl commands + **Table 1** Description of begetctl commands | Command| Format and Example| Description| | :---------- | :---------- |:--------| | init group test [stage] | init group test | For details about **stage**, see **ServiceStatus**.| | param ls [-r] [name] | Displays system parameters.
Example:
begetctl param ls persist.sys.usb | N/A| -| param get [name] | Obtains system parameter information.
Example:
begetctl param get
param get| N/A| -| param set name value| Sets system parameters.
Example:
begetctl param set ohos.servicectrl.display 1
param set ohos.servicectrl.display 1| N/A| -| param wait name [value] [timeout] | Waits for system parameters.
Example:
begetctl param wait persist.sys.usb.config hdc
param wait persist.sys.usb.config hdc| The default value of **timeout** is **30**.| -| param dump [verbose] | Dumps system parameter information.
Example:
begetctl param dump
param dump| N/A| -| param shell [name] | Enters the param shell.
Example:
begetctl param shell
param shell| N/A| +| param get [name] | Obtains system parameter information.
Example:
begetctl param get or param get| N/A| +| param set name value| Sets system parameters.
Example:
begetctl param set ohos.servicectrl.display 1 or param set ohos.servicectrl.display 1| N/A| +| param wait name [value] [timeout] | Waits for system parameters.
Example:
begetctl param wait persist.sys.usb.config hdc or param wait persist.sys.usb.config hdc| The default value of **timeout** is **30**.| +| param dump [verbose] | Dumps system parameter information.
Example:
begetctl param dump or param dump| N/A| +| param shell [name] | Enters the parameter shell.
Example:
begetctl param shell or param shell| N/A| | timer_stop servicename | Stops the service timer.
Example:
begetctl timer_stop appspawn | The value of **servicename** can contain a maximum of 96 characters.| -| timer_start servicename timeout | Starts the service timer.
Example:
begetctl timer_start appspawn | The value of **servicename** can contain a maximum of 96 characters. The default value of **timeout** is **10**.| -| start_service servicename | Starts a service.
Example:
begetctl start_service appspawn
start_service appspawn| N/A| -| stop_service servicename | Stops a service.
Example:
begetctl stop_service appspawn
stop_service appspawn| N/A| -| service_control start servicename | Starts a service.
Example:
begetctl service_control start appspawn
service_control start appspawn| N/A| -| service_control stop servicename | Stops a service.
Example:
begetctl service_control stop appspawn
service_control stop appspawn | N/A| -| misc_daemon --write_logo xxx.rgb | Writes the startup logo.
Example:
begetctl misc_daemon --write_logo logo.rgb
misc_daemon --write_logo logo.rgb| The maximum size of an RGB file is **1024*2038**. Only Hi3516D V300 is supported.| -| reboot | Restarts the system.
Example:
begetctl reboot
reboot|N/A| -| reboot shutdown | Shuts down the system.
Example:
begetctl reboot shutdown
reboot shutdown|N/A| -| reboot suspend | Suspends the system.
Example:
begetctl reboot suspend
reboot suspend| N/A| -| reboot updater | Restarts the system and enters updater.
Example:
begetctl reboot updater
reboot updater| N/A| -| reboot updater[:options] | Restarts the system and enters updater.
Example:
begetctl reboot updater
reboot updater| N/A| -| reboot flashd | Restarts the system and enters flashd.
Example:
begetctl reboot flashd
reboot flashd| N/A| -| reboot flashd[:options] | Restarts the system and enters flashd.
Example:
begetctl reboot flashd
reboot flashd| N/A| -| reboot charging | Restarts the system and enters charging.
Example:
begetctl reboot charging
reboot charging| N/A| -| reboot loader | Restarts the system and enters the burning mode.
Example:
begetctl reboot loader
reboot loader| N/A| +| timer_start servicename timeout | Starts the service timer.
Example:
begetctl timer_start appspawn | The value of **servicename** can contain a maximum of 96 characters. The default value of **timeout** is **10**. | +| start_service servicename | Starts a service.
Example:
begetctl start_service appspawn or start_service appspawn| N/A| +| stop_service servicename | Stops a service.
Example:
begetctl stop_service appspawn or stop_service appspawn| N/A| +| service_control start servicename | Starts a service.
Example:
begetctl service_control start appspawn or service_control start appspawn| N/A| +| service_control stop servicename | Stops a service.
Example:
begetctl service_control stop appspawn or service_control stop appspawn | N/A| +| misc_daemon --write_logo xxx.rgb | Writes the startup logo.
Example:
begetctl misc_daemon --write_logo logo.rgb or misc_daemon --write_logo logo.rgb| The maximum size of an RGB file is **1024*2038**. Only Hi3516D V300 is supported.| +| reboot | Restarts the system.
Example:
begetctl reboot or reboot|N/A| +| reboot shutdown | Shuts down the system.
Example:
begetctl reboot shutdown or reboot shutdown|N/A| +| reboot suspend | Suspends the system.
Example:
begetctl reboot suspend or reboot suspend| N/A| +| reboot updater | Restarts the system and enters updater.
Example:
begetctl reboot updater or reboot updater| N/A| +| reboot updater[:options] | Restarts the system and enters updater.
Example:
begetctl reboot updater or reboot updater| N/A| +| reboot flashd | Restarts the system and enters flashd.
Example:
begetctl reboot flashd or reboot flashd| N/A| +| reboot flashd[:options] | Restarts the system and enters flashd.
Example:
begetctl reboot flashd or reboot flashd| N/A| +| reboot charge | Restarts the system and enters the charge mode.
Example:
begetctl reboot charge or reboot charge| N/A| +| reboot loader | Restarts the system and enters the burning mode.
Example:
begetctl reboot loader or reboot loader| N/A| | bootchart stop | Stops chart analysis.
Example:
begetctl bootchart stop | Only rk3568 is supported.| | bootchart start | Starts chart analysis.
Example:
begetctl bootchart start | N/A| | bootchart disable | Disables chart analysis.
Example:
begetctl bootchart disable | N/A| @@ -51,18 +47,24 @@ bootchart is available only for the standard system, and begetctl is available f | sandbox -p process_name | Moves a process into the sandbox.
Example:
sandbox -p /bin/sh | N/A| | sandbox -n sandbox_name | Enters the configured system or chipset sandbox.
Example:
sandbox -n system | N/A| | sandbox -h | sandbox command help | N/A| - +| partitionslot getslot | Obtains the current active slot.
Example:
begetctl partitionslot getslot or partitionslot getslot| N/A| +| partitionslot getsuffix slot | Obtains the current matching slot.
Example:
begetctl partitionslot getsuffix 1 or partitionslot getsuffix 1| N/A| +| partitionslot setactive slot | Sets a partition slot as active.
Example:
begetctl partitionslot setactive 1 or partitionslot setactive 1| N/A| +| partitionslot setunboot slot | Sets a partition slot as inactive.
Example:
begetctl partitionslot setunboot 1 or partitionslot setunboot 1| N/A| +| modulectl uninstall moduleName | Uninstalls a dynamic plug-in.
Example:
modulectl uninstall bootchart | N/A| +| modulectl install moduleName | Installs a dynamic plug-in.
Example:
modulectl install bootchart | N/A| +| modulectl list | Views the list of dynamic plug-ins.
Example:
begetctl modulectl list | N/A| ## How to Develop ### Available APIs - **Table 1** Description of APIs + **Table 1** Description of APIs | API| Description| | ---------- | ---------- | -| void PluginExecCmdByName(const char *name, const char *cmdContent) | Starts the plug-in by name.| -| void PluginExecCmdByCmdIndex(int index, const char *cmdContent) | Starts the plug-in by index.| -| int PluginExecCmd(const char *name, int argc, const char **argv) | Starts the plug-in by command.| +| void PluginExecCmdByName(const char *name, const char *cmdContent) | Starts a plug-in by name.| +| void PluginExecCmdByCmdIndex(int index, const char *cmdContent) | Starts a plug-in by index.| +| int PluginExecCmd(const char *name, int argc, const char **argv) | Starts a plug-in by command.| | int AddCmdExecutor(const char *cmdName, CmdExecutor execCmd) | Adds the plug-in installation command.| ### How to Develop @@ -148,16 +150,16 @@ bootchart is available only for the standard system, and begetctl is available f 3. Restart the system. 4. Run the **begetctl bootchart stop** command. 5. Run the **begetctl bootchart disable** command. - 6. Export the following files from the **/data/bootchart** directory and save them to the **bootchart** folder:
+ 6. Export the following files from the **/data/bootchart** directory and save them to the **bootchart** folder: header
proc_diskstats.log
proc_ps.log
proc_stat.log
- 7. Run the tar -zcvf bootchart.tgz * command to compress the bootchart.tgz file (available only for Linux) and copy the compressed file to the linux:bootchart-master directory. - 8. Run the following command in the bootchart-master directory: + 7. Run the **tar -zcvf bootchart.tgz *** command to compress the **bootchart.tgz** file (available only for Linux) and copy the compressed file to the **linux:bootchart-master** directory. + 8. Run the following command in the **bootchart-master** directory: ``` python3 pybootchartgui.py -f pdf bootchart.tgz ``` Expected Result -
A **bootchart.pdf** file is generated in the **bootchart-master** directory. + A **bootchart.pdf** file is generated in the **bootchart-master** directory. diff --git a/en/device-dev/subsystems/subsys-boot-init-service.md b/en/device-dev/subsystems/subsys-boot-init-service.md index 38f88f250c..8a3a9ed0f6 100644 --- a/en/device-dev/subsystems/subsys-boot-init-service.md +++ b/en/device-dev/subsystems/subsys-boot-init-service.md @@ -9,7 +9,7 @@ Service configuration allows you to configure services on demand to create diffe For details, see [Description of service Fields](#table14737791471). -- init service startup control (for standard system or higher) +- init service startup control (for standard system or higher) The init process classifies services into three types based on service configurations and starts the services in different phases. @@ -17,7 +17,7 @@ Service configuration allows you to configure services on demand to create diffe - **normal**: common services in the system. This type of services are started in the post-init phase. This is the default service type. - **condition**: services that are started by running the startup command. You can add the **start xxxx** command to **jobs** to start the corresponding service. -- init service command execution (for standard system or higher) +- init service command execution (for standard system or higher) The init module provides the service command execution function, which allows services to execute different commands in different phases. @@ -41,7 +41,7 @@ Service configuration allows you to configure services on demand to create diffe With the parallel startup and command execution capabilities, processes can be started concurrently. -- init service on-demand startup +- init service on-demand startup If on-demand startup is enabled, the init process starts a service only when it is required. The **ondemand** attribute is used to determine whether to enable on-demand startup for a service. @@ -114,240 +114,24 @@ The service management module is available only for the mini system and standard By parsing the *.cfg file, you can obtain **service** fields, and then set and start the service. ### Parameters - **Table 1** Description of service fields - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Name - - Description - - Remarks - - Supported System Type -
- name - - Name of the current service. (Mandatory) - - Type: string. The value cannot be empty and can contain a maximum of 32 bytes. - - Small and standard systems -
- path - - Full path (including parameters) of the executable file for the current service. This is an array. (Mandatory) - - The first element is the path of the executable file, and the maximum number of elements is 20.
- Each element is a string that contains a maximum of 64 bytes. -
- Small and standard systems -
- uid - - User ID (UID) of the current service process. - - Type: int or string. - - Small and standard systems -
- gid - - Group ID (GID) of the current service process. - - Type: int, int[], string, or string array. - - Small and standard systems -
- once - - Whether the current service process is a one-off process. - - 1: The current service process is a one-off process. If the process exits, the init process does not restart it.
- 0: The current service process is not a one-off process. If the process exits, the init process restarts it upon receiving the SIGCHLD signal. -
- Small and standard systems -
- importance - - Current service priority. - - Standard system: The service priority ranges from -20 to 19. A value beyond the range is invalid.
- Small system: The value 0 indicates an unimportant process and a value greater than 0 indicates an important process. -
- Small and standard systems -
- caps - - Capabilities required by the current service. They are evaluated based on the capabilities supported by the security subsystem and configured in accordance with the principle of least permission. - - Type: number or string array. If you set the value to a number, use the standard Linux capability. If you set the value to a string array, use the standard macro name. - - Small and standard systems -
- critical - - Suppression mechanism for services. If the number of times a service is restarted exceeds the value N within the specified period T, the system will be restarted. - - Standard system:
Type: int array, for example, "critical": [M, N, T].
- M: enable flag (0: disable; 1: enable).
- N: number of times the service is started.
- T: period of time, in seconds.
Both M and N are greater than 0.
- Small and standard systems:
Type: int, for example, "critical": M.
M: enable flag (0: disable; 1: enable).
By default, N is 4 and T is 20. -
- Standard system -
- cpucore - - Number of CPU cores bound to the service. - - Type: int array, for example, "cpucore": [N1, N2, ...]. N1 and N2 indicate the indices of the CPU cores to be bound. For a single-core device, cpucore is 0. - - Standard system -
- d-caps - - Distributed service capability (for standard system or higher) - - Type: string array, for example, "d-caps": ["OHOS_DMS"]. - - Standard system -
- apl - - Ability privilege level (for standard system or higher). - - Type: string, for example, "apl": "system_core". The value can be system_core (default), normal, or system_basic. - - Standard system -
- start-mode - - Service startup mode (for standard system or higher). - - Type: string, for example, "start-mode": "condition". The value can be boot, normal, or condition. For details, see init Service Startup Control. - - Standard system -
- ondemand - - Whether on-demand startup is enabled. - - Type: bool, for example, "ondemand": true. This feature is available only for the small system running the Linux kernel. For details, see init Service On-Demand Startup. - - Small and standard systems -
- disable - - Reserved. - - None. - - Small and standard systems -
- sandbox - - Whether the sandbox function is enabled. - - 1 (default): Enable the sandbox function.
- 0: Disable the sandbox function. -
- Standard system -
+ **Table 1** Description of service fields
+ | Name| Supported System Type| Description| Remarks| + | ---------- |-------- | --------| --------| + | name | Small and standard systems | Name of the current service. (Mandatory)| Type: string. The value cannot be empty and can contain a maximum of 32 bytes.| + | path | Small and standard systems| Full path (including parameters) of the executable file for the current service. This is an array. (Mandatory)| The first element is the path of the executable file, and the maximum number of elements is 20.
Each element is a string that contains a maximum of 64 bytes.| + | uid | Small and standard systems| User ID (UID) of the current service process.| Type: int or string.| + | gid | Small and standard systems| Group ID (GID) of the current service process.| Type: int, int[], string, or string array.| + | once | Small and standard systems| Whether the current service process is a one-off process.| 1: The current service process is a one-off process. If the process exits, the init process does not restart it.
0: The current service process is not a one-off process. If the process exits, the init process restarts it upon receiving the SIGCHLD signal.| + | importance | Small and standard systems|
Standard system: service priority
Small system: service importance|
Standard system: The service priority ranges from -20 to 19. A value beyond the range is invalid.
Small system: The value 0 indicates an unimportant process and a value greater than 0 indicates an important process.| + | caps | Small and standard systems| Capabilities required by the current service. They are evaluated based on the capabilities supported by the security subsystem and configured in accordance with the principle of least permission.| Type: number or string array. If you set the value to a number, use the standard Linux capability. If you set the value to a string array, use the standard macro name.| + | critical | Standard system| Suppression mechanism for services. If the number of times a service is restarted exceeds the value N within the specified period T, the system will be restarted.|
Standard system:
Type: int array, for example, "critical": [M, N, T].
- M: enable flag (0: disable; 1: enable).
- N: number of times the service is started.
- T: period of time, in seconds.
Both M and N are greater than 0.
Small and standard systems:
Type: int, for example, "critical": M.
M: enable flag (0: disable; 1: enable).
By default, N is 4 and T is 20.| + | cpucore | Standard system| Number of CPU cores bound to the service.| Type: int array, for example, "cpucore": [N1, N2, ...]. N1 and N2 indicate the indices of the CPU cores to be bound. For a single-core device, cpucore is 0.| + | d-caps | Standard system| Distributed service capability.| Type: string array, for example, "d-caps": ["OHOS_DMS"].| + | apl | Standard system| Ability privilege level.| Type: string, for example, "apl": "system_core".
The value can be system_core (default), normal, or system_basic.| + | start-mode | Standard system| Service startup mode.| Type: string, for example, **"start-mode": "condition"**.
The value can be boot, normal, or condition. For details, see [init service startup control](#section56901555918).| + | ondemand | Small and standard systems| Whether on-demand startup is enabled.| Type: bool, for example, **"ondemand": true**. For small systems, this feature is available only on the Linux kernel.
For details, see [init Service On-Demand Startup](#section56901555920).| + | disable | Small and standard systems| Reserved.| None.| + | sandbox | Standard system| Whether the sandbox function is enabled.| 1 (default): Enable the sandbox function.
0: Disable the sandbox function.| **Table 2** Description of socket fields | Name| Description| @@ -362,10 +146,10 @@ By parsing the *.cfg file, you can obtain **service** fields, a | option | Socket option. This field is passed when **setsockopt** is called. Currently, the available options include SOCKET_OPTION_PASSCRED, SOCKET_OPTION_RCVBUFFORCE, SOCK_CLOEXEC, and SOCK_NONBLOCK.| ### Available APIs - **Table 3** FD proxy APIs + **Table 3** FD proxy APIs | API | Function| Description | | ---------- | ---------- |--------| - | int *ServiceGetFd(const char *serviceName, size_t *outfdCount) | Obtains the proxy FD from the init process.| Return value: Returns the pointer to the fd array if the operation is successful; returns **NULL** otherwise. (Note: Manual release is required.)
Arguments:
**serviceName**: service name.
**outfdCount**: length of the returned fd array.| + | int *ServiceGetFd(const char *serviceName, size_t *outfdCount) | Obtains the proxy FD from the init process.| Return value: Returns the pointer to the fd array if the operation is successful; returns **NULL** otherwise. (Note: Manual release is required.)
Arguments:
**serviceName**: service name.
**outfdCount**: length of the returned FD array.| | int ServiceSaveFd(const char *serviceName, int *fds, int fdCount) | Requests the init process for FD proxy.| Return value: Returns **0** if the operation is successful; returns **-1** otherwise.
Arguments:
**serviceName**: service name.
**fds**: pointer to the FD array for FD proxy.
**fdCount**: length of the FD array | int ServiceSaveFdWithPoll(const char *serviceName, int *fds, int fdCount) | Requests FD proxy in poll mode.| Return value: Returns **0** if the operation is successful; returns **-1** otherwise.
Arguments:
**serviceName**: service name.
**fds**: pointer to the FD array.
**fdCount**: length of the FD array. @@ -374,7 +158,7 @@ By parsing the *.cfg file, you can obtain **service** fields, a | :---------- | :---------- |:--------| | int ServiceControlWithExtra(const char *serviceName, int action, const char *extArgv[], int extArgc) | Configures service parameters.| Return value: Returns **0** if the operation is successful; returns **-1** otherwise.
Arguments:
**serviceName**: service name.
**action**: service action, which can be **start**, **stop**, or **restart**.
**extArgv**: parameter array.
**extArgc**: number of parameters.| | int ServiceControl(const char *serviceName, int action) | Controls the service behavior.| Return value: Returns **0** if the operation is successful; returns **-1** otherwise.
Arguments:
**serviceName**: service name.
**action**: service action, which can be **start**, **stop**, or **restart**.| - | int ServiceWaitForStatus(const char *serviceName, ServiceStatus status, int waitTimeout) | Waiting for service status| Return value: Returns **0** if the operation is successful; returns **-1** otherwise.
Arguments:
**serviceName**: service name.
**status**: service status.
**waitTimeout**: waiting timeout interval.| + | int ServiceWaitForStatus(const char *serviceName, ServiceStatus status, int waitTimeout) | waiting for the service status.| Return value: Returns **0** if the operation is successful; returns **-1** otherwise.
Arguments:
**serviceName**: service name.
**status**: service status.
**waitTimeout**: waiting timeout interval.| | int ServiceSetReady(const char *serviceName) | Sets a service as being ready.| Return value: Returns **0** if the operation is successful; returns **-1** otherwise.
Arguments:
**serviceName**: service name.| | int StartServiceByTimer(const char *serviceName, uint64_t timeout) | Starts a service by timer.| Return value: Returns **0** if the operation is successful; returns **-1** otherwise.
Arguments:
**serviceName**: service name.
timeout: timeout interval.| | int StopServiceTimer(const char *serviceName) | Stops a service timer.| Return value: Returns **0** if the operation is successful; returns **-1** otherwise.
Arguments:
**serviceName**: service name.| -- GitLab