Skip to content
Snippets Groups Projects

Resolve "Add script(s) for generating diagnostics"

Merged Štěpán Henek requested to merge 4-add-script-s-for-generating-diagnostics into master
1 unresolved thread

for more info see #4 (closed)

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Ghost User
  • Ghost User
    Ghost User @ghost started a thread on the diff
  • 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/*
    • Contributor

      Huh? What is this supposed to do?

    • Author Developer

      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
    • Author Developer

      comment fixed

    • Contributor

      If it is because of the prefix, then I think this is kind of abuse of grep to do so. Maybe a comment explaining the trick would be nice.

    • Please register or sign in to reply
  • Contributor

    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

  • Štěpán Henek Added 1 commit:

    Added 1 commit:

    • 48a18c0d - fixup! diagnostics: skeleton added
  • Štěpán Henek Added 2 commits:

    Added 2 commits:

    • a8baad0d - fixup! diagnostics: skeleton added
    • 9ddcd1b5 - fixup! diagnostics: new modules added
  • Štěpán Henek Added 2 commits:

    Added 2 commits:

    • d494f004 - fixup! diagnostics: new modules added
    • 4137b23d - fixup! diagnostics: skeleton added
  • Author Developer

    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> and help_<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.

  • Štěpán Henek Reassigned to @mvaner

    Reassigned to @mvaner

  • Contributor

    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

  • Štěpán Henek Added 1 commit:

    Added 1 commit:

    • c5e73a3a - new module format
  • Štěpán Henek Added 1 commit:

    Added 1 commit:

    • 004aef85 - diagnostics: certs module update
  • Štěpán Henek Added 1 commit:

    Added 1 commit:

    • 03ce27d8 - diagnostics: use nslookup in dns module
  • Štěpán Henek Added 1 commit:

    Added 1 commit:

    • 077263f5 - diagnostics: ips and routes module merged into network module
  • Štěpán Henek Added 2 commits:

    Added 2 commits:

    • d80cb159 - diagnostics: firewall_turris, firewall_uci and iptables merged into firewall module
    • 59eb2ed8 - diagnostics: start nikola module without initial sleep
  • Author Developer

    Ok, I made a couple of changes you suggested. Please let me know whether you find something that I missed.

  • Štěpán Henek Reassigned to @mvaner

    Reassigned to @mvaner

  • Reassigned to @shenek

  • Štěpán Henek Added 6 commits:

    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
  • Štěpán Henek Reassigned to @mvaner

    Reassigned to @mvaner

  • Contributor

    OK, I think this can be merged.

  • Reassigned to @shenek

  • Štěpán Henek Added 1 commit:

    Added 1 commit:

    • 84afd957 - diagnostics: cmdline options added (-b -o <file>)
  • Štěpán Henek Added 1 commit:

    Added 1 commit:

    • 272c7812 - diagnostics: cmdline options added (-O <directory>)
  • Štěpán Henek Added 1 commit:

    Added 1 commit:

    • a43bc3a8 - fixup! diagnostics: cmdline options added (-O <directory>)
  • Štěpán Henek Added 1 commit:

    Added 1 commit:

    • 7ed51533 - diagnostics: cmdline options added (-O <directory>)

    Compare with previous version

  • Štěpán Henek Added 20 commits:

    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>)

    Compare with previous version

  • Štěpán Henek Status changed to merged

    Status changed to merged

  • Author Developer

    squashed and merged

    Other changes will be performed in nuci.

  • Please register or sign in to reply
    Loading