Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions mt/mt-watcher.pl
Original file line number Diff line number Diff line change
@@ -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);
}
);
}
18 changes: 18 additions & 0 deletions mt/mt-watcher/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
18 changes: 4 additions & 14 deletions mt/plackup-mt
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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 \
"$@"
16 changes: 15 additions & 1 deletion mt/psgi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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