Hi!

I've been writing a script to monitor a process I wrote for a system running OpenWRT (an ar71xx image). It's a cus531 layout.
For some reason, when I create the package with the SDK it gets installed correctly, and works nicely (I create the necessary symlinks in /etc/rc.d/ via postinst enabling).
But when I create an image from scratch (aiming to burn it into a device) I get two problems:

  • the script is not installed in /etc/rc.d/ (I see this unsquashing the .bin file). If I remove the postinst/preinst sections in the Makefile, symlinks get created. I understand this has to do with the scan of files in /etc/init.d the image builder does, creating symlinks for any rc.d compatible script found in that directory.

  • the device gets "bricked": the SO seems to load until a moment in which my service and some other services (like wifi) don't respond, making it impossible to get into the device (there's no ethernet or serial access, unfortunately). I know the device still works because it responds to the button (which triggers some light codes prior to, for instance, resetting). I tried to associate the button with a network restart, with no success.

The script I have can be summarized like this:

#!/bin/sh /etc/rc.common

START=90
STOP=90

USE_PROCD=1

. /lib/functions.sh

io_init() {
    echo "13" > /sys/class/gpio/export
    echo "out" > /sys/class/gpio/gpio13/direction
    echo "1" > /sys/class/gpio/gpio13/value
    sleep 1s
    echo "0" > /sys/class/gpio/gpio13/value
    sleep 1s
    echo "1" > /sys/class/gpio/gpio13/value
}

ble_init() {
    /etc/init.d/bleServices stop

    if ! pidof hciattach > /dev/null; then
        bccmd -t BCSP -d /dev/ttyS0 psload -r /etc/default.psr
        hciattach /dev/ttyS0 bcsp
        hciconfig hci0 up
    fi

    /etc/init.d/bleServices start
}

network_init() {
    ifconfig wlan0 up
    # I know this could be done other way (uci)
    if ! grep -q "config interface 'wwan'" /etc/config/network; then
        echo -e "config interface 'wwan'" >> /etc/config/network
        echo -e "\toption proto 'dhcp'" >> /etc/config/network
        echo -e "\n" >> /etc/config/network
        /etc/init.d/network restart
    fi
}

init_switch() {
    io_init
    ble_init
    network_init

    # wait for services
    sleep 20s
}

default_config() {
    local config=$1
    local DEBUG_MODE
    local LOG
    config_get DEBUG_MODE $config debug true
    config_get LOG $config log true

    if [ ! "$2" = "noinit" ]; then
        init_switch
    else
        echo Avoiding initialization of already initialized services.
    fi

    # prevent more than one instance
    pidof myApp && killall myApp

    procd_open_instance
    procd_set_param command /bin/myApp
    [ $DEBUG_MODE = "true" ] && procd_append_param command -d
    [ $LOG = "true" ] && procd_append_param command -l
    procd_set_param respawn
    procd_close_instance
}

start_service() {
    config_load myconfig
    config_foreach default_config mydevice $1
}

I'd like to know if I'm missing something related to procd as to how it "does" things when an image is created from scratch. Or even if my script has an error that I'm not seeing at all.

Thanks!

(Last edited by pipetus on 21 Feb 2017, 01:52)