rc.d script not working as expected

Started by bobbis, October 12, 2017, 12:36:37 AM

Previous topic - Next topic
I have this https://forum.opnsense.org/index.php?topic=6073.msg25590#msg25590rc.d script, it starts while opnsense is booting and runs in the background after boot is complete, but it does nothing except beep, whats the last command in the command sequence.

If i start this script by hand like : "service mywlanpnp start", the script works as expected. Whats the problem that the script doesnt do anything except beep while it starts at boot?

Thanks

Well, it would have to be debugged, preferably with echo and sleep, assuming that this script is properly enabled in /etc/rc.conf ... but I can tell you that using "clog -f" in a non-interactive loop does not look correct. ;)


Cheers,
Franco

PS: Please paste the script in the thread, it's hard to help while switching browsers and scrolling in the "code" block.

October 13, 2017, 03:28:06 AM #2 Last Edit: October 13, 2017, 03:32:19 AM by bobbis
Hi Franco,

i dont know if you understand me correctly, the script works fine if i start, from terminal, it with "service ServiceName start", the rc.d script also starts correctly while opnsense is booting, "ServiceName_enable=YES" in /etc/rc.conf.d/ServiceName.
the command sequence is for starting the device and set config settings for it are:
sleep 1
/sbin/sysctl net.wlan.devices | /usr/bin/cut -d ' ' -f2 | /usr/bin/grep -o run[0-9] > /dev/null && /usr/local/etc/rc.reload_interface
/usr/local/bin/beep

i tested the script by starting and stopping it by hand from terminal, everything works well doing so BUT if opnsense starts the script "ServiceName_enable=YES" then only an beep appears ... so i dont know where the error is located and i dont want to waste another days to get this running cause every reboot of my system takes around 5 minutes. so i found an another solution which works flawless.
thanks anyway

and here is the complete script again:
#!/bin/sh
#
# PROVIDE: mywlanpnp
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Bobbis@forum.opnsense.org 07.10.2017 Version 0.001
#
# mywlanpnp enables you to use an USB-Wireless Device as pnp like.
# Make sure that you have allready the USB-Wireless Device configured before using this script.
# This script is just tested with only one USB-Wireless Device, in my case an "run0" Device.
# Modify the code to your own suit.
#
# HINT: Wait 10Seconds before disconnect or reconnect the USB-Wireless Device for better compatibility.
#
# Place this Script under /usr/local/etc/rc.d/mywlanpnp and set chmod execute flags.
# Note:
# Set "mywlanpnp_enable=YES" in /etc/rc.conf.d/mywlanpnp to run this script at boot.
#

. /etc/rc.subr

name="mywlanpnp"
rcvar=${name}_enable
mywlanpnp_enable=${mywlanpnp_enable-"NO"}

start_cmd="${name}_start"
stop_cmd="${name}_stop"

load_rc_config $name

file=/var/log/system.log

usb_disconnected_string="run[0-9]: at uhub[0-9], port [0-9], addr [0-9] (disconnected)" #run0: at uhub5, port 5, addr 2 (disconnected)
usb_connected_string="run[0-9]: <[0-9].[0-9]> on usbus[0-9]"                              #run0: <1.0> on usbus5


mywlanpnp_start() {
        if [ ! -f /var/run/mywlanpnp.pid ]
        then
            echo -n "Starting services: mywlanpnp"
            /usr/local/sbin/clog -f $file | while IFS='' read -r line; do
                case "$line" in
                    *${usb_connected_string}*)
                    #/usr/bin/head -1 | echo "connected"
                    sleep 1
                    #/sbin/sysctl net.wlan.devices | /usr/bin/cut -d ' ' -f2 | /usr/bin/grep -o run[0-9] > /dev/null && /usr/local/etc/rc.interfaces_wan_configure opt1
                    /sbin/sysctl net.wlan.devices | /usr/bin/cut -d ' ' -f2 | /usr/bin/grep -o run[0-9] > /dev/null && /usr/local/etc/rc.reload_interfaces
                    /usr/local/bin/beep
                    ;;
            *${usb_disconnected_string}*)
                    #/usr/bin/head -1 | echo "disconnected"
                    sleep 1
                    /bin/pgrep hostapd > /dev/null && sleep 1 && /bin/pgrep hostapd | /usr/bin/xargs kill && /usr/local/etc/rc.reload_interfaces
                    /usr/local/bin/beep
                    ;;
        esac
        done &
            echo $! > /var/run/mywlanpnp.pid
            echo "."
        else
            echo "It appears mywlanpnp is already running. NOT starting!"
        fi
}

mywlanpnp_stop() {
        if [ ! -f /var/run/mywlanpnp.pid ]
        then
            echo "It appears mywlanpnp is not running."
        else
            echo -n "Stopping services: mywlanpnp"
            kill `cat /var/run/mywlanpnp.pid`
            rm /var/run/mywlanpnp.pid
            echo "."
        fi
}

run_rc_command "$1"


appending:
/sbin/sysctl net.wlan.devices | /usr/bin/cut -d ' ' -f2 | /usr/bin/grep -o run[0-9] > /dev/null && /usr/local/etc/rc.reload_interface
or so
/sbin/sysctl net.wlan.devices | /usr/bin/cut -d ' ' -f2 | /usr/bin/grep -o run[0-9] > /dev/null && /usr/local/bin/php /usr/local/etc/rc.reload_interface
did not change anything

thanks a lot
bobbi