Some startup scripts won´t execute [SOLVED]

Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions
Author Message
peppo
DD-WRT Novice


Joined: 26 Jul 2015
Posts: 27

PostPosted: Fri Mar 19, 2021 17:33    Post subject: Some startup scripts won´t execute [SOLVED] Reply with quote
Hi all,

I have a new R7800 (DD-WRT v3.0-r45955 std (03/09/21)) as replacement for my old Archer C7 V2.
I am basically using the same config like before, but with new entries in rc_startup and some of them basically won´t execute on startup.

Code:
root@StellarCom:~# nvram get rc_startup
sleep 40
/opt/etc/init.d/rc.unslung start     
/opt/etc/init.d/S61stubby.sh start
/opt/etc/init.d/syslog-script.sh 
/opt/etc/init.d/adblock.sh
/opt/etc/init.d/cpugov.sh         
/opt/etc/init.d/yamon.sh           


/opt/etc/init.d/rc.unslung start <=OK (old)
/opt/etc/init.d/S61stubby.sh start <= OK (old)
/opt/etc/init.d/syslog-script.sh <= OK (old)


/opt/etc/init.d/adblock.sh NOK (old)

not executing at startup, BUT it´s properly executed every noon as a cronjob.
Code:
0 12 * * * root /opt/etc/init.d/adblock.sh


Code:

#!/bin/sh
logger -t adblock "Starting Adblock hostfile script $0"
_rogue=0.0.0.0
echo -e "n=1\nwhile ! curl -sS -L --compressed "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" > /opt/tmp/hsts ; do\n\t[ \$n -gt 5 ] && break\n\tlet n+=1\n\tsleep 60\ndone\ngrep \"^0.0.0.0\" /opt/tmp/hsts | grep \"^0.0.0.0\" | grep -v localhost | awk '{print \"$_rogue\\\t\"\$2}' | tr -d '\\\015' >/opt/tmp/dlhosts\nrm /opt/tmp/hsts\nkillall -HUP dnsmasq" >/opt/tmp/wh
sh /opt/tmp/wh &



/opt/etc/init.d/cpugov.sh <= NOK (additional)
not executing at startup, BUT can properly executed at the command line. => /opt/etc/init.d/cpugov.sh

Code:

#!/bin/sh
logger -t cpugov "Setting CPU governor to ondemand $0"
for CPUGOV in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do [ -f $CPUGOV ] || continue; echo -n ondemand > $CPUGOV
echo 35 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
echo 10 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
done


/opt/etc/init.d/yamon.sh <= NOK (additional)
not executing at startup, BUT can properly executed at the command line. => /opt/etc/init.d/yamon.sh

Code:

#!/bin/sh
sleep 10
logger -t yamon "starting YAMon4 $0"
/opt/YAMon4/start.sh 'reboot'


I think, the permissions are set correctly:
Code:

root@StellarCom:/opt/etc/init.d# ll
-rwxr--r--    1 root     root         373 Oct 18  2019 adblock.sh.old
-rwxr-xr-x    1 root     root         418 Oct 20  2019 S61stubby.sh
-rwxr-xr-x    1 root     root         966 Oct 26 18:59 rc.unslung
-rw-r--r--    1 root     root        2.8K Oct 26 18:59 rc.func
drwxr-xr-x    7 root     root        4.0K Mar  9 20:39 ..
drwxr-xr-x    2 root     root        4.0K Mar 12 20:32 .
-rwxr-xr-x    1 root     root         647 Mar 15 19:28 syslog-script.sh
-rwxr-xr-x    1 root     root         486 Mar 15 20:18 adblock.sh
-rwxr-xr-x    1 root     root          86 Mar 15 20:20 yamon.sh
-rwxr-xr-x    1 root     root         343 Mar 15 20:25 cpugov.sh


I am a little cluess now.
I would really appreciate some ideas what could be wrong here...

Thanks
Peppo


Last edited by peppo on Fri Mar 19, 2021 19:14; edited 1 time in total
Sponsor
eibgrad
DD-WRT Guru


Joined: 18 Sep 2010
Posts: 9157

PostPosted: Fri Mar 19, 2021 18:07    Post subject: Reply with quote
Difficult to know for sure what the problem is from this side of the forum, but when it comes to the startup script (or any event script for that matter), you have to be careful about the possibility of a) one of the sub-scripts blocking, and b) if blocking occurs, the router killing the event script itself (iow, if it has a time limit).

