(OK) run my script at boot time in android-x86_64 (Chih-Wei Huang)


https://groups.google.com/forum/#!topic/android-x86/yqaCDac58Zs



Chih-Wei Huang

https://en.wikipedia.org/wiki/Chih-Wei_Huang


There is a simpler way to run a customized script.
The system will automatically run
/system/etc/init.$hardware.sh
($hardware is the value in ro.hardware property)
on boot complete.

For example, to run eth0 in dhcp mode,
just put this line in that script:

start dhcpcd_eth0:eth0



++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Hi all,


I want to realize two things at boot time
1) get the eth0 up automatically at boot time
2) start an ssh daemon/server process. This process is compiled in external/myapps/sshd and appears correctly in /system/xbin/sshd. Furthermore, I have tested it in Android and starting it from the command line works perfectly.

Now, to get these two things started at boot time, I should modify the init.eeepc.rc file, as follows:

service startnetworking /system/bin/sh /system/etc/startnetworking.sh
     user root
     oneshot

service startsshd /system/xbin/sshd
    user root
    oneshoot

My startnetworking script is
#!/system/bin/sh
netcfg eth0 up
netcfg eth0 dhcp

I already discovered that it is not enough to modify the init.eeepc.rc file in out/target/product/eeepc/root/init.eeepc.rc. Rather, I have to modify it in device/asus/eeepc/init.eeepc.rc and then completely recompile my kernel to get the modifications actually in the init.rc, since apparently this is extraced from the ramdisk image at boot time (if I understood well).

This is quite a lengthy approach. Especially recompiling the kernel takes a long time.  Furthermore, I cannot get my scripts in the /system/etc folder.

My questions are:
- where in the source code do I have to put my own .sh scripts, so that they will appear in /system/etc?
- is /system/etc the right directory to put my own scripts? I did only find binaries in /system/xbin, so that's why I chose for /system/etc?
- what is the best way for fastest recompilation of the kernel? If I issues "make kernel TARGET_PRODUCT=eeepc", it says that nothing is to be done. And if I do a make clean, then it recompiles everything...

Thanks in advance!
Pieter
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

To add your script to your build output you can add to PRODUCT_COPY_FILES in one of your device make files. If you dig through some of the device directories you should see a place where someone is doing it already.


Example
PRODUCT_COPY_FILES += \
    $(LOCAL_PATH)/startnetworking:system/etc/startnetworking


Yolan

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

1. I don't know, I have no experience compiling Android from source :'(
2. It's better to put your own script in Android global PATH /system/bin or /system/sbin or /system/xbin.
3. The fastest way is decompress, modify, and then compress back the ramdisk.img but this is not a good way if you have a change to compile Android from source.

Sorry, my English not good enough :(

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Hi all,


thank you very much for your help.  The script is now available inside /system/sbin, but it seems it is not executed.

Here are the details.
In my init.eeepc.rc:

service sampleservice /system/bin/sh /system/sbin/samplescript.sh
     user root
     oneshot

The script itself:
#!/system/bin/sh
echo The sample script works!
echo "The sample script works!" > /data/misc/samplescript

The permissions of /system/sbin/samplescript.sh are as follows: -rw-r--r--    


Doing from command line "sh /system/sbin/samplescript.sh" works perfectly, but it seems the script is not executed at boot time. There are no entries in /data/misc/samplescript


* How can I resolve this issue? Where should I see the output of the "echo" command? Is there another/better way to have it printed in logcat or dmesg?
* The script itself is not executable. Does this matter and if yes, how do I have to make it executable? In my original directory it is executable, but somehow during the copy process (with PRODUCT_LOCAL_COPY) the executable rights disappear.
* Another option I see is that I did not "register" a service as such and perhaps this is just not the right way to call a sh script at boot time?

Any help is more than welcome!
Best regards,
Pieter

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

I solved the issue.


You have to add "class main" in the init.<target>.rc service specification.
Only class main and class core are automatically started by init.rc, and if you do not mention a class explicitly, it is in the class "default".

(otherwise, you have to add class_start YOURGROUP in the on boot section of init.<target>.rc section yourself)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Chih-Wei Huang

https://en.wikipedia.org/wiki/Chih-Wei_Huang


There is a simpler way to run a customized script.
The system will automatically run
/system/etc/init.$hardware.sh
($hardware is the value in ro.hardware property)
on boot complete.

For example, to run eth0 in dhcp mode,
just put this line in that script:

start dhcpcd_eth0:eth0



posted @ 2016-06-29 17:27  张同光  阅读(129)  评论(0编辑  收藏  举报