running a script from init.rc

11,123 views
Skip to first unread message

HV

unread,
Apr 24, 2012, 8:46:39 PM4/24/12
to android...@googlegroups.com
Hi All,

 I'm trying to initiate a script as a service from init.rc (running ICS), but it doesn't seem to work. Here is what I have:

************
service my_sh /system/bin/sh ./system/etc/my.sh
    user root
    group root
#    oneshot

And my.sh is very simple:

#!/system/bin/sh

echo "Executing my.sh"
lsmod
************

Any ideas what could be missing?

Thanks
HV

sathish kumar

unread,
Apr 25, 2012, 2:35:27 AM4/25/12
to harishv...@gmail.com, android...@googlegroups.com
follow how debuggerd service is called. it will work. and add oneshot


HV

unread,
Apr 25, 2012, 2:10:46 PM4/25/12
to android...@googlegroups.com
Hi Kumar,

  debuggerd is an executable, but what i'm trying to run is a script, so it's not exactly the same

Thanks
HV

On Tuesday, April 24, 2012 11:35:27 PM UTC-7, kumar wrote:
follow how debuggerd service is called. it will work. and add oneshot
On Wed, Apr 25, 2012 at 6:16 AM, HV <harishv...@gmail.com> wrote:
Hi All,

 I'm trying to initiate a script as a service from init.rc (running ICS), but it doesn't seem to work. Here is what I have:

************
service my_sh /system/bin/sh ./system/etc/my.sh
    user root
    group root
#    oneshot

And my.sh is very simple:

#!/system/bin/sh

echo "Executing my.sh"
lsmod
************

Any ideas what could be missing?

Thanks

Matthias Kaehlcke

unread,
Apr 25, 2012, 2:23:15 PM4/25/12
to HV, android...@googlegroups.com
El Tue, Apr 24, 2012 at 05:46:39PM -0700 HV ha dit:
by default Androids init redirects stdout and stderr to /dev/null,
therefore you won't see the output of this script. to see if the
service is executed you could make it create a file. also remove the
dot before the script name, it will probably work but you shouldn't
rely on init having / as working directory. and uncomment the oneshot
attribute, otherwise your script will be executed continuously

regards

--
Matthias Kaehlcke
Embedded Linux Developer
Amsterdam

La posibilidad de realizar un suenyo es lo
que hace que la vida sea interesante
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-

Chris Stratton

unread,
Apr 25, 2012, 2:55:35 PM4/25/12
to android...@googlegroups.com
On Tuesday, April 24, 2012 8:46:39 PM UTC-4, HV wrote:
Hi All,

 I'm trying to initiate a script as a service from init.rc (running ICS), but it doesn't seem to work. Here is what I have:

************
service my_sh /system/bin/sh ./system/etc/my.sh

Why are you staring what looks to be an absolute path with "." ??
 

Harish V

unread,
Apr 25, 2012, 2:59:01 PM4/25/12
to Matthias Kaehlcke, android...@googlegroups.com
Hi Matthias,

 Thanks for your response. I got the syntax sorted out now:

service my_sh /system/etc/my_sh.sh
    class main
#    user root
#    group root
    oneshot

With this, I do see the service kicking in. The next challenge is how do I get the script to work. Say if I want to cd /mnt/sdcard & this should show up in the shell prompt. Is that doable? In other words, it should work exactly as though I'm manually running the script

Thanks
HV

Matthias Kaehlcke

unread,
Apr 25, 2012, 3:12:37 PM4/25/12
to Harish V, android...@googlegroups.com
El Wed, Apr 25, 2012 at 11:59:01AM -0700 Harish V ha dit:

> Thanks for your response. I got the syntax sorted out now:
> service my_sh /system/etc/my_sh.sh
> class main
> # user root
> # group root
> oneshot
> With this, I do see the service kicking in. The next challenge is how do I
> get the script to work. Say if I want to cd /mnt/sdcard & this should show
> up in the shell prompt. Is that doable? In other words, it should work
> exactly as though I'm manually running the script

you expect the service to change the working directory of the console
process? that won't happen, the service runs in a separate process
with its own working directory, the cd command will only affect the
working directory of the service

best regards

--
Matthias Kaehlcke
Embedded Linux Developer
Amsterdam

El camino se hace al andar
(Antonio Machado)

Alvin Wong

unread,
Apr 26, 2012, 2:55:37 AM4/26/12
to android-porting
My words on this:
Follow that goldfish thing.

Note that all services outputs to /dev/null so you never see it in the
console. (How often
do you see outputs of services?) You can use logwrapper to log in
logcat or use redirection in script to output to files.

