How to auto start an application in openwrt?
Asked Answered
T

3

14

I have created a shell with necessary functions such as start() stop() restart()

But my file is not getting started at boot time.

I have used update-rc.d command in "ubuntu" to add this file to the list of autostart applications. And it was successfully started at boot time.

But in "openwrt" I have seen an enable function. Anyone aware of how to use this enable function or is there any similar command like update-rc.d in "openwrt"

I had some reference here : http://wiki.openwrt.org/doc/techref/initscripts

Tope answered 26/10, 2015 at 7:37 Comment(2)
This question is not about the C language, remove the c tag.Wino
my mistake... Its removed..Tope
F
8

/etc/init.d/ - directory will by automaticly readed and searching for boot function or START STOP. Starts at boot time.

boot() {
        echo boot
        # commands to run on boot
}

START-Position then to start

STOP-Position then to stop

START=10 
STOP=15

start() {        
        echo start
        # commands to launch application
}                 

stop() {          
        echo stop
        # commands to kill application 
}

EDITED:

In /etc/rc.common directory files are compiled whoes going to start on boot.

Enable your function: /etc/init.d/your_script.sh enable

Here you will find more information about booting http://wiki.openwrt.org/doc/techref/process.boot

Filthy answered 26/10, 2015 at 8:14 Comment(1)
Thanks for the response, But content in the link provided with the question saying the same thing. I tried it.. But not workingTope
H
29
  1. Make sure the first line of your script reads:

    #!/bin/sh /etc/rc.common
    
  2. Copy your script to the /etc/init.d/ directory

  3. Make sure the execute bit is on

    chmod +x /etc/init.d/<your script>
    
  4. Enable your script

    /etc/init.d/<your script> enable
    

    Your script should now have a symlink in /etc/rc.d/

    ls -lh /etc/rc.d | grep <your script>
    
  5. Confirm your init script is enabled:

    /etc/init.d/<your script> enabled && echo on
    

    If this command returns on, then you're all set. If this command doesn't return anything, then your script isn't enabled. Here's an example of a script that's enabled:

    root@OpenWrt:~# /etc/init.d/system enabled && echo on
    on
    

I've tested these steps on OpenWrt Chaos Calmer 15.05 but it should work on earlier versions. Good luck!

Hydrophilous answered 14/11, 2015 at 11:58 Comment(1)
This is gold. I've come back to this answer several times now. :)Bhagavadgita
F
8

/etc/init.d/ - directory will by automaticly readed and searching for boot function or START STOP. Starts at boot time.

boot() {
        echo boot
        # commands to run on boot
}

START-Position then to start

STOP-Position then to stop

START=10 
STOP=15

start() {        
        echo start
        # commands to launch application
}                 

stop() {          
        echo stop
        # commands to kill application 
}

EDITED:

In /etc/rc.common directory files are compiled whoes going to start on boot.

Enable your function: /etc/init.d/your_script.sh enable

Here you will find more information about booting http://wiki.openwrt.org/doc/techref/process.boot

Filthy answered 26/10, 2015 at 8:14 Comment(1)
Thanks for the response, But content in the link provided with the question saying the same thing. I tried it.. But not workingTope
P
4

If you need to run your command only at system start (just after boot): edit /etc/rc.local that is your file.

By default it contains just comments (Designated Driver, but this was the case in some earlier versions also):

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

You can add commands here.

My example:

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

if grep -q '/dev/sdb2' /proc/swaps ; then swapoff /dev/sda2 ; fi
comgt -s /etc/config/init-script.comgt
Prehistory answered 16/5, 2017 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.