diff --git a/Makefile b/Makefile index 9cc2ff2..03ccce2 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,9 @@ export HTTPD_EXPOSE_PORT export PLACKUP export CMD +# mt-watcher container +export PERL_FNS_NO_OPT + # override variables ENV_FILE=.env diff --git a/mt/mt-watcher.pl b/mt/mt-watcher.pl new file mode 100755 index 0000000..7b63f24 --- /dev/null +++ b/mt/mt-watcher.pl @@ -0,0 +1,40 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Cwd qw(getcwd); +use Filesys::Notify::Simple; + +if ( $ENV{DISABLE_MT_WATCHER} ) { + warn('mt-watcher container is disbled.'); + exit; +} + +# wait for `make me` to complete +sleep(5); + +my $mt_home = $ENV{MT_HOME} || getcwd(); +$mt_home =~ s{/+$}{}; # remove trailing slash + +my @files = ( map( {"$mt_home/$_"} qw(addons extlib lib plugins) ), glob("$mt_home/*.cgi") ); +my $watcher = Filesys::Notify::Simple->new( \@files ); +while (1) { + $watcher->wait( + sub { + my @paths = grep { + + # exclude files other than "*.cgi" at the top level + $_ =~ m{$mt_home/(?:[^/]+\.cgi|.*?/)}; + } map { $_->{path} } @_; + + return unless @paths; + + print( join( "\n", @paths ) . "\n" ); + system('docker kill -s HUP mt_mt_1'); + + # throttling + sleep(1); + } + ); +} diff --git a/mt/mt-watcher/Dockerfile b/mt/mt-watcher/Dockerfile new file mode 100644 index 0000000..455ef24 --- /dev/null +++ b/mt/mt-watcher/Dockerfile @@ -0,0 +1,18 @@ +FROM perl:5.34 + +ENV DOCKER_VERSION=20.10.7 + +## docker +RUN set -ex \ + \ + && mkdir /tmp/docker \ + && cd /tmp/docker \ + && curl -sL https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz -o docker.tgz \ + && tar zxf docker.tgz \ + && mv docker/docker /usr/bin/docker \ + && rm -fr /tmp/docker + +## cpan libraries +RUN set -ex \ + \ + && cpanm Filesys::Notify::Simple Linux::Inotify2 diff --git a/mt/plackup-mt b/mt/plackup-mt index 0bc5f09..ee4e50c 100755 --- a/mt/plackup-mt +++ b/mt/plackup-mt @@ -1,7 +1,5 @@ #!/bin/bash -reload_options="`ls *.cgi | sed -e 's/^/-R /'` `ls mt-static | grep -v support | sed -e 's/^/-R mt-static\//'`" - exec starman \ -MCGI \ -MFile::Spec \ @@ -12,16 +10,8 @@ exec starman \ -MDBI \ -MDBD::mysql \ -MImage::Magick \ - -R addons \ - -R alt-tmpl \ - -R default_templates \ - -R extlib \ - -R lib \ - -R php \ - -R plugins \ - -R search_templates \ - -R themes \ - -R tmpl \ - -R tools \ - $reload_options \ + -E production \ + --port=80 \ + --workers=2 \ + --pid=$MT_PID_FILE_PATH \ "$@" diff --git a/mt/psgi.yml b/mt/psgi.yml index d2b4904..a538afa 100644 --- a/mt/psgi.yml +++ b/mt/psgi.yml @@ -2,6 +2,20 @@ version: "3" services: mt: restart: always - command: "${PLACKUP:-/usr/local/lib/mt/bin/plackup-mt -E production -L Shotgun --port=80 --workers=2 --pid=/tmp/mt.psgi.pid} /var/www/cgi-bin/mt/mt.psgi" + command: "${PLACKUP:-/usr/local/lib/mt/bin/plackup-mt} /var/www/cgi-bin/mt/mt.psgi" + environment: + MT_PID_FILE_PATH: ${MT_PID_FILE_PATH:-/tmp/mt.psgi.pid} volumes: - "./plackup-mt:/usr/local/lib/mt/bin/plackup-mt" + mt-watcher: + build: + context: mt-watcher + working_dir: /var/www/cgi-bin/mt + command: /usr/local/lib/mt/bin/mt-watcher.pl + environment: + PERL_FNS_NO_OPT: ${PERL_FNS_NO_OPT:-0} + DISABLE_MT_WATCHER: ${DISABLE_MT_WATCHER:-0} + volumes: + - "${MT_HOME_PATH:-../../movabletype}:/var/www/cgi-bin/mt" + - "./mt-watcher.pl:/usr/local/lib/mt/bin/mt-watcher.pl" + - /var/run/docker.sock:/var/run/docker.sock