@@ -17,9 +17,18 @@ regularly as cron jobs.
1717- ` populate.py ` - This script provides an example of how to run computations as
1818 part of cron jobs. This is not currently in use.
1919- ` run_jobs.sh ` - This script ...
20+ - Reads from the ` .env ` file in the same directory.
2021 - Updates the spyglass repository, fetching from the master branch.
2122 - Runs a database connection check (relying on a valid datajoint config).
2223 - Runs the ` cleanup.py ` script.
24+ - ` check_disk_space.sh ` - This script ...
25+ - Reads from the same ` .env ` file as ` run_jobs.sh ` .
26+ - Checks the disk space of each drive in ` SPACE_CHECK_DRIVES `
27+ - Calculate the percent available relative to ` SPACE_PERCENT_LIMIT ` .
28+ - If above, sends an email for each drive to each recipient listed in
29+ ` SPACE_EMAIL_RECIPENTS ` .
30+ - If provided with ` SLACK_TOKEN ` and ` SLACK_CHANNEL ` , posts a message to
31+ slack.
2332
2433## Setup
2534
@@ -28,26 +37,51 @@ regularly as cron jobs.
2837 ` dj_local_conf.json ` and filling in the necessary information.
29383 . Copy the ` example.env ` file to ` .env ` in the ` maintenance_scripts ` directory
3039 and fill in the necessary information, including...
31- - ` SPYGLASS_CONDA_ENV ` : the name of the conda environment with Spyglass and
32- DataJoint installed.
33- - ` SPYGLASS_REPO_PATH ` : the path to the Spyglass repository.
34- - ` SPYGLASS_LOG ` : the path to the log file.
35- - Optional email settings. If not set, email notifications will not be sent.
36- - ` SPYGLASS_EMAIL_SRC ` : The email address from which to send notifications.
37- - ` SPYGLASS_EMAIL_PASS ` : the password for the email address.
38- - ` SPYGLASS_EMAIL_DEST ` : the email address to which to send notifications.
39- 4 . Set up a cron job to run ` run_jobs.sh ` at the desired interval by running
40+ - Items for running cleanup jobs:
41+ - ` SPYGLASS_CONDA_ENV ` : the name of the conda environment with Spyglass and
42+ DataJoint installed.
43+ - ` SPYGLASS_REPO_PATH ` : the path to the Spyglass repository.
44+ - ` SPYGLASS_LOG ` : the path to the log file.
45+ - Optional email settings. If not set, email notifications will not be
46+ sent.
47+ - ` SPYGLASS_EMAIL_SRC ` : The email address from which to send
48+ notifications.
49+ - ` SPYGLASS_EMAIL_PASS ` : the password for the email address.
50+ - ` SPYGLASS_EMAIL_DEST ` : the email address to which to send
51+ notifications.
52+ - Items for checking disk space:
53+ - ` TZ ` : the timezone to use reporting local times.
54+ - ` SPACE_PERCENT_LIMIT ` : the percentage of disk space below which to send
55+ notifications.
56+ - ` SPACE_CHECK_DRIVES ` : a space-separated list of drives to check.
57+ - ` SPACE_LOG ` : the path to the log file.
58+ - ` SPACE_EMAIL_SRC ` /` SPACE_EMAIL_PASS ` : email sender settings for disk
59+ space notifications.
60+ - ` SPACE_EMAIL_RECIPENTS ` : a space-separated list of email addresses to
61+ receive disk space notifications.
62+ - Items for posting to slack:
63+ - ` SLACK_TOKEN ` : the token for the slack app.
64+ - ` SLACK_CHANNEL ` : the channel to post to.
65+ 4 . Set up a cron job to run each shell script at the desired interval by running
4066 ` crontab -e ` and adding the script.
4167
4268Note that the log file will automatically be truncated to ` SPYGLASS_MAX_LOG `
4369lines on each run. 1000 lines should be sufficient.
4470
45- ### Example Cron Job
71+ To enable slack notifications, you will need to create a slack app and generate
72+ a token following the instructions
73+ [ here] ( https://api.slack.com/tutorials/tracks/posting-messages-with-curl ) .
74+ For posting to a private channel, you will need to invite the app to the
75+ relevant channel before attempting to post.
4676
47- In the following example, the script is set to run every Monday at 4:00 AM.
77+ ### Example Cron Jobs
78+
79+ In the following example, the cleanup script is set to run every Monday at 4:00
80+ AM, and the disk space check is set to run every day at 8:00 AM.
4881
4982``` text
50830 4 * * 1 /path/to/run_jobs.sh
84+ 0 8 * * * /path/to/check_disk_space.sh
5185```
5286
5387### Email Service
0 commit comments