-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions - cron_add() - cron_remove() which will be available in custom user/project startup scripts
- Loading branch information
1 parent
0420235
commit 00fbf12
Showing
3 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -u | ||
set -o pipefail | ||
|
||
|
||
########################################################### | ||
# Functions | ||
############################################################ | ||
|
||
# add line to devilbox's crontab, if not already there | ||
# and start cron service | ||
cron_add() { | ||
# save the entire line in one variable | ||
line="$*" | ||
|
||
DEBUG_LEVEL="$( env_get "DEBUG_ENTRYPOINT" "0" )" | ||
|
||
# check if line already exists in crontab | ||
crontab -l -u devilbox | grep "$line" > /dev/null | ||
status=$? | ||
|
||
if [ $status -ne 0 ] | ||
then | ||
log "info" "cron: adding line '${line}' ..." "$DEBUG_LEVEL" | ||
(crontab -l -u devilbox; echo "$line";) | crontab -u devilbox - | ||
fi | ||
|
||
# make sure the cron service is running | ||
if ! service cron status >/dev/null | ||
then | ||
service cron start | ||
fi | ||
} | ||
export -f cron_add | ||
|
||
cron_remove() { | ||
# save the entire line in one variable | ||
line=$* | ||
|
||
DEBUG_LEVEL="$( env_get "DEBUG_ENTRYPOINT" "0" )" | ||
|
||
# check if line already exists in crontab | ||
crontab -l -u devilbox | grep "$line" > /dev/null | ||
status=$? | ||
|
||
if [ $status -eq 0 ]; then | ||
log "info" "cron: removing line '${line}' ..." "$DEBUG_LEVEL" | ||
(crontab -l -u devilbox | grep -v "$line";) | crontab -u devilbox - | ||
fi | ||
} | ||
export -f cron_remove |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters