Hi,
I'm having a small issue modifying a init/service script (not my own).
The script uses PROCD, but has no active process.
(I thought of maybe using sleep
as a last resort)
When disabled there is no link in /etc/rc.d
When enabled there is a link /etc/rc.d/S99script -> /etc/init.d/script
When started, it applies a configuration
When stopped, it removes said configuration
I redefined service_running(){ [ "$check" = "something" ];}
/etc/init.d/script running
works, but service script running
does not.
So I hopped through the service structure:
running
-> service_running
-> procd_running
-> ubus dump instance
jsonfilter then searches for instance[*].running
So in this case service script running
always returns stopped
because there is no
active process.
Any ideas on how I can solve this?
frollic
November 11, 2024, 1:25pm
2
Create and check for semaphore file in /var ?
Sorry maybe I was too short in my synopsis, but the check works fine, its just this snippet from /sbin/service
that does not like me:
for service in /etc/init.d/* ; do
...
status="$( [ "$(ubus call service list "{ 'verbose': true, 'name': '$(basename "$service")' }" \
| jsonfilter -q -e "@['$(basename "$service")'].instances[*].running" | uniq)" = "true" ] \
&& echo "running" || echo "stopped" )"
https://openwrt.org/docs/guide-developer/procd-init-script-example
Can anyone tell me why this works
/var/myscript.sh
#!/bin/sh
sleep 1d
# service
..
/etc/init.d/myservice enabled running
and this does not:
#!/bin/sh
read -p "Press key to continue.. " -n1 -s
# service
..
/etc/init.d/myservice enabled stopped
edit: most likely stdin is closed
I looked at /sbin/service
and a service has to have an active process to toggle the stopped/running status.
Currently I cannot see if my service is active or not (other than running it directly /etc/init.d/myservice running).
Is there another way to toggle that flag?
pavelgl
November 15, 2024, 4:42pm
6
You open a second thread on the same subject.
If it is so important for you to see the status using service
, then modify /sbin/service
.
# /sbin/service
...
status="$( [ "$(ubus call service list "{ 'verbose': true, 'name': '$(basename "$service")' }" \
| jsonfilter -q -e "@['$(basename "$service")'].instances[*].running" | uniq)" = "true" ] \
&& echo "running" || echo "stopped" )"
# Start of modification
if [ $(basename "$service") == "myservice" ]; then
$service running
[ "$?" == "0" ] && status="running" || status="stopped"
fi
# End of modification
printf "%-30s\\t%10s\\t%10s\\n" "$service" "$boot" "$status"
...
Thank you for your time,
I made a generic modification, so it would benefit any service
that has defined the function running()
and would like to submit a PR.
Do you happen to know to which repo /sbin/service
belongs?
(because I cannot find it anywhere in either the openwrt or procd repo)
pavelgl
November 16, 2024, 7:13am
8
Execute command
/etc/init.d/svc_name info
and parse the complete information from the procd yourself.
@pavelgl :
Submitted PR 16992
@remittor
I'll look into that
@pavelgl
I'm fairly confident its done now, and its faster too.
OpenWrt SNAPSHOT, r28146-52b6c92479:
# time /rom/sbin/service | (sleep 1;sha256sum)
real 0m 0.46s
user 0m 0.36s
sys 0m 0.07s
da6d75540a7910a63cfbfa1e86d8fd1e070c10e336d37e2f051c2b972c8a3ea6 -
PR16992 applied:
# time /sbin/service | (sleep 1;sha256sum)
real 0m 0.14s
user 0m 0.16s
sys 0m 0.01s
da6d75540a7910a63cfbfa1e86d8fd1e070c10e336d37e2f051c2b972c8a3ea6 -