diff --git a/README.md b/README.md index 9a403b7..4984e16 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ A great project, don't get me wrong. It was just missing certain key enterprise - `name`: Human readable name that will be used as teh job filename. Optional. - `comment`: Comments to be included with crontab entry. Optional. - `schedule`: Crontab schedule syntax as described in https://godoc.org/github.com/robfig/cron. Ex `@hourly`, `@every 1h30m`, `* * * * * *`. Required. -- `command`: Command to be run on docker container/image. Required. +- `command`: Command to be run on in crontab container or docker container/image. Required. - `image`: Docker images name (ex `library/alpine:3.5`). Optional. - `project`: Docker Compose/Swarm project name. Optional, only applies when `contain` is included. - `container`: Full container name or container alias if `project` is set. Ignored if `image` is included. Optional. @@ -86,7 +86,7 @@ COPY logrotate.conf /etc/logrotate.conf CMD ["crond", "-f"] ``` -### Logging +### Logging - In Dev All `stdout` is captured, formatted, and saved to `/var/log/crontab/jobs.log`. Set `LOG_FILE` to `/dev/null` to disable logging. example: `2017-06-18T01:27:10+0000 e6ced859-1563-493b-b1b1-5a190b29e938 [info] Start Cronjob **map-a-vol** map a volume` diff --git a/docker-entrypoint b/docker-entrypoint index dad29ab..5ae2289 100755 --- a/docker-entrypoint +++ b/docker-entrypoint @@ -159,19 +159,20 @@ function build_crontab() { cat << EOF > ${HOME_DIR}/jobs/${SCRIPT_NAME}.sh #!/usr/bin/env bash set -e -UUID=\$(cat /proc/sys/kernel/random/uuid) -# TODO enable -# [error] write /dev/stdout: broken pipe <- when getting echo from docker stdout + +# TODO find workaround +# [error] write /dev/stdout: broken pipe <- when using docker commands +#UUID=\$(cat /proc/sys/kernel/random/uuid) #exec > >(read message; echo "\$(date -Iseconds) \${UUID} [info] \$message" | tee -a ${LOG_FILE} ) #exec 2> >(read message; echo "\$(date -Iseconds) \${UUID} [error] \$message" | tee -a ${LOG_FILE} >&2) - echo "Start Cronjob **${SCRIPT_NAME}** ${COMMENT}" $(make_cmd "$(jq -c .[$i] ${CONFIG})") - -echo "End Cronjob **${SCRIPT_NAME}** ${COMMENT}" EOF + + + if [ "$(jq -r .[$i].trigger ${CONFIG})" != "null" ]; then while read j ; do if [ "$(jq .[$i].trigger[$j].command ${CONFIG})" == "null" ]; then @@ -184,6 +185,8 @@ EOF done < <(jq -r '.['$i'].trigger|keys[]' ${CONFIG}) fi + echo "echo \"End Cronjob **${SCRIPT_NAME}** ${COMMENT}\"" >> ${HOME_DIR}/jobs/${SCRIPT_NAME}.sh + echo "${SCHEDULE} ${COMMAND}" >> ${CRONTAB_FILE} if [ "$(jq -r .[$i].onstart ${CONFIG})" == "true" ]; then diff --git a/test b/test new file mode 100755 index 0000000..2f24e30 --- /dev/null +++ b/test @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -e + +LOG_FILE=./jobs.log +touch ${LOG_FILE} +UUID="xxxxxxxxxxxxxxxxx" + +exec > >(read message; echo "$(date) ${UUID} [info] $message" | tee -a ${LOG_FILE} ) +exec 2> >(read message; echo "$(date) ${UUID} [error] $message" | tee -a ${LOG_FILE} >&2) + +echo "Start" + +docker run alpine sh -c 'while :; do echo "ping"; sleep 1; done' +# [error] write /dev/stdout: broken pipe + +echo "End"