jobstart

Package: WA2L/edrc 1.5.57
Section: General Commands (1)
Updated: 15 September 2024
Index Return to Main Contents

 

NAME

jobstart - run jobs thru a simple interface

 

SYNOPSIS

edrc/bin/jobstart [ -h | -V

jobstart JOBNAME...

jobstart ( -e | fun | distribute )

jobstart ( -l | list | time | timeline ) [ query ]

jobstart ( runs | runs-days | stats | stats-days ) [ query ]

jobstart ( enable | disable | unlock | lock ) JOBNAME...
jobstart ( enable | disable | unlock | lock ) all

jobstart print JOBNAME

jobstart log [ begin [ end ]]

jobstart logswitch

 

AVAILABILITY

WA2L/edrc

 

DESCRIPTION

Start jobs using a simple interface, where a job is identified by a JOBNAME.

The jobstart command can be called manually as user root from the command line, but running it scheduled (i.e. from cron or at) is the main purpose.

The jobstart command can be started on any system where it is available. However, the JOBNAME is started from the system that is configured in the JOBSTART_SYSTEM=system setting (e.g. JOBSTART_SYSTEM="root@acme301.acme.ch") in the jobstart.cfg configuration file.

If a job runs on a target system different to the JOBSTART_SYSTEM, the job needs to connect to the related target system (using ssh-exec for example).

Therefore the JOBSTART_SYSTEM acts like a hub to execute all jobs.

This to simplify jobs writing, understanding the job start mechanism and to consolidate the log output centrally.

The intention is to implement the job commands in the jobstart.cfg file to fulfill a specific task. The user then can start those (probably more complex) tasks using the JOBNAME without the need to remember command line options or dependencies.

The output of stderr and stdout is logged to the logfile, therefore it is not necessarily needed to write to a dedicated logfile from the job.

The JOBNAME should be in upper case and only the underscore (_) character should be used as separator.

Add additional jobs to the jobstart.cfg file between the

  # v-------------- JOBS FOLLOW ---------------v #

  :
  :

  # ^--------------- JOBS END -----------------^ #

markers.

See section EXAMPLES for example job definitions.

 

OPTIONS

-h
usage message.

-V
print configuration file name and configuration file version.

-e
edit the jobstart.cfg file in vi(1) editor.

Running jobs are not affected by the editing of the jobstart.cfg file.

Be aware, that the configuration file is saved automatically before editing using the vsav(1) command internally. Therefore when a messed-up file was saved, or to check changes, the vls(1), vdiff(1), vrestore(1) etc. commands can be used to verify changes or revert to a previous version.

-l | list
list all JOBNAMEs currently defined sorted by JOBNAME including a short description, a reference to additional job documentation and informs if and when the JOBNAME is scheduled in the crontab of root.

The name, description and the job documentation reference is extracted from the configuration file if the job is defined as:

  JOBNAME)      # description of the job

or

  JOBNAME)      # description of the job / [REF]

in the jobstart.cfg file.

time
list all JOBNAMEs currently defined sorted by scheduled HOUR and MINUTE.

timeline
list all JOBNAMEs currently defined sorted by scheduled HOUR and MINUTE whereas all range- and list-definitions are expanded to it's planned scheduled time.

query
wildcard expression to include only a subset of JOBNAMEs in the output.

print
print definition of job with given JOBNAME.

fun
list special utility functions that can be used in job definitions.

runs
overview of all jobs started yesterday and today. The report is sorted by the END time of the completed jobs.

runs-days
overview of all jobs started the last number of days. The report is sorted by the END time of the completed jobs.

runs-0
overview of all jobs started since begin. The report is sorted by the END time of the completed jobs.

stats
statistics of all jobs started the last 90 days.

Only job RUNS that are not skipped (due to jobstart.cfg configuration file syntax errors (EXITCODE = 2) or are disabled/locked (ACTIVE = False)) are COUNTed for job runtime statistics calculations.

Starts of jobs that are not defined are not listed.

stats-days
statistics of all jobs started the last number of days.

stats-0
statistics of all jobs started since begin.

log [ begin [ end ]]
print the jobstart.log file between the begin and end line number.

