Init script working manually but never automatically

Hello, First thanks for the community developers and supporter for this awesome software I have been running it for years and it always did the job and never caused me a trouble after good configurations.

recently I've upgraded to version 19 from an older one, I didn't notice any faced any issue except that an old custom routing init script isn't working anymore:

#!/bin/sh /etc/rc.common
 
START=25
 
start()
{
        sleep 20
        ip route add default via 192.168.40.1
        ip rule add from 192.168.50.0/24 priority 10 table wan2
        ip route add 192.168.50.0/24 dev br-landenver table wan2
        ip route add default via 127.104.21.** table wan2
}

I've tried to move start to 100 and increase sleep to 60 second but it doesn't help. When I run it manully using

/etc/init.d/customrule start

it runs perfectly.

I thought it could be an issue with the new PROCD so I wrote this:

#!/bin/sh /etc/rc.common
 
# Description: Enable custom route
# Author: Uak
 
START=90
USE_PROCD=1
EXTRA_COMMANDS="status"
EXTRA_HELP="        status      Print Homebridge run information"
 
is_running() {
    pgrep 'customRoute' > /dev/null 2>&1
}
 
start_service() {
    procd_open_instance "customRoute"
    procd_set_param command "ip route add default via 192.168.40.1"
    procd_set_param command "ip rule add from 192.168.50.0/24 priority 10 table wan2"
    procd_set_param command "ip route add 192.168.50.0/24 dev br-landenver table wan2"
    procd_set_param command "ip route add default via 127.104.21.** table wan2"
    procd_set_param stdout 1
    procd_set_param stderr 1
    procd_close_instance
}
 
reload_service(){
    echo "Restarting customRoute"
    stop
    start
}
 
status()
{
    if is_running; then
        echo "Running"
    else
        echo "Stopped"
        exit 1
    fi
}
~

it seemed that only one line from the commands I want to run is working. What did I do wrong, any help please?

I don't know the issue, but does the command
ip a s > /tmp/ip.out
work?

Yes it works. It shows may interfaces information

OK, so it works, being placed in your script?

Is it possible that the script was not enabled? Check /etc/rc.d/S...

Note that sleep command will block following init script from running

The quoting is incorrect. procd service instance corresponds to a single subprocess, i.e. "arg0" "arg1" ...

I would suggest switching to using either "config routein/etc/config/network`, or writing hotplug script for this.

no, I'll try that when I'm not connected remotely

I've checked it in /etc/rc.d/S... it is enabled.
Regarding the config in /etc/config/network I couldn't find if it accept the priority flag used by "ip" it seemed important to have my setup work.

I hope I can make those few commands works instead of moving to more complicated things, but I may have to at the end.

I agree that iproute2 commands are more straightforward compared to uci configs :wink:

I never used "ip rule" in uci network config, but "ip route" should work quite well

But I am still very curious why your script fails at the moment. Can you maybe redirect command errors to /dev/kmsg to show more details?

I do not It think you can use PROCD here. I would revert to the first version and debug it.

Add exec >>/root/log 2>&1 as the second line followed by set -x, reboot, then check the /root/log file for how the script ran and what happened.

It is possible that you have to implement this as a hot plug script instead: there could be something that resets the interfaces after your script is finished.

1 Like

100 is naturally wrong.
The number gets placed to the end of the symlink filename in /etc/rc.d, which files are then evaluated in alphabetical order, so 100 would be pretty much like 10.
Range is 01-99 ( and preferably 01-94, as /etc/rc.local is evaluated at 95)

/etc/rc.local would also be a natural place for those commands.

5 Likes

Thank you that solved it for me. I used my old script not the new PROCD format and set START to 94 it's working now.

Thank you to all people who tried to help with this issue.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.