I've noticed that my custom init.d scripts on my Yun do not start when the Yun is first powered on. If, once booted, I SSH into the Yun and issue the linux "reboot" command, when the Yun is rebooted then the init.d scripts start.
To prove this, I created the following script:
#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007 OpenWrt.org
START=10
STOP=15
start() {
touch /root/started
}
stop() {
touch /root/stopped
}
The above file was saved as /etc/init.d/test
After making the script executable (chmod +x /etc/init.d/test), I then enabled the script by executing the command:
/etc/init.d/test enable
...which created the relevant symlinks /etc/rc.d/S10test and /etc/rc.d/K15test
To confirm whether the init.d script was executed, I list the files in /root:
ls -al
...and check the timestamp of the "started" file.
The timestamp only appears to change when the "reboot" command is issued, and never when the Yun is first powered on.
I would be really grateful if someone could offer some advice on why these scripts don't start on power on.
Thanks.
If you need correct time stamp at boot, then need install ntpdate
opkg update
opkg install ntpdate
/etc/init.d/ntpdate enable
nano /etc/init.d/ntpdate
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2008 OpenWrt.org
START=60
STEP_SERVERS="0.openwrt.pool.ntp.org 1.openwrt.pool.ntp.org 2.openwrt.pool.ntp.$
TIMEOUT="2" # in seconds
start() {
for s in $STEP_SERVERS ; do
/usr/sbin/ntpdate -s -b -u -t "$TIMEOUT" "$s" && break
done
}
Since START=60 at ntpdate, move test to START=99
...
START=99
...
photomoose:
::::SNIP::::
-
The timestamp only appears to change when the "reboot" command is issued, and never when the Yun is first powered on.
-
I would be really grateful if someone could offer some advice on why these scripts don't start on power on.
Thanks.
@photomoose,
What your are writing is (mostly) correct.
On #1, there is no RTC (Real Time Clock) on the Yun. (You may notice it has no crystal or backup battery.) The way it sets the time is -- it looks for a file with what it thinks is the correct time - sets the time, then does a network time look up, then resets the time*. This is important because sometimes an upgrade will fail because the system time is off. There are more details, but I don't want to get off subject.
On #2, the boot sequence is not what you are thinking, they never have run that way on OpenWRT (the basis for Yun OS). While it is a Linux-based OS, there are differences.
If you would like to know more about how the system runs you can read my notes:
Documenting the Yún
http://codesnippets.altervista.org/documentation/yun/index.html
I have more notes off-line that I need to post, so don't be afraid to ask any questions.
Jesse
NOTE: Added (*) note in italics for for clarity.
My issue was never about the system time, apologies if I didn't make that clear enough. I was only using the timestamp as proof of whether my startup script had been executed. My real script does something else (it runs a Python script) - I was just using the "touch" command as an example.
The issue I was having (and am still having) is that the init.d script never seems to get started after a full power off/on.
If I manually start the script (i.e. /etc/init.d/test start), I can see that it does something. In this example, I see that the timestamp of the "touched" file is updated; in my real script, I can see that the python script is executing.
If I then reboot via the "reboot" command, then I notice that the init.d script is still executed. If, however, I power down then restart, the init.d script does not get executed.
Any ideas why?
Hi sonnyyu,
Thanks for your reply. Here's my real script:
#!/bin/sh /etc/rc.common
START=99
start() {
echo "Starting..."
python /usr/local/sbin/durrylights/durrylights.py &
echo "Started"
}
stop() {
pid=$(ps | grep '[p]ython /usr/local/sbin/durrylights/durrylights.py' | awk '{ print $1 }')
echo "Stopping..."
kill $pid
echo "Stopped"
}
As you can see, I am actually using 99, yet this does not appear to ever get started.
Testing with touch, see if it works?
photomoose:
::::SNIP::::
If I then reboot via the "reboot" command, then I notice that the init.d script is still executed. If, however, I power down then restart, the init.d script does not get executed.
Any ideas why?
@photomoose,
I was very clear in my last statement. YunOS and OpenWRT do NOT work like a typical Linux system. If you want to continue to make shots in the dark - go ahead. If you want to accomplish your task, then state what you want to do.
NOTE: this system is more embedded than like PC. So, following the standard methods will be furstrating.
Jesse