Skip to content

Commit

Permalink
[seiscomp] Add option --invert
Browse files Browse the repository at this point in the history
  • Loading branch information
gempa-dirk authored and gempa-jabe committed Oct 7, 2024
1 parent e2255b3 commit 52e6037
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 19 deletions.
46 changes: 35 additions & 11 deletions src/system/apps/seiscomp/descriptions/seiscomp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ options and commands, e.g., the command :command:`help`. Apply
$HOME/seiscomp-test/bin/seiscomp
Many of these actions are used by :ref:`scconfig`
Many of these actions are used by :ref:`scconfig`.


.. _sec_seiscomp_help:
Expand All @@ -50,6 +50,12 @@ other commands including examples:
seiscomp help
For basic help you may also use the option :option:`-h`:

.. code-block:: sh
seiscomp -h
.. _sec_seiscomp_applications:

Expand Down Expand Up @@ -139,8 +145,8 @@ categories. Examples:
.. _sec_seiscomp_enable:

Enable/disable
--------------
Enable/disable [*]_
-------------------

Enabled modules will be started to run as a background daemon module.
You may enable or disable one or multiple modules. Examples:
Expand All @@ -154,8 +160,8 @@ You may enable or disable one or multiple modules. Examples:
.. _sec_seiscomp_start:

Start/stop/restart/reload
-------------------------
Start/stop/restart/reload [*]_
------------------------------

Start all enabled modules:

Expand Down Expand Up @@ -194,8 +200,8 @@ modules and parameters.

.. _sec_seiscomp_check:

Check
-----
Check [*]_
----------

When modules stop unexpectedly, they are not stopped in a clean way. Such
stopped modules may be detected and started again in order to minimize
Expand Down Expand Up @@ -236,8 +242,8 @@ Examples:
.. _sec_seiscomp_status:

Status
------
Status [*]_
-----------

List the status of all, enabled, disabled, started, or specific modules.
Examples:
Expand Down Expand Up @@ -300,8 +306,8 @@ interactively.
.. _sec_seiscomp_update:

Update configuration
--------------------
Update configuration [*]_
-------------------------

The command :command:`update-config` allows reading bindings configurations from
the standard :file:`@KEYDIR@` directory as well as inventory from
Expand Down Expand Up @@ -407,3 +413,21 @@ seiscomp shell:
Lists all available profiles of a module.
...
.. note::

.. [*] With this command, the flag :option:`--invert` can be used
in order to invert the application to the specific modules. You may provide
one or more module names. A major application is to
restart most |scname| modules after a change in global bindings. However,
:ref:`seedlink` and :ref:`slarchive` are not affected by global
bindings and any downtime of these modules shall be avoided. Example:
.. code-block:: sh
seiscomp --invert restart seedlink slarchive
The same procedure could be achieved without :option:`--invert` by
explicitly stating all other modules which, however, may result in a
long list of module names.
13 changes: 12 additions & 1 deletion src/system/apps/seiscomp/descriptions/seiscomp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@
Print output as CSV in machine-readable format.
</description>
</option>
<option flag="h" long-flag="help" argument="" publicID="">
<description>
Produce this help message.
</description>
</option>
<option flag="i" long-flag="interactive" argument="" publicID="">
<description>
Interactive mode: Allow deleting files interactively when
Interactive mode: Allow deleting configurations interactively when
removing aliases.
</description>
</option>
<option flag="" long-flag="invert" argument="" publicID="">
<description>
Invert the selection of the specified module names when using any of the
commands: start, stop, check, status, reload, or restart.
</description>
</option>
<option flag="" long-flag="wait" argument="arg" publicID="">
<description>
Define a timeout in seconds for acquiring the seiscomp lock
Expand Down
42 changes: 35 additions & 7 deletions src/system/apps/seiscomp/seiscomp-control.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ def system(args):
# return subprocess.call(cmd, shell=True)


def info(msg):
sys.stderr.write(f"info: {msg}\n")
sys.stderr.flush()


def error(msg):
sys.stderr.write(f"error: {msg}\n")
sys.stderr.flush()
Expand Down Expand Up @@ -1357,21 +1362,27 @@ def on_help(args, _):
print("\nSynopsis:")
print(" seiscomp [flags] [commands] [arguments]")
print("\nFlags:")
print(" --asroot Allow running a command as root")
print(" --csv Print output as csv in machine-readable format")
print(" -h, [--help] Produce this help message.")
print(" --asroot Allow running a command as root.")
print(" --csv Print output as csv in machine-readable format.")
print(
" -i, [--interactive] Interactive mode: Allow deleting files "
"interactively when removing aliases"
" -i, [--interactive] Interactive mode: Allow deleting configurations "
"interactively when removing aliases."
)
print(
" --invert Invert the selection of the specified module names "
"when using any of the commands: start, stop, check, status, reload, or "
"restart."
)
print(
" --wait arg Define a timeout in seconds for acquiring the seiscomp "
"lock file, e.g. `seiscomp --wait 10 update-config`"
"lock file, e.g. `seiscomp --wait 10 update-config`."
)
print("\nAvailable commands:")
for helpAction in allowed_actions:
print(f" {helpAction}")

print("\nUse 'help [command]' to get more help about a command")
print("\nUse 'help [command]' to get more help about a command.")
print("\nExamples:")
print(" seiscomp help update-config Show help for update-config")
print(
Expand Down Expand Up @@ -1424,21 +1435,28 @@ def on_csv_help(_):
asRoot = False
lockTimeout = None
interactiveMode = False
invert = False

argv = sys.argv[1:]
argflags = []

# Check for flags
while argv:
if argv[0] == "--help" or argv[0] == "-h":
on_help([], "")
sys.exit(1)
if argv[0] == "--csv":
useCSV = True
argv = argv[1:]
elif argv[0] == "--asroot":
asRoot = True
argv = argv[1:]
if argv[0] == "--interactive" or argv[0] == "-i":
elif argv[0] == "--interactive" or argv[0] == "-i":
interactiveMode = True
argv = argv[1:]
elif argv[0] == "--invert":
invert = True
argv = argv[1:]
elif argv[0] == "--wait":
argv = argv[1:]
if not argv:
Expand All @@ -1459,13 +1477,15 @@ def on_csv_help(_):
else:
break


if len(argv) < 1:
print("seiscomp [flags] {%s} [args]" % "|".join(allowed_actions))
print("\nUse 'seiscomp help' to get more help")
sys.exit(1)

action = argv[0]
arguments = argv[1:]
inverted = []

if action not in allowed_actions:
print("seiscomp [flags] {%s} [args]" % "|".join(allowed_actions))
Expand All @@ -1476,6 +1496,12 @@ def on_csv_help(_):
print("know exactly what you are doing!")
sys.exit(1)

if invert and action in ["start", "stop", "check", "status", "reload", "restart"]:
inverted = arguments
arguments = []
else:
invert = False

# ------------------------------------------------------------------------------
# Initialize the environment
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -1602,6 +1628,8 @@ def on_csv_help(_):
for m in config_mods:
if m.isConfigModule:
continue
if invert and m.name in inverted:
continue
mods.append(m)

sys.exit(run_action(action, arguments, argflags))

0 comments on commit 52e6037

Please sign in to comment.