Current version: 0.1.4 (30 November 2024) [src]
scw
extends scheduled commands to
add concurrency locking, prerequisites, dependency checks, conflict
avoidance, randomised startup delays, flexible logging, and monitoring
metrics.
There are no complex dependencies - all you need to run
scw
is a scheduler such as
cron
.
Purpose
Many scheduled commands either dump their output into an email, or write logs which maybe have a start and end timestamp, but nothing in between. If the operator doesn’t get the email or check the logs, they won’t know about errors.
For example an old script might run 3 backups and produce a log like this:
Starting at Sat 9 Nov 10:42:22 GMT 2024 Backup job 1 OK tar: /root: Cannot open: Permission denied Backup job 2 failed! Backup job 3 OK Finished at Sat 9 Nov 13:42:43 GMT 2024
Searching the log for “failed” won’t say which day contained the failure, if the log spans several days - and there’s no way to tell specifically when backup job 2 failed, making fault analysis difficult.
Running the same script under scw produces logs like this:
2024-11-09T10:42:22 [s] (begin) 2024-11-09T10:42:22 [-] Starting at Sat 9 Nov 10:42:22 GMT 2024 2024-11-09T11:20:01 [-] Backup job 1 OK 2024-11-09T11:30:47 [E] tar: /root: Cannot open: Permission denied 2024-11-09T11:50:55 [-] Backup job 2 failed! 2024-11-09T13:42:42 [-] Backup job 3 OK 2024-11-09T13:42:43 [-] Finished at Sat 9 Nov 13:42:43 GMT 2024 2024-11-09T13:42:43 [s] (end) exit status 1, elapsed time 10821s
The output is timestamped, the exit status of the script is recorded, and an error marker file is created for monitoring systems to detect. This is all done without having to change the original script.
Features
Each distinct scheduled command is referred to as an “item” and can have its own configuration for each of these features:
Concurrency locking prevents an item from being run more than once at the same time, for example if it’s scheduled to run every 2 minutes and occasionally takes longer than that to complete.
Prerequisites allow an item to be prevented from running if some prior condition is not met, for example checking whether this is the active node of a failover cluster, or whether some crucial underpinning service is running.
Dependency checks allow an item to run only if some other item has succeeded before it - with the possibility of waiting a short while for the dependency to finish rather than giving up straight away. Useful when linked items need to be scheduled separately at particular times but the later one can only run if the earlier one has succeeded. For example, a data load batch may have to run at some time in the early morning, and a subsequent data processing batch, which for business reasons has to run after a particular time of day, can only run if the early morning data load succeeded.
Conflict avoidance prevents an item from running if some other item is still running - with the possibility of waiting a short while for the conflicting item to finish rather than giving up straight away.
Randomised startup delays can be configured for items, which is useful for avoiding resource overconsumption when the same item is scheduled to run on multiple systems.
Logging can be to any combination of files, syslog, email, or HTTP, with or without timestamps. The standard output and standard error of items can be combined or separated, and a special status stream is also made available so that significant events (such as starting each step of a multi-step process) can be recorded separately.
Metrics files are generated for each item. Any monitoring agent can read these files and raise alerts based on their contents. An item list file (a JSON array of item descriptions) is automatically generated so that a system such as Zabbix can find and monitor all items without needing an operator to make adjustments when items are added or removed.
In its simplest form, scw can be invoked from existing scheduler entries like this:
# Original entry 0 * * * * /some/command --option ARGUMENT # Replacement 0 * * * * scw run mycommand -s Command="/some/command --option ARGUMENT"
To make use of the full range of features, scheduled command
definitions can instead be placed into the scw item
definition directory, and “scw update
” can then generate
the appropriate crontab.
This software is distributed under the terms of the GNU General Public License version 3 or later.
- Source code: scw-0.1.4.tar.gz [signature]
- Setup guide for SCW
- Manual for SCW
- Git repository (at Codeberg)
- Issue tracker (at Codeberg)
To install scw
, follow these steps:
wget https://www.ivarch.com/programs/sources/ scw-0.1.4.tar.gz tar xzf scw-0.1.4.tar.gz cd scw-0.1.4 sh ./configure make sudo make install
Comments, bug reports, and patches can be sent using the Issue tracker, or through the Contact Form.
News
0.1.4 - 30 November 2024
- feature: new “TransmitForm” and “TransmitJSON” settings
- cleanup: tests now cover HTTP POST formats and long line handling
- docs: new setup guide
- docs: Zabbix autodiscovery template
0.1.0 - 24 November 2024
- fix: use Unix sockets to correct the ordering of mixed-stream output
- fix: record incomplete lines if the command did not end its final output with a newline
- fix: record the buffered output if the command exits with unrecorded output still in the pipeline
- fix: correct compilation problem on CentOS
- fix: correct fault in crontab and item list generation in all-users mode
- fix: remove failure marker on successful run
- i18n: translation stubs added
- cleanup: address all warnings from splint and flawfinder
- cleanup: test suite covering all actions and file-based recording
0.0.2 - 21 November 2024
- feature: new “–strict” option to govern whether to allow a run to proceed with warnings, if either the MetricsDir or the CheckLockFile is inaccessible, or an OutputMap file cannot be written to
- fix: drop the “run ITEM – command” syntax, as passing the command that way will guarantee shell quoting mishaps
- fix: correct the colour-coding of unbracketed status on the terminal
- fix: correct the status file descriptor being closed at the wrong time
- fix: correct the generation of the prerequisites-met metrics file
0.0.1 - 20 November 2024
- initial release