That's why whenever possible, it's best to run any sub-scripts in the background (&), at least when they don't have any dependencies wrt each other. I was particularly suspicious this might be the problem here because all the ones that didn't run came after /opt/etc/init.d/syslog-script.sh, but I have no idea what it does and whether it can end up blocking.

_________________
ddwrt-ovpn-split-basic.sh (UPDATED!) * ddwrt-ovpn-split-advanced.sh (UPDATED!) * ddwrt-ovpn-client-killswitch.sh * ddwrt-ovpn-client-watchdog.sh * ddwrt-ovpn-remote-access.sh * ddwrt-ovpn-client-backup.sh * ddwrt-mount-usb-drives.sh * ddwrt-blacklist-domains.sh * ddwrt-wol-port-forward.sh * ddwrt-dns-monitor.sh (NEW!)
peppo
DD-WRT Novice


Joined: 26 Jul 2015
Posts: 27

PostPosted: Fri Mar 19, 2021 18:16    Post subject: Reply with quote
Will try.
should it look like this? /opt/etc/init.d/adblock.sh &

The syslog-script exports the syslog to USB-Stick.
Code:

#!/bin/sh
# place this script in the startup script
logger -t syslog-script "Starting syslog to USB $0"
while ! ntpclient 91.206.8.36; do sleep 10; done
while :; do
    while ! pidof syslogd; do sleep 10; done
    args="$(ps | grep [s]yslogd | awk '{print substr($0,index($0,$6,$NF))}')"
    my_syslog="/opt/var/log/syslog_$(date +"%Y-%m-%d-%H%M%S").txt"
    while ! killall syslogd; do sleep 10; done
    echo "----- original syslog ----->"  > $my_syslog
    cat /var/log/messages >> $my_syslog
    echo "<----- original syslog -----" >> $my_syslog
    > /var/log/messages
    syslogd -L -l 7 -nO $my_syslog $args
done
#. /opt/etc/init.d/rc.func
eibgrad
DD-WRT Guru


Joined: 18 Sep 2010
Posts: 9157

PostPosted: Fri Mar 19, 2021 18:19    Post subject: Reply with quote
peppo wrote:
Will try.
should it look like this? /opt/etc/init.d/adblock.sh &

The syslog-script exports the syslog to USB-Stick.
Code:

#!/bin/sh
# place this script in the startup script
logger -t syslog-script "Starting syslog to USB $0"
while ! ntpclient 91.206.8.36; do sleep 10; done
while :; do
    while ! pidof syslogd; do sleep 10; done
    args="$(ps | grep [s]yslogd | awk '{print substr($0,index($0,$6,$NF))}')"
    my_syslog="/opt/var/log/syslog_$(date +"%Y-%m-%d-%H%M%S").txt"
    while ! killall syslogd; do sleep 10; done
    echo "----- original syslog ----->"  > $my_syslog
    cat /var/log/messages >> $my_syslog
    echo "<----- original syslog -----" >> $my_syslog
    > /var/log/messages
    syslogd -L -l 7 -nO $my_syslog $args
done
#. /opt/etc/init.d/rc.func


Well in this particular case, the issue is whether the script *prior* to this script is blocking. If it is, this script and all the other that follow will NOT execute until the blocking stops.

FWIW, this script *could* block do the following line:

Code:
while ! ntpclient 91.206.8.36; do sleep 10; done


And this line (it seems to run continuously, no breaks).

Code:
while :; do


That's what you're trying to avoid!

_________________
ddwrt-ovpn-split-basic.sh (UPDATED!) * ddwrt-ovpn-split-advanced.sh (UPDATED!) * ddwrt-ovpn-client-killswitch.sh * ddwrt-ovpn-client-watchdog.sh * ddwrt-ovpn-remote-access.sh * ddwrt-ovpn-client-backup.sh * ddwrt-mount-usb-drives.sh * ddwrt-blacklist-domains.sh * ddwrt-wol-port-forward.sh * ddwrt-dns-monitor.sh (NEW!)
peppo
DD-WRT Novice


Joined: 26 Jul 2015
Posts: 27

PostPosted: Fri Mar 19, 2021 18:48    Post subject: Reply with quote
It´s working now. Thanks mate.

Code:

sleep 40
/opt/etc/init.d/rc.unslung start &
/opt/etc/init.d/S61stubby.sh start &
/opt/etc/init.d/syslog-script.sh &
/opt/etc/init.d/adblock.sh &
/opt/etc/init.d/cpugov.sh &
/opt/etc/init.d/yamon.sh &


And I commented out this line:
Code:
 while ! ntpclient 91.206.8.36; do sleep 10; done

because the router is already time set at this point.
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum