Thanks.
echoing to a file when invoked from the script works. I posted that
in Jan 13, 7:43am message. And for the beagleboard Ubuntu Maverick
image, runlevels 2 and 3 have exactly the same scripts. So changing
from 2 to 3 does not promise doing any good. But I tried it anyway.
And it did not improve the situation with respect to the function of
my daemon.
So I went off and read the man page for the Ubuntu /sbin/init daemon,
which was quite a revelation for someone expecting the last word to be
the scripts in /etc/rcX.d/. For now, I'm backing off the use of
scripts in /etc/rX.d, in favor of using Ubuntu start daemon .conf
files in /etc/init. I know the rc script method should work, but I'm
so deep into looking without seeing that I'm taking as few chances as
possible with with simulated runlevels. And runlevels are simulated
in Ubuntu Maverick. See this nice write up: http://www.linux.com/archive/feature/125977
So here is the .conf file I constructed, which is a clone of the .conf
file sshd uses (and sshd works). I also note that my mcagent daemon
does in fact fork, so "expect fork" is valid in the config.
start on filesystem
stop on runlevel [!2345]
expect fork
respawn
respawn limit 10 5
umask 022
pre-start script
test -x /opt/local/bin/mcagent || { stop; exit 0; }
ifconfig -a > /opt/if.log
end script
exec /opt/local/bin/mcagent 225.0.0.37 12345 1>/var/log/mcagent.log
2>&1
# --- cut here
The daemon fails to start successfully, and logs this to stderr, which
I capture in the mcagent.log:
setsockopt() failed: No such device
The code that generated this error looks like
/* construct an IGMP join request structure */
mc_req.imr_multiaddr.s_addr = inet_addr(mc_addr_str);
mc_req.imr_interface.s_addr = htonl(INADDR_ANY);
/* send an ADD MEMBERSHIP message via setsockopt */
if ((setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void*)
&mc_req, sizeof(mc_req))) < 0) {
perror("setsockopt() failed");
exit(1);
}
I capture the output of ifconfig -a as a pre-start action. That
output looks like
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
usb0 Link encap:Ethernet HWaddr f2:a2:36:7c:49:6a
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
usb1 Link encap:Ethernet HWaddr 12:82:26:5e:aa:ae
inet6 addr: fe80::1082:26ff:fe5e:aaae/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1492 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:534 (534.0 B)
However, when I login to the board, and type ifconfig -a I get this,
noting that usb1 (the interface that ultimately gets an address from
the dhcp server) has no IPv4 address when the .conf script runs, but
has one by the time I login.
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
usb0 Link encap:Ethernet HWaddr f2:a2:36:7c:49:6a
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
usb1 Link encap:Ethernet HWaddr 12:82:26:5e:aa:ae
inet addr:192.168.0.139 Bcast:192.168.0.255 Mask:
255.255.255.0
inet6 addr: fe80::1082:26ff:fe5e:aaae/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1492 Metric:1
RX packets:96 errors:0 dropped:0 overruns:0 frame:0
TX packets:20 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:12518 (12.5 KB) TX bytes:3032 (3.0 KB)
So it sounds like I need to use in the .conf file a different start-
event than "filesystem" (a weird choice for openssh-server to have
used, which I inherited in the .conf file clone. But sshd works, so
who am I to question). I searched for standard event-names associated
with the new Ubuntu init daemon, but found none. Logically, I want
some event named "network-is-all-the-way-up".
BTW, usb0 does not seem to be a usable physical interface. What is it
actually doing there??