Skip to content

Commit 2f5593a

Browse files
committed
Merge pull request #5 from devsu/dev2
Dev2
2 parents 872631b + aa85a0c commit 2f5593a

File tree

5 files changed

+91
-9
lines changed

5 files changed

+91
-9
lines changed

Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ WORKDIR /var/www
6161
ADD ./startup.sh /opt/startup.sh
6262
RUN chmod +x /opt/startup.sh
6363

64-
ADD ./cron.sh /opt/cron.sh
65-
RUN chmod +x /opt/cron.sh
66-
6764
RUN mkdir -p /var/cache/nginx/microcache
6865

6966
# Avoid sendmail starting as a service

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ The startup.sh script will add the environment variables with MYSQL_ to /etc/php
7070
*sendmail* usually requires an specific HOSTNAME, run like this:
7171

7272
$ docker run -d -h example.com -v application:/var/www my_mysql_container:mysql devsu/nginx-drupal7
73+
74+
## Drush Cron Support
75+
76+
To specify *cron* schedule you can set the variable `CRON_SCHEDULE` to the desired settings. Like this:
77+
78+
$ docker run -d -e CRON_SCHEDULE="10 * * * *" -v application:/var/www my_mysql_container:mysql devsu/nginx-drupal7
79+
80+
The default value is "*/15 * * * *" (Every fifteen minutes)
7381

7482
## Changes from base image [iiiepe/docker-nginx-drupal](https://github.com/iiiepe/docker-nginx-drupal)
7583

config/supervisor/supervisord-nginx.conf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ nodaemon=true
33

44
[program:sendmail]
55
priority=2
6-
command=/usr/sbin/sendmail -bD
6+
command=/usr/sbin/sendmail -bD -q 5m
77
stdout_logfile=/var/log/supervisor/%(program_name)s.log
88
stderr_logfile=/var/log/supervisor/%(program_name)s.log
99
autorestart=true
@@ -22,3 +22,10 @@ stdout_logfile=/var/log/supervisor/nginx.log
2222
stderr_logfile=/var/log/supervisor/nginx.log
2323
autorestart=true
2424
startretries=100
25+
26+
[program:cron]
27+
priority=3
28+
command=/usr/sbin/cron -f -L 15
29+
stdout_logfile=/var/log/supervisor/%(program_name)s.log
30+
stderr_logfile=/var/log/supervisor/%(program_name)s.log
31+
autorestart=true

cron.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

startup.sh

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
ENV_CONF=/etc/php5/fpm/pool.d/env.conf
44

5+
ENV_CRON=/etc/cron.d/drupal
6+
7+
# Force deletion and creation of new file
8+
rm -f $ENV_CRON
9+
510
echo "Configuring Nginx and PHP5-FPM with environment variables"
611

712
# Update php5-fpm with access to Docker environment variables
@@ -10,6 +15,7 @@ for var in $(env | awk -F= '{print $1}')
1015
do
1116
echo "Adding variable {$var}"
1217
echo "env[${var}] = ${!var}" >> $ENV_CONF
18+
echo "${var}=${!var}" >> $ENV_CRON
1319
done
1420

1521
# We need to configure the /etc/hosts file so sendmail works properly
@@ -35,5 +41,73 @@ echo "ff00::0 ip6-mcastprefix" >> /etc/hosts
3541
echo "ff02::1 ip6-allnodes" >> /etc/hosts
3642
echo "ff02::2 ip6-allrouters" >> /etc/hosts
3743

44+
# Setting up drush cron to run according CRON_SCHEDULE or 15 min by default
45+
if [[ -z $CRON_SCHEDULE ]]; then
46+
CRON_SCHEDULE="*/15 * * * *"
47+
else
48+
echo "CRON setup to user input"
49+
fi
50+
51+
# Checking if the cron is already set up
52+
# Cron job written according http://www.drush.org/en/master/cron/
53+
CRON_JOB="root /usr/bin/env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin COLUMNS=72 /usr/local/bin/drush --root=/var/www cron"
54+
CHECK=$(cat /etc/crontab | grep -o "$CRON_JOB" )
55+
56+
if [[ -z $CHECK ]]; then
57+
echo "$CRON_SCHEDULE $CRON_JOB" >> /etc/cron.d/drupal
58+
echo "$(date "+%Y-%m-%d %H:%M:%S") CRON_JOB set in /etc/crontab" >> /var/log/supervisor/cron.log
59+
else
60+
echo "$(date "+%Y-%m-%d %H:%M:%S") CRON_JOB already created, doing nothing..." >> /var/log/supervisor/cron.log
61+
fi
62+
63+
# Adding .htaccess to sites/default/files/ and /tmp according https://www.drupal.org/SA-CORE-2013-003
64+
65+
FILES_HTACCESS="# Turn off all options we don't need.
66+
Options None
67+
Options +FollowSymLinks
68+
69+
# Set the catch-all handler to prevent scripts from being executed.
70+
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
71+
<Files *>
72+
# Override the handler again if we're run later in the evaluation list.
73+
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003
74+
</Files>
75+
76+
# If we know how to do it safely, disable the PHP engine entirely.
77+
<IfModule mod_php5.c>
78+
php_flag engine off
79+
</IfModule>"
80+
81+
TMP_HTACCESS="# Turn off all options we don't need.
82+
Options None
83+
Options +FollowSymLinks
84+
85+
# Set the catch-all handler to prevent scripts from being executed.
86+
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
87+
<Files *>
88+
# Override the handler again if we're run later in the evaluation list.
89+
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003
90+
</Files>
91+
92+
# If we know how to do it safely, disable the PHP engine entirely.
93+
<IfModule mod_php5.c>
94+
php_flag engine off
95+
</IfModule>
96+
Deny from all"
97+
98+
# Checking files/.htaccess
99+
if [[ -e /var/www/sites/default/files/.htaccess ]]; then
100+
echo "File already exists"
101+
else
102+
echo "$FILES_HTACCESS" > /var/www/sites/default/files/.htaccess
103+
fi
104+
105+
# Checking /tmp/.htaccess
106+
if [[ -e /tmp/.htaccess ]]; then
107+
echo "File already exists"
108+
else
109+
echo "$TMP_HTACCESS" > /tmp/.htaccess
110+
fi
111+
38112
# Runnning supervisor
39-
/usr/bin/supervisord -n
113+
/usr/bin/supervisord -n

0 commit comments

Comments
 (0)