Good luck,
Alvin Wong

Chris Stratton

unread,
Apr 26, 2012, 3:18:35 PM4/26/12
to android...@googlegroups.com, Matthias Kaehlcke
On Wednesday, April 25, 2012 2:59:01 PM UTC-4, HV wrote:
 
With this, I do see the service kicking in. The next challenge is how do I get the script to work. Say if I want to cd /mnt/sdcard & this should show up in the shell prompt. Is that doable? In other words, it should work exactly as though I'm manually running the script

Are you saying you want to pre-run commands in the adb shell session?  Or the shell of a terminal emulator on the device?   



HV

unread,
Apr 26, 2012, 3:28:57 PM4/26/12
to android...@googlegroups.com
I wanted the commands that I'm running from within the script get translated on to the console. But, I guess that's not possible

Chris Stratton

unread,
Apr 26, 2012, 10:47:35 PM4/26/12
to android...@googlegroups.com
On Thursday, April 26, 2012 3:28:57 PM UTC-4, HV wrote:
I wanted the commands that I'm running from within the script get translated on to the console. But, I guess that's not possible

That depends on what you mean by "translated" and "console" - neither term matches very well with the possibilities.

Perhaps back up and tell us what running these commands is supposed to accomplish, which may suggest how to handle them.


Alvin Wong

unread,
Apr 27, 2012, 2:02:51 AM4/27/12
to android-porting
Hi,

If you need to do some setup job (for example setting hardware, e.g.
cpu scaling) you can use a script, just look into `init.goldfish.rc`
and `/system/etc/init.goldfish.sh`.

However I don't think you would like to show something in the console.
Android has a GUI, and normally you don't want to show information to
the user in this way.
If this is for debug purpose, you'd probably use `logwrapper` to wrap
your script or use output redirection (`command > file`) for commands
in your script, or just type into the serial console or adb shell, or
you can even use Terminal Emulator.

You know, we don't usually expect and don't need the output of
services to show in the console. All services launched by `init` are
redirected to `/dev/null` so you cannot see them.

Perhaps you can point out what exactly you want to do and some of us
would help you decide the best way to do that.

Good luck,
Alvin Wong

HV

unread,
Apr 30, 2012, 4:41:44 PM4/30/12
to android...@googlegroups.com
Thanks for all your responses, appreciate it. I was able to put up a script that does the job

Chen Jiaqi

unread,
Jun 25, 2013, 11:16:53 PM6/25/13
to android...@googlegroups.com
Please try like this:

on boot
exec /system/bin/sh ./system/etc/my.sh

add to init.rc

在 2012年4月25日星期三UTC+8上午8时46分39秒,HV写道:

Ravishka Fernando

unread,
Mar 24, 2014, 3:59:12 PM3/24/14
to android...@googlegroups.com
Hello all :) sorry for posting an off topic question but this is the only forum which I found close to my situation..

My device (HTC Amaze 4G) executes some system/bin files in the boot process for various services, such as (qcks, ks, ewmutzd, akmd, uimq) bin files.. Well I ported kernel 3.4 to htc amaze 4G, and for ramdisk i mostly used the stuff from stock ics ramdisk but when my rom (JB Sense) boots none of those files get executed.. I tried

service kickstart /system/bin/qcks 1
class core
oneshot

Like in stock when it didn't work I entered "start kickstart" under post-fs
Still nothing happening..The files are there in the system/bin directory but the service doesn't start :/ what am i missing?

Steve Jones

unread,
Mar 25, 2014, 1:53:40 PM3/25/14
to android...@googlegroups.com
Hi 

You'd probably get your problem solved a lot quicker if you provided the ramdisk.img ( or boot.img ) you are using. 
At a guess however I would make sure the .rc permissions are set to 644 otherwise the init process will class the file as unsafe and refuse to process it which is probably the likely cause here....  You can find out for sure by running adb shell dmesg during the boot process, assuming you have it all enabled.. You should see a message like "skipping insecure file <filename>". 

Hope that Helps

Ravishka Fernando

unread,
Mar 26, 2014, 6:42:42 AM3/26/14
to android...@googlegroups.com
thats my ramdisk ... i did everything i know at this point i'm too confused i'm not sure what to do anymore :/ the only change is that in stock htc ramdisk it's named as 'init.ruby.rc and unvented.ruby.rc'' in this it's target.rc .. when i name as ruby the rom bootloops..
boot.img-ramdisk.zip
Reply all
Reply to author
Forward
0 new messages