Commit graph

6 commits

Author SHA1 Message Date
Christian Marangi
d97883005f
rc: add option to get info for a single script in list method
Add option to get info for a single script in list method.

To get info of a particular script pass the name arg to the list method.

If the script doesn't exist an empty table is returned.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
2023-01-31 16:11:24 +01:00
Christian Marangi
632b4fc898
rc: add option to skip running check for list method
Running check may be slow and increase result time in the other of 70ms
for the list method.

Add an option to skip running check by passing the skip_running_check as
true in the list method args to speedup execution if the running info is
not needed.

With the option set to true the execution time lower to just 5ms.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
2023-01-31 16:11:23 +01:00
Christian Marangi
5577db9208
rc: add support for scanning USE_PROCD and skip running if not supported
Running check is supported only in procd scripts. This cause prolonged
execution time since the function needs to timeout.

To fix this check if the script USE_PROCD and run running check only if
supported.

Also provide running info only if the running check is supported.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
2023-01-31 16:11:23 +01:00
Christian Marangi
4de3f02e31
rc: fix and improve script scanning START and STOP
Currently we stop searching at the first occurence of START or STOP
entry. This is wrong since we totally miss the other data (START or
STOP) in the occurence of the other.

Fix and improve script scanning by:
- Increase the line max length to 255 char to read it in one go.
- Scan only the first 10 lines.
- Don't stop at the first occurence and try to search also for the other
  data.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
2023-01-31 16:11:17 +01:00
Rafał Miłecki
3fea655981 rc: support init.d scripts with START=0
Use negative value (instead of 0) to indicate missing START.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2020-09-18 08:10:56 +02:00
Rafał Miłecki
646daa0bec rc: new ubus object for handling /etc/init.d/ scripts
This commit adds "rc" ubus object with methods "list" and "exec" for
listing and calling init.d script appropriately. It's useful for all
kind of UIs (e.g. LuCI) and custom apps.

Example:
root@OpenWrt:~# ubus call rc list
{
	"blockd": {
		"start": 80,
		"enabled": true,
		"running": true
	},
	"dnsmasq": {
		"start": 19,
		"enabled": true,
		"running": true
	}
}
root@OpenWrt:~# ubus call rc init '{ "name": "blockd", "action": "disable" }'
root@OpenWrt:~# ubus call rc init '{ "name": "dnsmasq", "action": "stop" }'
root@OpenWrt:~# ubus call rc list
{
	"blockd": {
		"start": 80,
		"enabled": false,
		"running": true
	},
	"dnsmasq": {
		"start": 19,
		"enabled": true,
		"running": false
	}
}

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Acked-by: Jo-Philipp Wich <jo@mein.io>
2020-09-10 13:18:09 +02:00