Annvix:Tools/srv/Dependency

From linsec.ca
Jump to: navigation, search

I would like to overhaul the dependency tracking mechanism for services.

Contents

Goals

  • Move most logic into the srv program
    • Reduce run time checks
    • Speed up services
    • Notify the admin, rather than do stuff behind back
    • Centralize logic because it may become non-trivial
    • Simplicitic run script implementation for easy integration with execline
  • existing checkdepends() is kinda quiet
    • User is not notified, it goes into the parent's logs and syslog
  • existing checkdepends() is susceptable to misbehavior of looping service
  • existing logic doesn't automatically down depended services
    • Dependency tracking has to be both directions
  • existing logic encourages looping behavior for run script when a dependency to become available instead of waiting for it to come up.
  • existing checkdepends() might have timing issues
    • A service could be running but not actually "working". I would think this could be seen on boot, all services starting at once and high load on box.


Service Implementation

Create a directory called "depends" in the service directory. This will contain symlinks (to its corresponding service directory in /var/service) to the services that it depends on.

For nomenclature, I am going to use "parent" to refer to the service that it depends on and "child" for the service that is depends on a another (think dependency tree/graph).

An example child run script might look like:

NOTE: all code is completely untested

#!/bin/execlineb

/bin/elglob -0 DEPENDS ./depends/*

# MAYBE: backtick -n DEPENDS { find ./depends -type l -xtype d } ?

/bin/foreground { /sbin/svwaitup -t5 $DEPENDS }

<do something>

This will wait until all dependencies have been up 5 seconds before executing.


A parent service (named parent) should have a finish script maybe like :

NOTE: all code is completely untested

#!/bin/execlineb

/bin/elglob -0 CHILDREN /service/*/depends/parent

# MAYBE: backtick -n CHILDREN { find /service/*/depends/parent -type l -xtype d } ?

/bin/foreground { /sbin/runsvctrl r $CHILDREN }

Notice, that we restart the children, this will put them make them wait for the parent service to be available.


Srv Implementation

We need to make sure that we make sure that we do dependency tracking of not just the children but grandchildren, great-grands, etc.

It would be nice to make sure all dependency tracking actions occur before we continue, and if a dependency action cannot be fulfilled then bail.

  • Add Service

We need to generate a dependency graph of the service and starting from the bottom, add each service, make sure it is available (a wait threshold), and then do the next one -- slowing moving upwards to the service we would like to add.

  • Del Service

We need to generate a dependency graph of the service and starting from the bottom, shutdown each service, make sure it is down (a wait threshold), and then do the next one -- slowing moving upwards to the service we would like to delete.

  • Start A Service

We should do a trasversal of the dependency graph starting services.

  • Stop A Service

Technically, the finish script should take care of the dependencies (ie, send them into a wait state). But I think instead of waiting the children programs need to be also stopped. See trasversal of the dependency graph.

  • Restart A Service

Finish script should do it -- but might want to do it explicitely so we can be verbose and know what is occuring.


Notes

New runit version have the ability to utilize a ./check script to service is up and available. I think this might be needed for consistent, reliable services.

Q: I wonder how thorough is sys5 init dependency tracking/resolution is?

Personal tools
other sites