Skip to content

Commit b370b2c

Browse files
committed
adding supervisord for queue workers
Added supervisord to run the queue worker,. moved php-fpm and nginx to supervisord as well.
1 parent e24abe9 commit b370b2c

File tree

4 files changed

+72
-23
lines changed

4 files changed

+72
-23
lines changed

.dev/docker/README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ This is a ready to use docker image for the panel.
44
## Requirements
55
This docker image requires some additional software to function. The software can either be provided in other containers (see the [docker-compose.yml](docker-compose.yml) as an example) or as existing instances.
66

7-
A mysql database is required. We recommend [this](https://hub.docker.com/_/mariadb/) image if you prefer to run it in a docker container. As a non-containerized option we recommend mariadb.
7+
A mysql database is required. We recommend the stock [MariaDB Image](https://hub.docker.com/_/mariadb/) image if you prefer to run it in a docker container. As a non-containerized option we recommend mariadb.
88

9-
A caching software is required as well. You can choose any of the [supported options](#cache-drivers).
9+
A caching software is required as well. We recommend the stock [Redis Image](https://hub.docker.com/_/redis/) image. You can choose any of the [supported options](#cache-drivers).
1010

11-
You can provide additional settings using a custom `.env` file or by setting the appropriate environment variables.
11+
You can provide additional settings using a custom `.env` file or by setting the appropriate environment variables in the docker-compose file.
1212

1313
## Setup
1414

@@ -32,20 +32,25 @@ Note: If your `APP_URL` starts with `https://` you need to provide an `LETSENCRY
3232
| Variable | Description | Required |
3333
| ------------------- | ------------------------------------------------------------------------------ | -------- |
3434
| `APP_URL` | The URL the panel will be reachable with (including protocol) | yes |
35+
| `APP_TIMEZONE` | The timezone to use for the panel | yes |
3536
| `LETSENCRYPT_EMAIL` | The email used for letsencrypt certificate generation | yes |
3637
| `DB_HOST` | The host of the mysql instance | yes |
3738
| `DB_PORT` | The port of the mysql instance | yes |
3839
| `DB_DATABASE` | The name of the mysql database | yes |
3940
| `DB_USERNAME` | The mysql user | yes |
4041
| `DB_PASSWORD` | The mysql password for the specified user | yes |
4142
| `CACHE_DRIVER` | The cache driver (see [Cache drivers](#cache-drivers) for detais) | yes |
43+
| `SESSION_DRIVER` | | yes |
44+
| `QUEUE_DRIVER` | | yes |
45+
| `REDIS_HOST` | The hostname or IP address of the redis database | yes |
46+
| `REDIS_PASSWORD` | The password used to secure the redis database | maybe |
47+
| `REDIS_PORT` | The port the redis database is using on the host | maybe |
4248
| `MAIL_DRIVER` | The email driver (see [Mail drivers](#mail-drivers) for details) | yes |
4349
| `MAIL_FROM` | The email that should be used as the sender email | yes |
4450
| `MAIL_HOST` | The host of your mail driver instance | maybe |
4551
| `MAIL_PORT` | The port of your mail driver instance | maybe |
4652
| `MAIL_USERNAME` | The username for your mail driver | maybe |
4753
| `MAIL_PASSWORD` | The password for your mail driver | maybe |
48-
| `APP_TIMEZONE` | The timezone to use for the panel | yes |
4954

5055

5156
### Cache drivers
@@ -54,7 +59,9 @@ We recommend redis when using docker as it can be started in a container easily.
5459

5560
| Driver | Description | Required variables |
5661
| -------- | ------------------------------------ | ------------------------------------------------------ |
57-
| redis | | `REDIS_HOST` |
62+
| redis | host where redis is running | `REDIS_HOST` |
63+
| redis | port redis is running on | `REDIS_PORT` |
64+
| redis | redis database password | `REDIS_PASSWORD` |
5865

5966
### Mail drivers
6067
You can choose between different mail drivers according to your needs.
@@ -66,4 +73,4 @@ Every driver requires `MAIL_FROM` to be set.
6673
| mandrill | [Mandrill](http://www.mandrill.com/) | `MAIL_USERNAME` |
6774
| postmark | [Postmark](https://postmarkapp.com/) | `MAIL_USERNAME` |
6875
| mailgun | [Mailgun](https://www.mailgun.com/) | `MAIL_USERNAME`, `MAIL_HOST` |
69-
| smtp | Any SMTP server can be configured | `MAIL_USERNAME`, `MAIL_HOST`, `MAIL_PASSWORD`, `MAIL_PORT` |
76+
| smtp | Any SMTP server can be configured | `MAIL_USERNAME`, `MAIL_HOST`, `MAIL_PASSWORD`, `MAIL_PORT` |

.dev/docker/entrypoint.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@ do
3434
done
3535

3636
## make sure the db is set up
37-
php artisan migrate --seed --force
37+
echo -e "Migrating and Seeding DB"
38+
php artisan migrate --force
39+
php artisan db:seed --force
3840

39-
echo -e "Done\n"
41+
## start cronjobs for the queue
42+
echo -e "Starting cron jobs"
43+
crond
4044

41-
## start php-fpm in the background
42-
echo -e "Starting php-fpm in the background. \n"
43-
php-fpm7 -D
44-
echo -e "php-fpm started \n"
45-
46-
## start webserver
47-
echo -e "Starting nginx in the foreground. \n"
48-
nginx -g 'pid /tmp/nginx.pid; daemon off;'
45+
echo -e "Starting supervisord"
46+
exec "$@"

.dev/docker/supervisord.conf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[unix_http_server]
2+
file=/tmp/supervisor.sock ; path to your socket file
3+
4+
[supervisord]
5+
logfile=/var/log/supervisord/supervisord.log ; supervisord log file
6+
logfile_maxbytes=50MB ; maximum size of logfile before rotation
7+
logfile_backups=2 ; number of backed up logfiles
8+
loglevel=error ; info, debug, warn, trace
9+
pidfile=/var/run/supervisord.pid ; pidfile location
10+
nodaemon=false ; run supervisord as a daemon
11+
minfds=1024 ; number of startup file descriptors
12+
minprocs=200 ; number of process descriptors
13+
user=root ; default user
14+
childlogdir=/var/log/supervisord/ ; where child log files will live
15+
16+
[rpcinterface:supervisor]
17+
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
18+
19+
[supervisorctl]
20+
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
21+
22+
[program:php-fpm]
23+
command=/usr/sbin/php-fpm7 -F
24+
autostart=true
25+
autorestart=true
26+
27+
[program:queue-worker]
28+
command=/usr/bin/php /app/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3
29+
user=nginx
30+
autostart=true
31+
autorestart=true
32+
33+
[program:nginx]
34+
command=/usr/sbin/nginx -g 'daemon off;'
35+
autostart=true
36+
autorestart=true
37+
priority=10
38+
stdout_events_enabled=true
39+
stderr_events_enabled=true

Dockerfile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@ FROM alpine:3.8
22

33
WORKDIR /app
44

5-
RUN apk add --no-cache --update ca-certificates certbot nginx dcron curl tini php7 php7-bcmath php7-common php7-dom php7-fpm php7-gd php7-mbstring php7-openssl php7-zip php7-pdo php7-phar php7-json php7-pdo_mysql php7-session php7-ctype php7-tokenizer php7-zlib php7-simplexml \
5+
RUN apk add --no-cache --update ca-certificates certbot nginx dcron curl tini php7 php7-bcmath php7-common php7-dom php7-fpm php7-gd php7-mbstring php7-openssl php7-zip php7-pdo php7-phar php7-json php7-pdo_mysql php7-session php7-ctype php7-tokenizer php7-zlib php7-simplexml supervisor \
66
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
77

88
COPY . ./
99

10+
RUN cp .env.example .env \
11+
&& composer install --no-dev --optimize-autoloader \
12+
&& rm .env \
13+
&& chown -R nginx:nginx . && chmod -R 777 storage/* bootstrap/cache
14+
1015
RUN cp .dev/docker/default.conf /etc/nginx/conf.d/default.conf \
1116
&& cp .dev/docker/www.conf /etc/php7/php-fpm.d/www.conf \
12-
&& mkdir /var/run/php \
13-
&& cp .env.example .env \
14-
&& composer install --no-dev --optimize-autoloader \
15-
&& rm .env
17+
&& cat .dev/docker/supervisord.conf > /etc/supervisord.conf \
18+
&& echo "* * * * * /usr/bin/php /app/pterodactyl/artisan schedule:run >> /dev/null 2>&1" >> /var/spool/cron/crontabs/root \
19+
&& mkdir -p /var/run/php /var/run/nginx \
20+
&& mkdir -p /var/log/supervisord/
1621

1722
EXPOSE 80 443
1823

19-
RUN chown -R nginx:nginx . && chmod -R 777 storage/* bootstrap/cache
24+
ENTRYPOINT ["/bin/ash", ".dev/docker/entrypoint.sh"]
2025

21-
ENTRYPOINT ["ash", ".dev/docker/entrypoint.sh"]
26+
CMD [ "supervisord", "-n", "-c", "/etc/supervisord.conf" ]

0 commit comments

Comments
 (0)