distribute
distribute the jobstart.cfg file to the relevant nodes as defined in the DISTRIBUTION=host_list in the environment to keep it in sync after changes.

The host_list is a comma separated list of hosts (as returned by the hostlist -l command).

JOBNAME...
start a job identified by the JOBNAME.

A space separated list of JOBNAMEs can be defined to execute several jobs in sequence. The jobstart command stops executing a JOBNAME sequence as soon as a JOBNAME has an exit code different to 0 (success) and 98 (deactivated).

enable
enable a given job with JOBNAME or all jobs to be started.

disable
disable a given job with JOBNAME or all current jobs from being started.

A disabled JOBNAME is listed as ACTIVE False when listing all jobs using jobstart list.

unlock
unlock a given job with JOBNAME or all jobs to be started.

lock
lock a given job with JOBNAME or all current jobs from being started.

lock provides a second level of disabling jobs from being started beside of the jobstart disable JOBNAME command.

jobstart lock JOBNAME is used to rather permanently prevent a job from being started where jobstart disable JOBNAME is used to rather temporarily prevent a job from being started.

A locked JOBNAME is listed as ACTIVE False when listing all jobs using jobstart list.

logswitch
move the contents of the current log file jobstart.log to jobstart.<TIMESTAMP>.log.

After a logswitch the runs, stats and log options can still be used to query information of all jobstart log files (the current jobstart.log and all available jobstart.<TIMESTAMP>.log files) without the need to know in which file the information is stored.

A log switch can significantly improve performance for queries of more recent events without loosing information as a normal log rotate would.

The jobstart logswitch command should probably be scheduled (using ecrontab(1) for example).

 

ENVIRONMENT

$EDRC_DEBUG_JOBSTART_JOBS
set this environment variable to True to switch on jobs debugging and to False to switch off debugging.

 

EXIT STATUS

0
no error.

1
error.

2
the configuration file has syntax errors. No jobs will be started if a syntax error is detected in the configuration file.

3
configuration file edrc/etc/jobstart.cfg not found.

4
usage displayed.

5
command aborted (using Ctrl+C).

6
config file version displayed.

7
program file distributed using the distribute option.

8
job activated using the jobstart enable JOBNAME or jobstart unlock JOBNAME command.

9
job deactivated using the jobstart disable JOBNAME or jobstart lock JOBNAME command.

10
utility functions that can be used in jobs listed.

11
list of jobs displayed using the list, time or timeline option.

12
the configuration file jobstart.cfg has been edited using the -e option.

13
log file jobstart.log printed using the log option.

14
JOBNAME definition printed.

16
command start not permitted. This error occurs, if jobstart command is started by a user different to the user defined in the optional STARTUSER=user setting, or the user has no permission to write to the jobstart.log file, the jobstart.locked file or the jobstart.disabled file.

98
started JOBNAME is deactivated (by jobstart disable JOBNAME or jobstart lock JOBNAME

99
supplied JOBNAME is not defined.

 

FILES

edrc/etc/jobstart.cfg
configuration file with jobs definitions.

edrc/etc/jobstart.lib
optional environment specific function library to be used in jobs.

This functions could also be added to the jobstart.cfg config file, but when defining the functions in jobstart.lib the functions are listed when jobstart fun is used and the comment format is:

  # myfunction opt1 opt2 -- description

edrc/var/cache/jobstart/jobstart.cache
cached property data of switched log files.

edrc/var/log/jobstart.log
log file of jobstart.

edrc/var/settings/jobstart.disabled
list of disabled jobs. This file is maintained when using jobstart ( enable | disable ) JOBNAME.

edrc/var/settings/jobstart.locked
list of locked jobs. This file is maintained when using jobstart ( unlock | lock ) JOBNAME.

 

EXAMPLES

1) example job definitions

A job is a shell case structure, which is

  JOBNAME)    # job description
              echo "job code goes here ..."
              ;;

or with a reference to additional job documentation:

  JOBNAME)    # job description / [REF]
              echo "job code goes here ..."
              ;;

