Init script fails to start

I am trying to run a script on start up. The aim is to run an rtl_433 compatible SDR Stick, read data into MQTT and then send it to Home Assistant
If i open the terminal and execute the script everything is fine.
/etc/init.d/mqtt start

#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007 OpenWrt.org
 
START=98
STOP=99
 
start() {        
        echo start
        rtl_433 -F json -M utc -F mqtt://XXX.XXX.XXX.XXX,retain=0,user=XXX,pass=XXXX,events=rtl_433[/model][/id]
}                 
 
stop() {          
        echo stop
        # commands to kill application 
}

However closing the terminal kills the process...
Starting the script manually through LuCI web interface /luci/admin/system/startup - results in failure : XHR request timed out
and enabling script at startup results in boot failure unless i unplug the usb stick.
I did run chmod +x /etc/init.d/mqtt. Could some one help me to find the problem?

Best
Stephan

Add an & at the end of the command line (is it correct in the 1st place?) ?

Or screen (install the package 1st) in front of "rtl_433".

Might try using killall rtl_433 for stopping, if available, haven't checked.

1 Like

This might help you...

Put the relevant command into a detached shell, so that it stays alive.

( rtl_433 ... )&

This worked, process stays after closing the terminal
-Thanks!

However, best thing would be, if i could run the command using the init script.

What is the difference in

  1. calling the service in the terminal:
root@OpenWrt_XXX:~# /etc/init.d/mqtt start

no error - everything works fine

  1. call the service via LuCI web interface and start the process by pressing the start button on the page /luci/admin/system/startup? Which results in: XHR request timed out
  2. Start up (when script is enabled): which results in a boot failure

This is the script that I use:

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

START=90
USE_PROCD=1

start_service() {
	procd_open_instance
	procd_set_param respawn ${respawn_threshold:-5} ${respawn_timeout:-0} ${respawn_retry:-0}
	procd_set_param command /usr/bin/rtl_433 -T 10000 -R03 -R24 -R30 -R96 -M protocol -F "mqtt://192.168.4.1,user=router,pass=[REDACTED],retain=1,events=[hostname][/protocol][/id]"
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_close_instance
}

2 Likes

This worked!
Thanks

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.