From 6f1cfcdcbcd1b55aafc86dfbca5c75a5f26b6141 Mon Sep 17 00:00:00 2001 From: Wilton Rodrigues Date: Thu, 4 Nov 2021 13:56:22 -0300 Subject: [PATCH] Add Support for Cron - Resolves #65 --- 2.9/Dockerfile | 7 ++++++- 2.9/docker-compose.yml | 23 ++++++++++++++++++++--- 2.9/scripts/cron.sh | 24 ++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100755 2.9/scripts/cron.sh diff --git a/2.9/Dockerfile b/2.9/Dockerfile index 621725f..391600f 100644 --- a/2.9/Dockerfile +++ b/2.9/Dockerfile @@ -23,6 +23,7 @@ RUN yum ${YUM_FLAGS} install wget \ yum-utils \ tar \ make \ + crontabs \ yum ${YUM_FLAGS} install epel-release ; \ wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm ; \ wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm ; \ @@ -63,6 +64,10 @@ RUN yum ${YUM_FLAGS} install wget \ php73-php-zip \ php73-php-opcache ; +# https://wiki.ocsinventory-ng.org/03.Basic-documentation/Understanding-OCS-Crontab/ +RUN mkdir -p /var/spool/cron; \ + echo '*/30 * * * * cd /usr/share/ocsinventory-reports/ocsreports/crontab; for cron in $(ls cron*.php); do date --iso-8601=s; echo "Executing cron: ${cron}"; /usr/bin/php73 ${cron}; done' > /var/spool/cron/apache + RUN wget https://github.com/OCSInventory-NG/OCSInventory-ocsreports/releases/download/${OCS_VERSION}/OCSNG_UNIX_SERVER-${OCS_VERSION}.tar.gz -P /tmp && \ tar xzf /tmp/OCSNG_UNIX_SERVER-${OCS_VERSION}.tar.gz -C /tmp; @@ -82,7 +87,7 @@ RUN sed -ri \ "/etc/httpd/conf/httpd.conf" COPY conf/ /tmp/conf -COPY ./scripts/docker-entrypoint.sh /usr/bin/docker-entrypoint.sh +COPY ./scripts/*.sh /usr/bin/ EXPOSE 80 443 diff --git a/2.9/docker-compose.yml b/2.9/docker-compose.yml index bd3b12b..0f6cb79 100644 --- a/2.9/docker-compose.yml +++ b/2.9/docker-compose.yml @@ -25,7 +25,7 @@ services: networks: - localocs depends_on: - - ocsdb + - ocsdb ocsdb : image : mysql:5.7 @@ -43,7 +43,24 @@ services: MYSQL_DATABASE : ocsweb networks: - localocs - + + ocscron: + image: ocsinventory/ocsinventory-docker-image:2.9 + container_name : ocsinventory-cron + restart: always + command: /usr/bin/cron.sh + environment: + OCS_DB_SERVER: ocsinventory-db + OCS_DB_USER: ocsuser + OCS_DB_PASS: ocspass + OCS_DB_NAME: ocsweb + links: + - ocsdb + networks: + - localocs + depends_on: + - ocsdb + networks: localocs: @@ -53,4 +70,4 @@ volumes: varlibdata: httpdconfdata: sqldata: - + diff --git a/2.9/scripts/cron.sh b/2.9/scripts/cron.sh new file mode 100755 index 0000000..89baa28 --- /dev/null +++ b/2.9/scripts/cron.sh @@ -0,0 +1,24 @@ +#!/bin/sh +set -eu + +echo "+------------------------------------------------------------+" +echo "| Starting OCS Inventory Cron Management Docker... |" +echo "+------------------------------------------------------------+" + +exec crond -n -P -x sch + +# Usage: +# crond [options] +# +# Options: +# -h print this message +# -i deamon runs without inotify support +# -m off, or specify prefered client for sending mails +# -n run in foreground +# -p permit any crontab +# -P use PATH="/usr/bin:/bin" +# -c enable clustering support +# -s log into syslog instead of sending mails +# -x print debug information +# +# Debugging flags are: ext,sch,proc,pars,load,misc,test,bit