The example below shows the definition of the jobs SYS2HTML and CRONTAB:

  # v------------------------------------- JOBS FOLLOW --------------------------------------v #

  CRONTAB)            # list JOBSTART_SYSTEM crontab / crond(3)
                      #
                      echo "# ========== system root crontab =========="
                      crontab -l
                      echo "# =========== edrc root crontab ==========="
                      ecrontab -l
                      set_exitcode 0
                      ;;

  SYS2HTML)           # system configuration HTML
                      #
                      collect=`hostlist`
                      outputdir=$REPORTDIR/SYS2HTML/$TODAY

                      # job workload 
                      #
                      mkdir $outputdir >/dev/null 2>&1; chmod 755 $outputdir
                      sys2html -o $outputdir $collect
                      set_exitcode 0
                      ;;

  # ^--------------------------------------- JOBS END ---------------------------------------^ #

2) list jobs

To list all defined jobs, output correlates to example 1):

  [ / ]
  [ root@acme301 ][*edrc*/bash]: jobstart -l

  ACTIVE JOBNAME  CRON  HOUR MINUTE DAY MONTH WEEKDAY QUEUE   DESCRIPTION                  DOCREF
  ------ -------- ----- ---- ------ --- ----- ------- ------- ---------------------------- --------
  True   CRONTAB                                              list JOBSTART_SYSTEM crontab crond(3)
  True   PUBLISH  YES   08   00     *   *     1,3     Q02-J01 publish documentation files
  True   SYS2HTML YES   12   00     *   *     7       Q01-J01 system configuration HTML
  True   WEBSYNC  YES   12   00     *   *     7       Q01-J02 synchronize webserver data   [DLD]
  (2)

The scheduling information is resolved from the ecrontab and crontab definition on the JOBSTART_SYSTEM:

  [ / ]
  [ root@acme301 ][*edrc*/bash]: ecrontab -l

  #
  # acme301:~edrc/var/spool/cron/root - root crontab
  #
  # [000] 06.07.2021 CWa  Initial Version
  #
  
  SHELL=/bin/bash
  PATH=~edrc/bin:/usr/bin:/bin
  
  #------ ------ ------ ------ -------------- ------------------------------------------
  #MINUTE HOUR   DAY    MONTH  WEEKDAY        COMMAND
  #(0-59) (0-23) (1-31) (1-12) (1=Mon, 7=Sun)
  #------ ------ ------ ------ -------------- ------------------------------------------
  00      12     *      *      7              jobrun SYS2HTML WEBSYNC
  00      08     *      *      1,3            jobrun PUBLISH
  #------ ------ ------ ------ -------------- ------------------------------------------

 

SEE ALSO

edrcintro(1), crontab(1), ecrontab(1), crond(3), fit(3), hostlist(3), jobstart.cfg(4), jobstart.lib(4), fnmatch(3), sh(1), ssh-exec(1), usage(1), vdiff(1), vls(1), vrestore(1), vsav(1)

 

NOTES

Beside the operating system commands, all commands provided by the WA2L/edrc package can be used.

To use jobstart in an application, create a symlink to the edrc/bin/jobstart command with a different name:

Example:

  ln -s ~edrc/bin/jobstart /opt/myApp/bin/jobctl

The FILES of such a jobstart instance are: /opt/myApp/etc/jobctl.cfg, /opt/myApp/etc/jobctl.lib, /opt/myApp/log/jobctl.log, /opt/myApp/var/jobctl.disabled, /opt/myApp/var/jobctl.locked, and edrc/var/cache/jobstart/jobctl.cache.

The setting JOBRUN_SYSTEM=system defines the system from where the jobs are started for an instance with any name of jobstart (jobctl in this example), as the JOBSTART_SYSTEM=system does for jobstart.

 

BUGS

-

 

AUTHOR

jobstart was developed by Christian Walther. Send suggestions and bug reports to wa2l@users.sourceforge.net .

 

COPYRIGHT

Copyright © 2021 Christian Walther

This is free software; see https://www.gnu.org/licenses/gpl-2.0.html for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


 

Index

NAME
SYNOPSIS
AVAILABILITY
DESCRIPTION
OPTIONS
ENVIRONMENT
EXIT STATUS
FILES
EXAMPLES
SEE ALSO
NOTES
BUGS
AUTHOR
COPYRIGHT

This document was created by man2html using the manual pages.
Time: 22:03:45 GMT, December 09, 2024