Run Shell script on boot in AOSP 11

Viewed 287

I am building AOSP 11 for emulator x86_64 and trying to run shell script on boot.

Below is my shell script test.sh

#!/vendor/bin/sh

echo "Hello" >> /data/local/tmp/test.txt

created myrc.rc file to create service

service runapp /vendor/bin/test.sh
        class main
        seclabel u:r:init-myservice:s0
        user root
        group root
        oneshot
        disabled

on property:dev.bootcomplete=1
        start runapp

In device/generic/goldfish/sepolicy/x86/file_contexts i have file_contexts with

/vendor/bin/test.sh u:object_r:init-myservice_exec:s0

In device/generic/goldfish/sepolicy/x86/init-myservice.te

type init-myservice, domain;
type init-myservice_exec, exec_type, vendor_file_type, file_type;

init_daemon_domain(init-myservice)

allow init-myservice vendor_file_type:file { execute getattr map open read };
allow init-myservice vendor_toolbox_exec:file read;

Add myrc.rc and test.sh in device/generic/goldfish/x86_64-vendor.mk file

PRODUCT_COPY_FILES += \
    external/service/test.sh:$(TARGET_COPY_OUT_VENDOR)/bin/test.sh \
    external/service/myrc.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/myrc.rc \

In build/make/target/board/generic_x86_64/BoardConfig.mk

BOARD_SEPOLICY_DIRS += device/generic/goldfish/sepolicy/x86

But I can't see any file test.txt created in /data/local/tmp/

It's look like service not running on boot.

I have checked dmesg logs but there not any logs of "runapp" service which i have created.

Anyone have idea on this ?

1 Answers

@GNK,for the rooted device below solution is working No need to define any domain.

create rc file with below configuration

**service runapp /system/bin/test.sh class main seclabel u:r:su:s0 user root group root oneshot disabled

on property:dev.bootcomplete=1 start runapp**

Modify your make file to put this files.

  1. Put rc file in /etc/init/
  2. Put test.sh in /system/bin/
Related