Skip to content
Rüdiger Beck edited this page Jan 14, 2018 · 8 revisions

Hooks

Hooks can be used to run your own scripts after users are added/updated/killed with sophomorix-add/sophomorix-update/sophomorix-kill.

To find out in which directory sophomorix expects your scripts and to run them initially, use sophomorix-hook:

For example:

  • sophomorix-hook --update to see which scripts would be run
  • sophomorix-hook --update --run to run the scripts

sophomorix-hook is what you need to debug your scripts. How they are called where the output is logged, ... It shows what is actually done. Even if this wiki page should be outdated.

For Scripts the following rules apply:

  • The script must be executable
  • The <scriptname> must end with a-zA-Z0-9. Other names are ignored (i.E. Editor backups)
  • If there are multiple scripts in a directory, they are run in ascibetically order. So 002-script is run after 001-script.
  • The scripts are run as the last thing, so that sophomorix can continue without delay.
  • The scripts are run in the background (nor sure yet!!!???). STDOUT and STDERR are both logged in one log file per script (appended)
  • The scripts are NOT run when 0 users are added/updated/killed
  • You must decide if you need a global script or school script:
    • Global scripts are called with the <epoch> parameter (they should handle ALL users)
    • School scripts are called with the parameters <epoch> <school> (they should handle ONLY users of this school)
    • You also need to decide what you script must do, when a user is moved FROM another school TO your school OR moved FROM your school TO another school.
  • Your scripts should be designed to run multiple times without falling on their noses.
  • If you need to know, which user was modified, you must parse logfiles
    • The following files might be interesting for you:
      • /var/log/sophomorix/userlog/user-add.log (one line per user addition)
      • /var/log/sophomorix/userlog/user-update.log (one or more lines per user update)
      • /var/log/sophomorix/userlog/user-kill.log (one line per user deletion)
    • Parse the appropriate logfile, and find the users added/updated/killed this time by the unix epoch (first parameter of the script, second entry in a logline)
Clone this wiki locally