-1

I have created a simple HelloWorld application. I want to autostart my application in OpenWRT(19.07.1) just after boot up. The application should be started automatically after the shell prompt comes.

My helloworld application is in /usr/bin

I want to start this application automatically after bootup in openwrt

here is what I have created in /etc/init.d/script.sh

#!/bin/sh

START=10

start() {

    echo start 

    /usr/bin/helloworld

}

then

chmod +x script    
/etc/init.d/script enable

After this I rebooted

I tried the above steps, but after rebooting no changes are reflected

manually I'm able to run my application.

Please help to resolve this issue.

Can anyone please write script for me??

  • 1
    I reformated your post - please check if correct. `./usr/bi` what is that dot doing there? – KamilCuk Jul 23 '20 at 12:53
  • this is how i'm executing my application manually.. – AAKARSH JAIN Jul 23 '20 at 12:55
  • From which directory are you executing your application manually? Do you understand what dot in front of a pathname means and the different between relative and absolute path? – KamilCuk Jul 23 '20 at 12:58
  • Actually I have created my application's package and I have installed it using opkg install helloworld_1.0-1_x86_64.ipk. So helloworld application is installed in /usr/bin.Application can be executed directly also with helloworld. There is no need of ./usr/bin/helloworld..I tried with simple helloworld and ./usr/bin/helloworld ,but both are not working automatically.....and both are working manually.... – AAKARSH JAIN Jul 23 '20 at 13:05
  • Please make sure that `helloworld` is in the path `/usr/bin`, and then remove the dot from the line in the script. – the busybee Jul 23 '20 at 13:09
  • As you said I tried removing dot from my script .then i did /etc/init.d/script enable ..and then reboot...but still not working...I also wrote mkdir dir_name in the script and after rebooting that directory is getting created but my application is not getting started. – AAKARSH JAIN Jul 23 '20 at 13:15
  • I have also followed https://stackoverflow.com/questions/33340659/how-to-auto-start-an-application-in-openwrt....But unfortunately this also not working for me – AAKARSH JAIN Jul 23 '20 at 13:18
  • Which part of the question is related to C language? – Gerhardh Jul 23 '20 at 16:49
  • No part..sorry. – AAKARSH JAIN Jul 23 '20 at 16:57

2 Answers2

2

Your shebang line,

#!/bin/sh /etc/rc.common

is wrong: it causes the shell to read and execute /etc/rc.common instead of the current file. Change it to

#!/bin/sh

instead, and it should now work.


If you have /usr/bin/whatnow:

#!/bin/sh /usr/local/bin/helpers

This part of the script will never be interpreted by the shell.

and /usr/local/bin/helpers:

#!/bin/sh

echo "This is the helper!"

then running whatnow will output This is the helper!.

None
  • 281
  • 1
  • 3
  • Thanks for your response.How to call this script automatically after boot up in openwrt? – AAKARSH JAIN Jul 23 '20 at 16:56
  • None's answer is correct. Regarding "start script automatically", look here: https://openwrt.org/docs/techref/initscripts. Basic steps: 1) Put "script" (please consider a better name, but...) in `/etc/init.d/script`, 2) Make it executable, 3) Enabled it at startup: `/etc/init.d/script enable`. Please "upvote" and "Accept" None's answer if it helped :) – FoggyDay Jul 23 '20 at 17:02
  • I got your point.....Can you please write that script??Actually I tried but not working for me...my application name is helloworld.. – AAKARSH JAIN Jul 23 '20 at 17:09
  • Can anyone write that script for me please..?? – AAKARSH JAIN Jul 23 '20 at 17:16
  • #!/bin/sh START=10 start() { echo start /usr/bin/helloworld This is my script....and helloworld is the application which I want to launch automatically after bootup......Is this correct??? – AAKARSH JAIN Jul 23 '20 at 17:35
  • @AAKARSHJAIN : Update the body of your Q above and indicate that "This is my best attempt to solve my problem". Requests to "write the script for me" (even with "please") are frowned upon here. (Just saying). Did you remove the the `/etc/rc.common` as mentioned above. Be sure that we are looking at your best attempt to solve your problem. Good luck. – shellter Jul 23 '20 at 17:43
1

Create a procd script as described in OpenWRT procd init script example. Place your script in /etc/init.d/<filename>.

It can look like this:

#!/bin/sh /etc/rc.common
USE_PROCD=1
START=95
STOP=01
start_service() {
    procd_open_instance
    procd_set_param command /bin/sh "/var/myscript.sh"
    procd_close_instance
}

There is many more options available in the manual.

adamkonrad
  • 6,794
  • 1
  • 34
  • 41