Resolve "Add script(s) for generating diagnostics"
for more info see #4 (closed)
Merge request reports
Activity
- diagnostics/modules/cron.module 0 → 100644
1 help=" 2 info about about the cron 3 " 4 5 if [ "$1" = "run" ] ; then 6 # is running 7 sh modules/processes.module run | grep cron | grep -v 'grep\|cron\.module\|diagnostics' 8 echo 9 10 # get the package info 11 opkg info $(opkg search "$(which cron)" | cut -d ' ' -f1) 12 13 # md5 + sizes of the files 14 grep '' /etc/cron.d/* It prints the contents of a couple of files.
/etc/cron.d/fw-rules:MAILTO="" /etc/cron.d/fw-rules:0 * * * * root /usr/share/firewall/turris-download /etc/cron.d/fw-rules:5 * * * * root /usr/share/firewall/turris /etc/cron.d/majordomo:# m h dom mon dow user command /etc/cron.d/majordomo:*/5 * * * * root majordomo_db.sh downsize /etc/cron.d/majordomo:1 * * * * root majordomo_db.sh genhour /etc/cron.d/majordomo:4 * * * * root majordomo_cache.lua precache /etc/cron.d/majordomo:0 3 */3 * * root majordomo_cache.lua invalidate
I find the approach of modules nice. But this concrete technical solution seems a bit strange.
The help is handled through a variable, while the action is called. One is sourced (every time for all the modules, no matter if we do need help), the other run separately. It seems inconsistent. Also, sourcing all the modules into the main script sounds a bit dangerous (one module could clobber some global variable, like the help text of other module). The help_* name mangling doesn't sound much better.
May I suggest one of these approaches?
- Put the help in a separate file (eg. .module and .help) and load them when they are needed (eg. just cat them).
- Have both the run and help as functions, run it in a sub-process (when needed).
- Have both the content and the help in variables (though this doesn't sound very comfortable).
Furthemore, I think the splitting of functionality into modules could get more attention. For example, putting ip addresses and routes into the same module may make sense (as one is not much useful without the other). We may want to add switch configuration somewhere there as well (or /etc/config/network). The firewall is scattered through multiple modules (why?), while all the logs are indiscriminately in the same module.
Reassigned to @shenek
Well my original intention was to have the module structure like this:
help=" " run() { ... }
And I wanted to have it loaded in the main file as
run_<module_name>
andhelp_<module_name>
. I just wanted to have a separate namespace for each module. I haven't planned on using variables in the modules. So sourcing the file doesn't seemed so bad.Unfortunately I couldn't find a way how to do it in ash. I know how to do it in bash using
declare
built-in. So what you see there is just a simple workaround.Anyways it seems that I don't need the help_* variables that much. So I could do something like this:
#!/bin/bash # help text # help text uname -a
And parse the help from the first comments. What do you think?
Note that I'm still planning to merge some modules (firewall, ip, ...), but I'd like to do it after I update the format.
The parsing approach seems to be both fragile and inconvenient. I don't like it.
If you didn't insist on loading all into memory of the main script (which seems unnecessary and wasteful anyway), I might have a solution. Provide a helper script, something on the lines of:
#!/bin/sh . "$1" case "$2" ; in help) echo "$help" ;; run) run() ;; esac
And use such script as the runner (eg. the thing on the first
#!<something>
line) of the modules. Then you can simply call/path/X.module run
.This is actually the approach that rc scripts use.
Reassigned to @shenek
Reassigned to @shenek
Added 6 commits:
- 1662a5d9 - new module format
- dd13430e - diagnostics: certs module update
- fe3af3be - diagnostics: use nslookup in dns module
- 61f1a0d8 - diagnostics: ips and routes module merged into network module
- a371e4a4 - diagnostics: firewall_turris, firewall_uci and iptables merged into firewall module
- a87af022 - diagnostics: start nikola module without initial sleep
Toggle commit listI hope I fixed your last remark. Unfortunately I managed to perform a force-push a now the comment is somehow lost.
https://gitlab.labs.nic.cz/turris/misc/commit/c5e73a3acbaf71cf1a3024fcd3a89d725a76a303#bf3afb40eebae70d75eb9e92798bad5eacc27846_38_29 -> https://gitlab.labs.nic.cz/turris/misc/commit/1662a5d9b80afdd11bfc3b66cc86fec7b7bb7a73
Reassigned to @shenek
Added 1 commit:
- 7ed51533 - diagnostics: cmdline options added (-O <directory>)
Added 20 commits:
- 7ed51533...dc98526c - 5 commits from branch
master
- 017ef696 - diagnostics: skeleton added
- 6d2e3296 - diagnostics: new modules added
- f5b21035 - diagnostics: a brief description of the module format
- 17dc2340 - diagnostics: stderr -> stdout redirection
- c1f34b02 - diagnostics: new modules added
- dc2a4488 - MAX_LINES_PER_MODULE variable set (default 10000)
- 9a6f1cf5 - diagnostics: new modules added
- 6861eba3 - new module format
- 4f44a3eb - diagnostics: certs module update
- 527a768d - diagnostics: use nslookup in dns module
- 7f1adfc9 - diagnostics: ips and routes module merged into network module
- 6f926382 - diagnostics: firewall_turris, firewall_uci and iptables merged into firewall module
- 95dd0ae2 - diagnostics: start nikola module without initial sleep
- 160f9304 - diagnostics: cmdline options added (-b -o <file>)
- 13080d5b - diagnostics: cmdline options added (-O <directory>)
Toggle commit list- 7ed51533...dc98526c - 5 commits from branch