OpenHarmony的init程式、init配置與啟動項配置

秦舒云發表於2024-10-14

1. init程式編譯完後部署在

/bin/init

2. init程式的啟動配置檔案為

/system/etc/init.cfg

看一下內容與格式:

3.init程式的後續啟動指令碼放置目錄為

/system/etc/init/

裡面是以 .cfg結尾的檔案,我們看一下其中的1個重要啟動項配置檔案appspawn.cfg:

這個檔案在原始碼中儲存在:

./base/startup/appspawn/appspawn.cfg
{
    "jobs" : [{
            "name" : "service:nwebspawn",
            "cmds" : [
                "mkdir /mnt/sandbox",
                "mkdir /mnt/sandbox/com.ohos.render/ 0711 nwebspawn nwebspawn"
            ]
        }
    ],
    "services" : [{
            "name" : "appspawn",
            "path" : ["/system/bin/appspawn",
                      "--process-name com.ohos.appspawn.startup --start-flags daemon --type standard ",
                      "--sandbox-switch on --bundle-name com.ohos.appspawn.startup --app-operate-type operate ",
                      "--render-command command --app-launch-type singleton --app-visible true"],
            "importance" : -20,
            "uid" : "root",
            "gid" : ["root"],
            "socket" : [{
                "name" : "AppSpawn",
                "family" : "AF_LOCAL",
                "type" : "SOCK_STREAM",
                "protocol" : "default",
                "permissions" : "0660",
                "uid" : "root",
                "gid" : "appspawn",
                "option" : [
                ]
            },
            {
                "name" : "NWebSpawn",
                "family" : "AF_LOCAL",
                "type" : "SOCK_STREAM",
                "protocol" : "default",
                "permissions" : "0666",
                "uid" : "nwebspawn",
                "gid" : "nwebspawn",
                "option" : [
                ]
            }],
            "sandbox" : 0,
            "start-mode" : "boot",
            "secon" : "u:r:appspawn:s0",
            "jobs" : {
                "on-start" : "service:nwebspawn"
            },
            "bootevents" : "bootevent.appspawn.started"
        }
    ]
}

相關文章