OpenWrt Forum Archive

Topic: Need to run application at boot time,, Script Not working properly

The content of this topic has been archived on 25 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello All,

I want to run my application at boot time. So for this purpose i have wriiten a script file which is located at location /etc/init.d/.
I am using command "/etc/inint.d/test start" for running this application.

But some times this application runs at boot time and some time it doesn't!!

#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
START=50

boot() {
        start
}

start() {
        /bin/test &
}

stop() {
killall test
}



PLease suggest!!

Thanks in Advance.

Regards,
WirelessUser

Need some help Openwrt pplz..

Regards,
WirelessUser

Try with:

/etc/init.d/test enable
reboot

so it gets enabled at boot time.

(Last edited by Dogge on 17 Jun 2010, 17:46)

Thnx for your reply. I tried:-

" /etc/init.d/test enable"
reboot
I am able to see test file in "/etc/rc.d" location. This makes my application run at boot time but after 4-5 reboot it fails to start at boot time.

Please suggest. Do i need to do any other settings?????

Thnx in Advance!!

Regards,
WirelessUser

I am having what appears to be the same problem, a python script won't start on boot.

ASUS WL-520GU - Kamikaze 8.09 (openwrt-brcm-2.4-squashfs.trx from MightyOhm, http://mightyohm.com/blog/2008/11/build … -openwrt/)

After much research, it seems this is the way to set up a script to run at bootup.  The rcS runs through all the scripts in rc.d.  I created a file in init.d to start the python script named launchmyscript.  When I ran the enable command, it created the equivalent file in rc.d.

???

- /etc/init.d/rcS
-----------------------------------
#!/bin/sh
# Copyright (C) 2006 OpenWrt.org
{
    for i in /etc/rc.d/$1*; do
        [ -x $i ] && $i $2 2>&1
    done
} | logger -s -p 6 -t '' &


-/etc/init.d/launchmyscripts
-----------------------------------
#!/bin/sh /etc/rc.common
# Chris' application startup script
# start it after everything else is loaded

START=98

start() {
    echo Starting TweetAWatt Wattcher.py
    python /opt/tweetawatt/wattcher.py &
}

I run these commands and it works fine:
# /etc/init.d/launchmyscripts enable  (creates the S98launchmyscripts file in /etc/rc.d/)
# /etc/init.d/launchmyscripts start

But it does not start up when I unplug and restart the router.  I test to see if it's running with:
# ps -ef | grep wattcher.py
652 root      1920 S    grep wattcher.py


After bootup I can manually start and then I see this in the ps command:
  655 root     13600 S    python /opt/tweetawatt/wattcher.py
  660 root      1920 S    grep wattcher.py

What other info might help with this diagnosis.

Thanks in advance,
Chris.

Try to log the python errors. Does your script need the wan to be up? Any entry in logread??

Aha! You may be on to something, Ripat.  I see this on the last lines of the list from logread:

Jan  1 00:00:32 OpenWrt user.info : Starting TweetAWatt Wattcher.py
Jan  1 00:00:32 OpenWrt user.info : /etc/rc.common: eval: line 13: python: not found


I see the echo (Starting TweetAWatt Wattcher.py) from /etc/rc.d/S98launchmyscripts and then what appears to be an error about not found.  Sadly, I'm not sure what was not found: 

Is it something in rc.common (line 13 is between stop and reload)? 
Is is it python that can't be found?
Is it something in my script (no references to lan/wan connections by or near line 13)?

Here's the full logread below, if that's helpful.

Thanks for any tips,
Chris.


root@OpenWrt:~# logread
Jan  1 00:00:08 OpenWrt syslog.info syslogd started: BusyBox v1.11.2
Jan  1 00:00:08 OpenWrt user.notice kernel: klogd started: BusyBox v1.11.2 (2008-12-01 16:57:55 PST)
Jan  1 00:00:08 OpenWrt user.warn kernel: CPU revision is: 00029029
Jan  1 00:00:08 OpenWrt user.warn kernel: Primary instruction cache 16kB, physically tagged, 4-way, linesize 16 bytes.
Jan  1 00:00:08 OpenWrt user.warn kernel: Primary data cache 16kB, 2-way, linesize 16 bytes.
Jan  1 00:00:08 OpenWrt user.warn kernel: Linux version 2.4.35.4 (jkeyzer@wavelen) (gcc version 3.4.6 (OpenWrt-2.0)) #3 Mon Dec 1 17:35:57 PST 2008
Jan  1 00:00:08 OpenWrt user.warn kernel: Setting the PFC to its default value
Jan  1 00:00:08 OpenWrt user.warn kernel: Determined physical RAM map:
Jan  1 00:00:08 OpenWrt user.warn kernel:  memory: 01000000 @ 00000000 (usable)
Jan  1 00:00:08 OpenWrt user.warn kernel: On node 0 totalpages: 4096
Jan  1 00:00:08 OpenWrt user.warn kernel: zone(0): 4096 pages.
Jan  1 00:00:08 OpenWrt user.warn kernel: zone(1): 0 pages.
Jan  1 00:00:08 OpenWrt user.warn kernel: zone(2): 0 pages.
Jan  1 00:00:08 OpenWrt user.warn kernel: Kernel command line: root=/dev/mtdblock2 rootfstype=squashfs,jffs2 init=/etc/preinit noinitrd console=ttyS0,115200
Jan  1 00:00:08 OpenWrt user.warn kernel: CPU: BCM5354 rev 3 at 240 MHz
Jan  1 00:00:08 OpenWrt user.warn kernel: Using 120.000 MHz high precision timer.
Jan  1 00:00:08 OpenWrt user.warn kernel: Calibrating delay loop... 237.56 BogoMIPS
Jan  1 00:00:08 OpenWrt user.info kernel: Memory: 14272k/16384k available (1419k kernel code, 2112k reserved, 96k data, 84k init, 0k highmem)
Jan  1 00:00:08 OpenWrt user.info kernel: Dentry cache hash table entries: 2048 (order: 2, 16384 bytes)
Jan  1 00:00:08 OpenWrt user.info kernel: Inode cache hash table entries: 1024 (order: 1, 8192 bytes)
Jan  1 00:00:08 OpenWrt user.info kernel: Mount cache hash table entries: 512 (order: 0, 4096 bytes)
Jan  1 00:00:08 OpenWrt user.info kernel: Buffer cache hash table entries: 1024 (order: 0, 4096 bytes)
Jan  1 00:00:08 OpenWrt user.warn kernel: Page-cache hash table entries: 4096 (order: 2, 16384 bytes)
Jan  1 00:00:08 OpenWrt user.warn kernel: Checking for 'wait' instruction...  unavailable.
Jan  1 00:00:08 OpenWrt user.warn kernel: POSIX conformance testing by UNIFIX
Jan  1 00:00:08 OpenWrt user.warn kernel: PCI: no core
Jan  1 00:00:08 OpenWrt user.warn kernel: PCI: Fixing up bus 0
Jan  1 00:00:08 OpenWrt user.info kernel: Linux NET4.0 for Linux 2.4
Jan  1 00:00:08 OpenWrt user.info kernel: Based upon Swansea University Computer Society NET3.039
Jan  1 00:00:08 OpenWrt user.warn kernel: Initializing RT netlink socket
Jan  1 00:00:08 OpenWrt user.warn kernel: Starting kswapd
Jan  1 00:00:08 OpenWrt user.warn kernel: Registering mini_fo version $Id$
Jan  1 00:00:08 OpenWrt user.info kernel: devfs: v1.12c (20020818) Richard Gooch (rgooch@atnf.csiro.au)
Jan  1 00:00:08 OpenWrt user.info kernel: devfs: boot_options: 0x1
Jan  1 00:00:08 OpenWrt user.notice kernel: JFFS2 version 2.1. (C) 2001 Red Hat, Inc., designed by Axis Communications AB.
Jan  1 00:00:08 OpenWrt user.info kernel: squashfs: version 3.0 (2006/03/15) Phillip Lougher
Jan  1 00:00:08 OpenWrt user.warn kernel: pty: 256 Unix98 ptys configured
Jan  1 00:00:08 OpenWrt user.info kernel: Serial driver version 5.05c (2001-07-08) with MANY_PORTS SHARE_IRQ SERIAL_PCI enabled
Jan  1 00:00:08 OpenWrt user.info kernel: ttyS00 at 0xb8000300 (irq = 3) is a 16550A
Jan  1 00:00:08 OpenWrt user.info kernel: ttyS01 at 0xb8000400 (irq = 3) is a 16550A
Jan  1 00:00:08 OpenWrt user.info kernel: b44.c:v0.93 (Mar, 2004)
Jan  1 00:00:08 OpenWrt user.debug kernel: PCI: Setting latency timer of device 00:01.0 to 64
Jan  1 00:00:08 OpenWrt user.info kernel: eth0: Broadcom 47xx 10/100BaseT Ethernet e0:cb:4e:44:26:1c
Jan  1 00:00:08 OpenWrt user.debug kernel: Physically mapped flash: Found an alias at 0x400000 for the chip at 0x0
Jan  1 00:00:08 OpenWrt user.debug kernel: Physically mapped flash: Found an alias at 0x800000 for the chip at 0x0
Jan  1 00:00:08 OpenWrt user.debug kernel: Physically mapped flash: Found an alias at 0xc00000 for the chip at 0x0
Jan  1 00:00:08 OpenWrt user.debug kernel: Physically mapped flash: Found an alias at 0x1000000 for the chip at 0x0
Jan  1 00:00:08 OpenWrt user.debug kernel: Physically mapped flash: Found an alias at 0x1400000 for the chip at 0x0
Jan  1 00:00:08 OpenWrt user.debug kernel: Physically mapped flash: Found an alias at 0x1800000 for the chip at 0x0
Jan  1 00:00:08 OpenWrt user.debug kernel: Physically mapped flash: Found an alias at 0x1c00000 for the chip at 0x0
Jan  1 00:00:08 OpenWrt user.notice kernel:  Amd/Fujitsu Extended Query Table v1.1 at 0x0040
Jan  1 00:00:08 OpenWrt user.notice kernel: number of CFI chips: 1
Jan  1 00:00:08 OpenWrt user.notice kernel: cfi_cmdset_0002: Disabling fast programming due to code brokenness.
Jan  1 00:00:08 OpenWrt user.notice kernel: Flash device: 0x400000 at 0x1c000000
Jan  1 00:00:08 OpenWrt user.notice kernel: bootloader size: 131072
Jan  1 00:00:08 OpenWrt user.info kernel: Physically mapped flash: Filesystem type: squashfs, size=0x13e028
Jan  1 00:00:08 OpenWrt user.notice kernel: Creating 5 MTD partitions on "Physically mapped flash":
Jan  1 00:00:08 OpenWrt user.notice kernel: 0x00000000-0x00020000 : "cfe"
Jan  1 00:00:08 OpenWrt user.notice kernel: 0x00020000-0x003f0000 : "linux"
Jan  1 00:00:08 OpenWrt user.notice kernel: 0x0009a800-0x001e0000 : "rootfs"
Jan  1 00:00:08 OpenWrt user.warn kernel: mtd: partition "rootfs" doesn't start on an erase block boundary -- force read-only
Jan  1 00:00:08 OpenWrt user.notice kernel: 0x003f0000-0x00400000 : "nvram"
Jan  1 00:00:08 OpenWrt user.notice kernel: 0x001e0000-0x003f0000 : "rootfs_data"
Jan  1 00:00:08 OpenWrt user.info kernel: Initializing Cryptographic API
Jan  1 00:00:08 OpenWrt user.info kernel: NET4: Linux TCP/IP 1.0 for NET4.0
Jan  1 00:00:08 OpenWrt user.info kernel: IP Protocols: ICMP, UDP, TCP, IGMP
Jan  1 00:00:08 OpenWrt user.info kernel: IP: routing cache hash table of 512 buckets, 4Kbytes
Jan  1 00:00:08 OpenWrt user.info kernel: TCP: Hash tables configured (established 1024 bind 2048)
Jan  1 00:00:08 OpenWrt user.info kernel: NET4: Unix domain sockets 1.0/SMP for Linux NET4.0.
Jan  1 00:00:08 OpenWrt user.info kernel: NET4: Ethernet Bridge 008 for NET4.0
Jan  1 00:00:08 OpenWrt user.info kernel: 802.1Q VLAN Support v1.8 Ben Greear <greearb@candelatech.com>
Jan  1 00:00:08 OpenWrt user.info kernel: All bugs added by David S. Miller <davem@redhat.com>
Jan  1 00:00:08 OpenWrt user.warn kernel: VFS: Mounted root (squashfs filesystem) readonly.
Jan  1 00:00:08 OpenWrt user.info kernel: Mounted devfs on /dev
Jan  1 00:00:08 OpenWrt user.info kernel: Freeing unused kernel memory: 84k freed
Jan  1 00:00:08 OpenWrt user.warn kernel: Algorithmics/MIPS FPU Emulator v1.5
Jan  1 00:00:08 OpenWrt user.warn kernel: diag: Detected 'ASUS WL-520gU'
Jan  1 00:00:08 OpenWrt user.info kernel: b44: eth0: Link is up at 100 Mbps, full duplex.
Jan  1 00:00:08 OpenWrt user.info kernel: b44: eth0: Flow control is off for TX and off for RX.
Jan  1 00:00:08 OpenWrt user.info kernel: roboswitch: Probing device eth0: found!
Jan  1 00:00:08 OpenWrt user.info kernel: mini_fo: using base directory: /
Jan  1 00:00:08 OpenWrt user.info kernel: mini_fo: using storage directory: /jffs
Jan  1 00:00:08 OpenWrt user.warn kernel: jffs2.bbc: SIZE compression mode activated.
Jan  1 00:00:10 OpenWrt user.info kernel: b44: eth0: Link is up at 100 Mbps, full duplex.
Jan  1 00:00:10 OpenWrt user.info kernel: b44: eth0: Flow control is off for TX and off for RX.
Jan  1 00:00:11 OpenWrt user.info kernel: SCSI subsystem driver Revision: 1.00
Jan  1 00:00:12 OpenWrt user.warn kernel: BFL_ENETADM not set in boardflags. Use force=1 to ignore.
Jan  1 00:00:12 OpenWrt user.info kernel: device eth0.0 entered promiscuous mode
Jan  1 00:00:12 OpenWrt user.info kernel: eth0.0: dev_set_promiscuity(master, 1)
Jan  1 00:00:12 OpenWrt user.info kernel: device eth0 entered promiscuous mode
Jan  1 00:00:12 OpenWrt user.info kernel: br-lan: port 1(eth0.0) entering learning state
Jan  1 00:00:12 OpenWrt user.info kernel: br-lan: port 1(eth0.0) entering forwarding state
Jan  1 00:00:12 OpenWrt user.info kernel: br-lan: topology change detected, propagating
Jan  1 00:00:13 OpenWrt user.info kernel: usb.c: registered new driver usbdevfs
Jan  1 00:00:13 OpenWrt user.info kernel: usb.c: registered new driver hub
Jan  1 00:00:14 OpenWrt user.debug kernel: eth0.1: add 01:00:5e:00:00:01 mcast address to master interface
Jan  1 00:00:16 OpenWrt user.debug kernel: PCI: Setting latency timer of device 00:05.0 to 64
Jan  1 00:00:16 OpenWrt user.emerg kernel: PCI/DMA
Jan  1 00:00:16 OpenWrt user.emerg kernel: wl0: wlc_attach: chiprev 3 coreunit 0 corerev 13 cccap 0x104007ea maccap 0x30482205 band 2.4G, phy_type 5 phy_rev 0 ana_rev 6
Jan  1 00:00:16 OpenWrt user.warn kernel: wl0: Broadcom BCM4318 802.11 Wireless Controller 4.150.10.5
Jan  1 00:00:16 OpenWrt user.info : Warning: loading wl will taint the kernel: non-GPL license - Proprietary
Jan  1 00:00:16 OpenWrt user.info :   See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Jan  1 00:00:17 OpenWrt user.info kernel: Journalled Block Device driver loaded
Jan  1 00:00:18 OpenWrt user.info kernel: CSLIP: code copyright 1989 Regents of the University of California
Jan  1 00:00:18 OpenWrt user.info kernel: PPP generic driver version 2.4.2
Jan  1 00:00:18 OpenWrt user.warn kernel: ip_tables: (C) 2000-2002 Netfilter core team
Jan  1 00:00:19 OpenWrt user.warn kernel: ip_conntrack version 2.1 (5953 buckets, 5953 max) - 344 bytes per conntrack
Jan  1 00:00:19 OpenWrt user.info kernel: SB USB20H init
Jan  1 00:00:19 OpenWrt user.info kernel: SB COREREV: 2
Jan  1 00:00:19 OpenWrt user.info kernel: SB USB20H resetting
Jan  1 00:00:19 OpenWrt user.info kernel: USB20H fcr: 0x64
Jan  1 00:00:19 OpenWrt user.info kernel: USB20H shim cr: 0x8f7
Jan  1 00:00:19 OpenWrt user.debug kernel: PCI: Setting latency timer of device 00:03.0 to 64
Jan  1 00:00:19 OpenWrt user.info kernel: usb-ohci.c: USB OHCI at membase 0xb8003000, IRQ 6
Jan  1 00:00:19 OpenWrt user.info kernel: usb-ohci.c: usb-00:03.0, PCI device 14e4:471a
Jan  1 00:00:19 OpenWrt user.info kernel: usb.c: new USB bus registered, assigned bus number 1
Jan  1 00:00:19 OpenWrt user.info kernel: hub.c: USB hub found
Jan  1 00:00:19 OpenWrt user.info kernel: hub.c: 2 ports detected
Jan  1 00:00:20 OpenWrt user.info kernel: Initializing USB Mass Storage driver...
Jan  1 00:00:20 OpenWrt user.info kernel: usb.c: registered new driver usb-storage
Jan  1 00:00:20 OpenWrt user.info kernel: USB Mass Storage support registered.
Jan  1 00:00:20 OpenWrt user.info kernel: hub.c: new USB device 00:03.0-1, assigned address 2
Jan  1 00:00:20 OpenWrt user.info kernel: scsi0 : SCSI emulation for USB Mass Storage devices
Jan  1 00:00:20 OpenWrt user.warn kernel:   Vendor: USB 2.0   Model: photobuket        Rev: 1.00
Jan  1 00:00:20 OpenWrt user.warn kernel:   Type:   Direct-Access                      ANSI SCSI revision: 02
Jan  1 00:00:20 OpenWrt user.warn kernel: Attached scsi removable disk sda at scsi0, channel 0, id 0, lun 0
Jan  1 00:00:20 OpenWrt user.warn kernel: SCSI device sda: 254208 512-byte hdwr sectors (130 MB)
Jan  1 00:00:20 OpenWrt user.warn kernel: sda: Write Protect is off
Jan  1 00:00:20 OpenWrt user.info kernel: Partition check:
Jan  1 00:00:20 OpenWrt user.info kernel:  /dev/scsi/host0/bus0/target0/lun0:
Jan  1 00:00:20 OpenWrt user.info kernel:  p1
Jan  1 00:00:20 OpenWrt user.debug kernel: WARNING: USB Mass Storage data integrity not assured
Jan  1 00:00:20 OpenWrt user.debug kernel: USB Mass Storage device found at 2
Jan  1 00:00:20 OpenWrt user.notice root: usb device is mass storage
Jan  1 00:00:20 OpenWrt user.notice root: waiting on usb drive 0 ...
Jan  1 00:00:21 OpenWrt user.notice root: waiting on usb drive 1 ...
Jan  1 00:00:21 OpenWrt user.info kernel: kjournald starting.  Commit interval 5 seconds
Jan  1 00:00:21 OpenWrt user.info kernel: EXT3 FS 2.4-0.9.19, 19 August 2002 on sd(8,1), internal journal
Jan  1 00:00:21 OpenWrt user.info kernel: EXT3-fs: recovery complete.
Jan  1 00:00:21 OpenWrt user.info kernel: EXT3-fs: mounted filesystem with ordered data mode.
Jan  1 00:00:21 OpenWrt user.info : Success: /dev/scsi/host0/bus0/target0/lun0/part1
Jan  1 00:00:22 OpenWrt user.notice root: waiting on usb drive 2 ...
Jan  1 00:00:23 OpenWrt user.info kernel: device wl0 entered promiscuous mode
Jan  1 00:00:23 OpenWrt user.info kernel: wl0: attempt to add interface with same source address.
Jan  1 00:00:23 OpenWrt user.info kernel: br-lan: port 2(wl0) entering learning state
Jan  1 00:00:23 OpenWrt user.info kernel: br-lan: port 2(wl0) entering forwarding state
Jan  1 00:00:23 OpenWrt user.info kernel: br-lan: topology change detected, propagating
Jan  1 00:00:23 OpenWrt user.notice root: waiting on usb drive 3 ...
Jan  1 00:00:24 OpenWrt user.info : Loading defaults
Jan  1 00:00:25 OpenWrt user.notice root: waiting on usb drive 4 ...
Jan  1 00:00:26 OpenWrt user.notice root: waiting on usb drive 5 ...
Jan  1 00:00:26 OpenWrt user.info : Loading synflood protection
Jan  1 00:00:26 OpenWrt user.info : Adding custom chains
Jan  1 00:00:27 OpenWrt user.info : Loading zones
Jan  1 00:00:27 OpenWrt user.notice root: waiting on usb drive 6 ...
Jan  1 00:00:28 OpenWrt user.info : Loading rules
Jan  1 00:00:28 OpenWrt user.info : Loading forwarding
Jan  1 00:00:28 OpenWrt user.info : Loading redirects
Jan  1 00:00:28 OpenWrt user.info : Loading includes
Jan  1 00:00:28 OpenWrt user.notice root: waiting on usb drive 7 ...
Jan  1 00:00:29 OpenWrt user.notice root: waiting on usb drive 8 ...
Jan  1 00:00:29 OpenWrt user.notice root: adding br-lan to firewall zone lan
Jan  1 00:00:30 OpenWrt user.notice root: waiting on usb drive 9 ...
Jan  1 00:00:30 OpenWrt authpriv.info dropbear[585]: Running in background
Jan  1 00:00:31 OpenWrt user.notice root: waiting on usb drive 10 ...
Jan  1 00:00:32 OpenWrt user.info : udhcpc: bind(UDP): Cannot assign requested address
Jan  1 00:00:32 OpenWrt daemon.info dnsmasq[609]: started, version 2.45 cachesize 150
Jan  1 00:00:32 OpenWrt daemon.info dnsmasq[609]: compile time options: IPv6 GNU-getopt ISC-leasefile no-DBus no-I18N TFTP
Jan  1 00:00:32 OpenWrt daemon.info dnsmasq[609]: using local addresses only for domain lan
Jan  1 00:00:32 OpenWrt daemon.info dnsmasq[609]: reading /tmp/dhcp.leases
Jan  1 00:00:32 OpenWrt daemon.info dnsmasq[609]: reading /tmp/resolv.conf.auto
Jan  1 00:00:32 OpenWrt daemon.info dnsmasq[609]: using nameserver 192.168.0.1#53
Jan  1 00:00:32 OpenWrt daemon.info dnsmasq[609]: using local addresses only for domain lan
Jan  1 00:00:32 OpenWrt daemon.info dnsmasq[609]: read /etc/hosts - 1 addresses
Jan  1 00:00:32 OpenWrt user.info : Starting TweetAWatt Wattcher.py
Jan  1 00:00:32 OpenWrt user.info : /etc/rc.common: eval: line 13: python: not found

In your script, give python's full path. (/bin/python ?). To get it's full path:
$ which python

ripat,
Python was installed on the usb drive:

$ which python returned:
/opt/usr/bin/python


After making the change in /etc/init.d/launchmyscript and then running /etc/init.d/launchmyscript enable I saw the change reflected in /etc/rc.d/S98launchmyscript:
#!/bin/sh /etc/rc.common
# Chris' application startup script
# start it after everything else is loaded

START=98

start() {
    echo Starting TweetAWatt Wattcher.py
    /opt/usr/bin/python /opt/tweetawatt/wattcher.py &
}



Now logread reflects this:
Jan  1 00:00:31 OpenWrt user.info : Starting TweetAWatt Wattcher.py
Jan  1 00:00:32 OpenWrt user.info : /opt/usr/bin/python: can't load library 'libpthread.so.0'


When I was installing python on the usb it kept reflecting an error about failure to create a symlink to python.  I had the original usb format as FAT, so I changed the formatting to ext3 and it installed without error.

Also, without the full path to python, I can manually run:
/etc/init.d/launchmyscripts start

And the script runs fine.  BTW, it runs fine *with* and *without* the path to python.  So it works either way when I am logged in as root.  Perhaps this is an issue of not being logged in as root during the boot process?

Thanks,
Chris.

I assume there is LD_LIBRARY_PATH and other env stuff involved which gets set in /etc/profile. This file is not included at boot time so the env vars have to be redone in the initscript.

jow,

Here is my /etc/profile file, below.  So are you saying that I this file does not get read until I log in as root?  Perhaps I need to set the path commands in the file: /etc/init.d/launchmyscripts

or is there a specific syntax added to a file called initscript?

Thanks for your help,
Chris.


#!/bin/sh
[ -f /etc/banner ] && cat /etc/banner


export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:/opt/usr/bin:/opt/usr/sbin
export LD_LIBRARY_PATH=/lib:/usr/lib:/opt/usr/lib:/opt/lib

export HOME=/root
export PS1='\u@\h:\w\$ '

[ -x /bin/more ] || alias more=less
[ -x /usr/bin/vim ] && alias vi=vim || alias vim=vi

[ -z "$KSH_VERSION" -o \! -s /etc/mkshrc ] || . /etc/mkshrc

[ -x /sbin/arp ] || arp() { cat /proc/net/arp; }
[ -z /bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }

Try adding

. /etc/profile

as very first statement to the start() procedure in your init script.

jow,

Tried to run the /etc/profile did not work so I took the path commands and added them into the launchmyscripts and it seems to work:

The question now...  Is there any downside to this approach.

Thanks folks, for all your help.


/etc/init.d/launchmyscripts

#!/bin/sh /etc/rc.common
# Chris' application startup script
# start it after everything else is loaded

START=98

start() {
    echo Starting TweetAWatt Wattcher.py with export PATH, LD_LIBRARY_PATH
    export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:/opt/usr/bin:/opt/usr/sbin
    export LD_LIBRARY_PATH=/lib:/usr/lib:/opt/usr/lib:/opt/lib
    echo $PATH
    python /opt/tweetawatt/wattcher.py &
}

the only downside is that you have the vars defined in two places now

You shouldn't try to "start" /etc/profile but include it by adding

. /etc/profile

to your script.

I bet you missed the dot.

ciao

Memphis

PS: dont miss the "space" after the dot big_smile

(Last edited by Memphis on 20 Jul 2010, 07:57)

You're right, Memphis.  I missed the period when I tried it before.  Good catch.

It works.  Thanks.


#!/bin/sh /etc/rc.common
# Chris' application startup script
# start it after everything else is loaded

START=98

start() {
    echo Starting TweetAWatt Wattcher.py with include profile
    . /etc/profile
    echo $PATH
    python /opt/tweetawatt/wattcher.py &
}

stop() {
    killall wattcher.py
}

Sadly, I'm baaaack....  All seemed to be working well, and I bricked my Asus WL520GU while trying to add lighttpd and php.  Started over and because I had most of my configs and reasonably good notes, it was not too bad to put back together.


Anyway,  the problem is again with the init script to launch a python script.  If I run python /opt/tinaja/allsensors.py at the command prompt, logged in as root, the program executes just fine but when it is launched in the init script at boot-up it starts OK, but then when the script accesses the serial port - choke!  It happens that the choke is in the std serial.py libs but I think the problem is with serial device config, root user, etc.  I don't know...

I can see the script running by issuing the PS command.  The clue is in the syslog when I run logread. I get lots of lines that look like this:

Sep  7 09:36:18 OpenWrt daemon.info init: init: process '/bin/ash --login' (pid 2172) exited. Scheduling for restart.
Sep  7 09:36:18 OpenWrt daemon.info init: init: starting pid 2173, tty '/dev/tts/0': '/bin/ash --login'

These messages seem to coincide with my script's access to the serial port.

BTW, the serial port is receiving data from an xBee serial device - working fine when logged in and launched manually.


Code examples

The init script:

#!/bin/sh /etc/rc.common
# start it after everything else is loaded
START=98
start() {
        echo +++++++++++++++++++++++++++++++++++++++++++++++++++
    echo Starting sensor manager - /opt/tinaja/allsensors.py
    # PATH, LD_LIBRARY_PATH are configured in /etc/profile
    . /etc/profile
        # python /opt/tinaja/testReader.py 
    python /opt/tinaja/allsensors.py &
    echo +++++++++++++++++++++++++++++++++++++++++++++++++++
}
stop() {
    killall allsensors.py
}

line of code that leads to the hang-up:

    packet = xbee.find_packet(ser)

This is the actual section of code that hangs:

    try:
        packet = xbee.find_packet(ser)
        if not packet:
            print "    no serial packet found... "+ time.strftime("%Y %m %d, %H:%M")
            syslog.syslog("mainloop exception: no serial packet found..." )
            return
    except Exception, e:
        print "mainloop exception: Serial packet: "+str(e)
        syslog.syslog("mainloop exception: Serial packet: "+str(e))
        return

    syslog.syslog("2 ... stuck inside of mobile with the memphis blues again... " + time.strftime("%Y %m %d, %H:%M"))

It never gets to the syslog 2 ... command.


setup in allsensors.py (main script, my version of wattcher.py)

SERIALPORT = "/dev/tts/0"    # the com/serial port the XBee is connected to
BAUDRATE = 9600      # the baud rate we talk to the xbee

This initialization seems to run without throwing an error:

    ser = serial.Serial(SERIALPORT, BAUDRATE)
    ser.open()

in inittab:

::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K stop
tts/0::askfirst:/bin/ash --login
ttyS0::askfirst:/bin/ash --login
tty1::askfirst:/bin/ash --login

from dmesg:

Serial driver version 5.05c (2001-07-08) with MANY_PORTS SHARE_IRQ SERIAL_PCI enabled
ttyS00 at 0xb8000300 (irq = 3) is a 16550A
ttyS01 at 0xb8000400 (irq = 3) is a 16550A

Any tips greatly appreciated,
Chris.

Fixed!  I hope...

The problem seemed to be due to a command in /etc/inittab

Found a reference in this post:
https://forum.openwrt.org/viewtopic.php … 280#p96280

Need to comment out the line refering to tts/0 so the file looks like this:

::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K stop
# tts/0::askfirst:/bin/ash --login
ttyS0::askfirst:/bin/ash --login
tty1::askfirst:/bin/ash --login

Still don't know why.  If anyone has an explanation, I'd love to know.  AND, might this break something else?

Thanks,
Chris.

The discussion might have continued from here.