Ringo001
Ringo001

Reputation: 163

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.

The init.rc file has been modified to include the following code

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 /

Currently I am only using a simple test script (testScript.sh) which issues the following command

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. Their current location is /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.

Am I missing something? Could it be an issue with SELinux?

My device currently has SElinux set to permissive. This was done via altering the BoardConfig.mk file and doing a rebuild of the boot.img.

Upvotes: 6

Views: 9445

Answers (1)

Ringo001
Ringo001

Reputation: 163

By running the command dmesg | grep -C5 initAsic I saw that I was getting this error code returned

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. 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.

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. 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

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. It also has more useful information regarding the SELinux issue I was encountering: init warning: Service myservice needs a SELinux domain defined. Please fix

Upvotes: 5

Related Questions