Room
October 17, 2021, 6:24pm
1
What is the best way to control whether a service is running or not, so that when the state changes, the script is started?
Read pgrep
every second? Or is it possible to run the script on an event?
Upd: I need a script that will run when the dropbear
or uhttpd
services start or stop, for control purposes.
daniel
October 17, 2021, 6:28pm
2
ubus subscribe service
gives you events as line / JSON objects.
2 Likes
See hotplug.d, if script brings up/down interfaces.
Follow log in bash-script:
logread -f | while read line; do
echo $line
done
1 Like
Room
October 18, 2021, 4:51am
4
daniel:
ubus subscribe service
I've tried, but so far I can't get it to react to start/stop a particular service.
Unfortunately, the start/stop is not recorded in the logs.
I need a script that will run when the dropbear
or uhttpd
services start or stop, for control purposes.
daniel
October 18, 2021, 9:36am
5
How about
ubus subscribe service | jsonfilter -e '@["instance.start"].service' | while read service; do
echo "$service just started"
done
1 Like
Room
October 18, 2021, 12:13pm
6
daniel:
How about
Thank you! I don't know what I did wrong yesterday, but today the ubus subscribe service
is working.
I excluded jsonfilter
because it doesn't read the incoming stream all the time, but did it through if
and grep
right in the while loop.
system
Closed
October 28, 2021, 12:13pm
7
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.