Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run shepherd via cron #76

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A Docker swarm service for automatically updating your services whenever their b

### Configuration

Shepherd will try to update your services every 5 minutes by default. You can adjust this value using the `SLEEP_TIME` variable.
Shepherd will try to update your services every 5 minutes by default. You can adjust this value using the `SLEEP_TIME` variable. Alternatively set `CRON_SETTING` to run shepherd at a given time. When `CRON_SETTING` is provided, `SLEEP_TIME` will be ignored.

You can prevent services from being updated by appending them to the `IGNORELIST_SERVICES` variable. This should be a space-separated list of service names.

Expand Down
24 changes: 23 additions & 1 deletion shepherd
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ get_registry_password() {
fi
}

main() {
run_main() {
local sleep_time supports_detach_option supports_registry_auth verbose image_autoclean_limit ignorelist
local registry_user=""
local registry_password=""
Expand Down Expand Up @@ -181,6 +181,7 @@ main() {

if [[ ${RUN_ONCE_AND_EXIT+x} ]]; then
update_services "$ignorelist" "$supports_detach_option" "$supports_registry_auth" "$supports_insecure_registry" "$supports_no_resolve_image" "$image_autoclean_limit" "$registry_user" "$registry_password" "$registry_host"
logger "Update finished." "true"
else
while true; do
update_services "$ignorelist" "$supports_detach_option" "$supports_registry_auth" "$supports_insecure_registry" "$supports_no_resolve_image" "$image_autoclean_limit" "$registry_user" "$registry_password" "$registry_host"
Expand All @@ -190,4 +191,25 @@ main() {
fi
}

run_crond() {
mkdir -p /etc/cron.d
echo "${CRON_SETTING:-} BASH_ENV=/save-env /usr/local/bin/shepherd >> /var/log/shepherd.log 2>&1" > /etc/cron.d/shepherd
chmod 0644 /etc/cron.d/shepherd
export RUN_ONCE_AND_EXIT='true'
export CRON_SETTING=''
env > /save-env
crontab /etc/cron.d/shepherd
touch /var/log/cron.log
touch /var/log/shepherd.log
crond -L /var/log/cron.log && tail -f /var/log/cron.log -f /var/log/shepherd.log
}

main() {
if [[ -z "${CRON_SETTING:-}" ]]; then
run_main "$@"
else
run_crond "$@"
fi
}

main "$@"