简体   繁体   English

Android 在启动时使用 init.rc 运行脚本不起作用

[英]Android run script at boot using init.rc not working

I'm trying to run a script that exectues when the device has finished booting.我正在尝试运行一个在设备完成启动时执行的脚本。 This particular device does not support running scripts from an init.d directory, which is why I am using init.rc.这个特定设备不支持从 init.d 目录运行脚本,这就是我使用 init.rc 的原因。

The init.rc file has been modified to include the following code init.rc 文件已修改为包含以下代码

on property:sys.boot_completed=1
start initAsic

service initAsic /data/local/tmp/runn.sh
user root
group root
oneshot

The boot image has then been rebuilt and flashed to the device.然后,启动映像已重建并刷新到设备。 The changes can be confirmed by viewing the init.rc file located at /可以通过查看位于/的 init.rc 文件来确认更改

Currently I am only using a simple test script (testScript.sh) which issues the following command目前我只使用一个简单的测试脚本(testScript.sh),它发出以下命令

echo hi >> /data/local/tmp/test.txt

The testScript.sh and text.txt file has 777 permissions set and both have been pushed to the device using adb push . testScript.sh 和 text.txt 文件设置了777权限,并且都已使用adb push推送到设备。 Their current location is /data/local/tmp/他们当前的位置是/data/local/tmp/

For some reason it seems that my script is not running, as I can't see any text being written to test.txt.出于某种原因,我的脚本似乎没有运行,因为我看不到任何文本被写入 test.txt。

Am I missing something?我错过了什么吗? Could it be an issue with SELinux?会不会是 SELinux 的问题?

My device currently has SElinux set to permissive.我的设备目前已将 SElinux 设置为许可。 This was done via altering the BoardConfig.mk file and doing a rebuild of the boot.img.这是通过更改 BoardConfig.mk 文件并重建 boot.img 来完成的。

By running the command dmesg | grep -C5 initAsic通过运行命令dmesg | grep -C5 initAsic dmesg | grep -C5 initAsic I saw that I was getting this error code returned dmesg | grep -C5 initAsic我看到我收到了这个错误代码

service initAsic does not have a SELinux domain defined

The issue what that I needed to add the line seclabel u:r:init:s0 to my init service.我需要将行seclabel u:r:init:s0添加到我的初始化服务中的问题。 The complete service now looks like this.完整的服务现在看起来像这样。

service initAsic2 /data/local/tmp/runn.sh
seclabel u:r:init:s0
user root
group root
oneshot
disabled

The disabled keyword has also been added as per sugestion by another SO member, although not sure if it is necessary. disabled 关键字也已根据另一个 SO 成员的建议添加,但不确定是否有必要。

Also note that SElinux must be set to permissive to allow this service to run or alternatively a policy must be set to allow the service to run.另请注意,必须将 SElinux 设置为permissive以允许该服务运行,或者必须设置策略以允许该服务运行。 There are several techniques to doing so.有几种技术可以做到这一点。 The one that worked for me involved adding the follwing line to the BoardConfig.Mk file for my device对我有用的一项是将以下行添加到我的设备的 BoardConfig.Mk 文件中

BOARD_KERNEL_CMDLINE += androidboot.selinux=permissive

and doing a rebuild/flash of the updated boot image.并对更新的引导映像进行重建/刷新。

This post was where I found the suggestion to add seclabel property.这篇文章是我发现添加 seclabel 属性的建议的地方。 It also has more useful information regarding the SELinux issue I was encountering: init warning: Service myservice needs a SELinux domain defined.它还包含有关我遇到的 SELinux 问题的更多有用信息: 初始化警告:Service myservice 需要定义 SELinux 域。 Please fix 请修复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM