diff --git a/.travis.yml b/.travis.yml index e6e5b1f..daffaf2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ language: shell branches: only: - - - #replace variables, omit brackets + - universal-cron #replace variables, omit brackets services: - docker @@ -12,8 +12,8 @@ services: env: global: - DOCKERHUB="linuxserver/mods" #don't modify - - BASEIMAGE="baseimagename" #replace - - MODNAME="modname" #replace + - BASEIMAGE="universal" #replace + - MODNAME="cron" #replace jobs: include: @@ -32,4 +32,4 @@ jobs: - echo $DOCKERPASS | docker login -u $DOCKERUSER --password-stdin # Push all of the tags - docker push ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${TRAVIS_COMMIT} - - docker push ${DOCKERHUB}:${BASEIMAGE}-${MODNAME} \ No newline at end of file + - docker push ${DOCKERHUB}:${BASEIMAGE}-${MODNAME} diff --git a/Dockerfile b/Dockerfile index 4ece5e8..482658a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM scratch -LABEL maintainer="username" +LABEL maintainer="nemchik" # copy local files COPY root/ / diff --git a/Dockerfile.complex b/Dockerfile.complex deleted file mode 100644 index 4463d83..0000000 --- a/Dockerfile.complex +++ /dev/null @@ -1,21 +0,0 @@ -## Buildstage ## -FROM lsiobase/alpine:3.9 as buildstage - -RUN \ - echo "**** install packages ****" && \ - apk add --no-cache \ - curl && \ - echo "**** grab rclone ****" && \ - mkdir -p /root-layer && \ - curl -o \ - /root-layer/rclone.deb -L \ - "https://downloads.rclone.org/v1.47.0/rclone-v1.47.0-linux-amd64.deb" - -# copy local files -COPY root/ /root-layer/ - -## Single layer deployed image ## -FROM scratch - -# Add files from buildstage -COPY --from=buildstage /root-layer/ / diff --git a/README.md b/README.md index 62f203f..9f66e62 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,19 @@ -# Rsync - Docker mod for openssh-server +# cron - Docker mod for any container -This mod adds rsync to openssh-server, to be installed/updated during container start. +This mod adds cron to any container, to be installed/updated during container start. -In openssh-server docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:openssh-server-rsync` +In any container docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:universal-cron` -If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:openssh-server-rsync|linuxserver/mods:openssh-server-mod2` +If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:universal-cron|linuxserver/mods:universal-mod2` -# Mod creation instructions +This mod will ensure you have a `/config/crontabs/root` file where you can add cron jobs to run inside the container. -* Fork the repo, create a new branch based on the branch `template`. -* Edit the `Dockerfile` for the mod. `Dockerfile.complex` is only an example and included for reference; it should be deleted when done. -* Inspect the `root` folder contents. Edit, add and remove as necessary. -* Edit this readme with pertinent info, delete these instructions. -* Finally edit the `travis.yml`. Customize the build branch, and the vars for `BASEIMAGE` and `MODNAME`. -* Ask the team to create a new branch named `-`. Baseimage should be the name of the image the mod will be applied to. The new branch will be based on the `template` branch. -* Submit PR against the branch created by the team. +No cron jobs (aside from what may be included in the base OS) are included by default. + +You can test to confirm things are working by adding the following line to `/config/crontabs/root` + +```cron +*/5 * * * * /bin/echo test >> /config/tmp.txt +``` + +Then restart the container and wait 5 minutes to see that the test completes. Remove the test and restart the container after confirming. diff --git a/root/defaults/crontabs-mod/abc b/root/defaults/crontabs-mod/abc new file mode 100644 index 0000000..b5e283c --- /dev/null +++ b/root/defaults/crontabs-mod/abc @@ -0,0 +1 @@ +# min hour day month weekday command diff --git a/root/defaults/crontabs-mod/root b/root/defaults/crontabs-mod/root new file mode 100644 index 0000000..b5e283c --- /dev/null +++ b/root/defaults/crontabs-mod/root @@ -0,0 +1 @@ +# min hour day month weekday command diff --git a/root/etc/cont-init.d/95-cron b/root/etc/cont-init.d/95-cron new file mode 100644 index 0000000..a5e7f26 --- /dev/null +++ b/root/etc/cont-init.d/95-cron @@ -0,0 +1,42 @@ +#!/usr/bin/with-contenv bash + +# determine if setup is needed for ubuntu +if [ ! -f /usr/sbin/cron ] && \ +[ -f /usr/bin/apt ]; then + # install cron + apt-get update + apt-get install --no-install-recommends -y \ + cron +fi + +# make folders +mkdir -p \ + /config/crontabs + +# if root crontabs do not exist in config +# copy root crontab from system +if [[ ! -f /config/crontabs/root ]] && \ +crontab -l -u root; then + crontab -l -u root > /config/crontabs/root +fi + +# if root crontabs still do not exist in config (were not copied from system) +# copy root crontab from included defaults +[[ ! -f /config/crontabs/root ]] && \ + cp /defaults/crontabs-mod/root /config/crontabs/ + +# if abc crontabs do not exist in config +# copy abc crontab from system +if [[ ! -f /config/crontabs/abc ]] && \ +crontab -l -u abc; then + crontab -l -u abc > /config/crontabs/abc +fi + +# if abc crontabs still do not exist in config (were not copied from system) +# copy abc crontab from included defaults +[[ ! -f /config/crontabs/abc ]] && \ + cp /defaults/crontabs-mod/abc /config/crontabs/ + +# import user crontabs +crontab -u root /config/crontabs/root +crontab -u abc /config/crontabs/abc diff --git a/root/etc/cont-init.d/98-vpn-config b/root/etc/cont-init.d/98-vpn-config deleted file mode 100644 index a5f9127..0000000 --- a/root/etc/cont-init.d/98-vpn-config +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/with-contenv bash - -# Determine if setup is needed -if [ ! -f /usr/local/lib/python***/dist-packages/sshuttle ] && \ -[ -f /usr/bin/apt ]; then - ## Ubuntu - apt-get update - apt-get install --no-install-recommends -y \ - iptables \ - openssh-client \ - python3 \ - python3-pip - pip3 install sshuttle -fi -if [ ! -f /usr/lib/python***/site-packages/sshuttle ] && \ -[ -f /sbin/apk ]; then - # Alpine - apk add --no-cache \ - iptables \ - openssh \ - py3-pip \ - python3 - pip3 install sshuttle -fi - -chown -R root:root /root -chmod -R 600 /root/.ssh diff --git a/root/etc/services.d/cron/run b/root/etc/services.d/cron/run new file mode 100644 index 0000000..e12085b --- /dev/null +++ b/root/etc/services.d/cron/run @@ -0,0 +1,10 @@ +#!/usr/bin/with-contenv bash + +if [ -f /usr/bin/apt ]; then + # ubuntu + exec /usr/sbin/cron -f -L 1 +fi +if [ -f /sbin/apk ]; then + # alpine + exec /usr/sbin/crond -f -S -l 5 +fi diff --git a/root/etc/services.d/sshvpn/run b/root/etc/services.d/sshvpn/run deleted file mode 100644 index 7d49e79..0000000 --- a/root/etc/services.d/sshvpn/run +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/with-contenv bash - -sshuttle --dns --remote root@${HOST}:${PORT} 0/0 -x 172.17.0.0/16