title: Running a script as a service from init.rc on Android at boot
body: <p>In order to execute a script on Android (Samsung Note 10.1 (N8010), 4.4.2) at boot I added the following to the end of the <code>init.rc</code> (unpacking/repacking the <code>boot.img</code>) to have it run as a service:</p>
  
  <pre><code>service test /system/bin/test_script.sh
      class main
      oneshot
  </code></pre>
  
  <p>The script looks like this:</p>
  
  <pre><code> #!/system/bin/sh
   mkdir /sdcard/test_directory
  </code></pre>
  
  <p>It is eventually supposed to do something else, but for testing I kept it simple. Permissions are <code>0755</code>.</p>
  
  <p>The problem though is that the directory <code>/sdcard/test_directory</code> is not being created, which leads me to believe that the service is never being started, i.e, the script is never being executed.</p>
  
  <p>I've already tried numerous things mentioned in other threads.
  E.g., adding the line <code>user root</code> to the service, rebooting multiple times (since apparently a service is not being started after booting the device right after flashing the <code>boot.img</code>) or putting the script in different folders like <code>/system/etc/</code> or <code>/data/local/tmp</code>.</p>
  
  <p>Any idea what could be the problem?
  Is it possible to somehow monitor whether the service is actually being started (maybe it is, but the problem lies within the script)?
  Is there maybe even a better way to executing a script at boot (device does not have <code>init.d</code> support and I don't want to use an app like <a href="https://play.google.com/store/apps/details?id=com.androguide.universal.init.d&amp;hl=en" rel="nofollow">Unversal Init.d</a>)?</p>
  
  <p>EDIT:</p>
  
  <p>Don't know why, but it works now.</p>
  
  <p>Moved the script around multiple times, ended up putting it under /data and removing the file extension. Also added some more lines to the script like <code>mkdir /data/local/tmp/test_directory</code>. The directory under <code>/sdcard</code> is not being created though (maybe a permission problem?). Probably the reason, why I thought the script had not been executed, if it has been before.</p>
  
  <p>Question remaining: is there a way to monitor whether a service is actually being started?</p>