Run script using init.rc doesn't work


Question

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.


Answer

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 as this is a requirement of init. The complete service now looks like this. The disabled keyword has also been added as suggested by Irfan.



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


Also note that SElinux must be set to permissive to allow this service to run or preferably - as setting SElinux to permissive is a security risk - defining the appropriate rules for SElinux and using the modified policy.



More information on the topic here: https://android.stackexchange.com/a/207647/218526



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: https://stackoverflow.com/questions/43600261/init-warning-service-myservice-needs-a-selinux-domain-defined-please-fix


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes