From 194457e6620337035ac11ff4b31a50c982552e73 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 8 May 2023 17:57:52 +0000 Subject: [PATCH] Initial commit --- .gitignore | 1 + Dockerfile | 19 ++++++++++++++++ app/runonce | 50 +++++++++++++++++++++++++++++++++++++++++++ app/update_rsr_images | 19 ++++++++++++++++ crontab | 22 +++++++++++++++++++ default.conf | 43 +++++++++++++++++++++++++++++++++++++ docker-entrypoint.sh | 4 ++++ start.sh | 13 +++++++++++ 8 files changed, 171 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100755 app/runonce create mode 100755 app/update_rsr_images create mode 100644 crontab create mode 100644 default.conf create mode 100755 docker-entrypoint.sh create mode 100755 start.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f07a8de --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +www/* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c73fb54 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM nginx + +ENV WEBROOT /var/www +ENV RSR_FTP_HOST ftps://ftps.rsrgroup.com +ENV RSR_USER 46554 +ENV RSR_PASS 1XXXR3Ea + + +RUN apt update && apt install -y \ + cron \ + lftp \ + vim + +ADD app /opt/app +COPY crontab /etc/crontab +COPY default.conf /etc/nginx/conf.d/default.conf +COPY docker-entrypoint.sh /start.sh + +CMD /start.sh \ No newline at end of file diff --git a/app/runonce b/app/runonce new file mode 100755 index 0000000..0207e31 --- /dev/null +++ b/app/runonce @@ -0,0 +1,50 @@ +#!/usr/bin/perl +use strict; +use File::Path qw/make_path/; + +my $pidpath = '/tmp/runonce_pid'; + +if(!-d $pidpath) { + make_path($pidpath) || die "Unable to create $pidpath: $!\n"; + chmod(0777, $pidpath) || die "Unable to chmod $pidpath: $!\n"; +} + +my $waitmode=0; +if(lc($ARGV[0]) eq '-w') { + $waitmode=1; + shift(@ARGV); +} + +my($tag,@cmd)=@ARGV; +if(!$tag || !@cmd) { + die "Usage: $0 \n"; +} + +my $file = "$pidpath/$tag"; +for(;;) { + if(-e $file) { + open(IN, $file) || die "Unable to read $file: $!\n"; + my $pid=; + close(IN); + chomp($pid); + + if(kill(0, $pid)) { + print "$pid is alive\n"; + exit(0) unless($waitmode); + sleep(1); + } else { + last; + } + } else { + last; + } +} + +open(OUT, ">", $file) || die "Unable to write $file: $!\n"; +print OUT $$; +close(OUT); + +my $res=system(@cmd); + +unlink($file) || die "Unable to unlink $file: $!\n"; +exit($res); \ No newline at end of file diff --git a/app/update_rsr_images b/app/update_rsr_images new file mode 100755 index 0000000..9ec5cab --- /dev/null +++ b/app/update_rsr_images @@ -0,0 +1,19 @@ +#!/bin/bash + +export SUBDIRS="ftp_images ftp_highres_images" +export HOST + +for d in $SUBDIRS +do + export LOCALDIR="$WEBROOT/images/$d" + export REMOTEDIR="/$d/rsr_number" + + echo "Copy '$RSR_FTP_HOST:$REMOTEDIR' to '$LOCALDIR'" + lftp -c "set ftp:ssl-auth TLS; + open ftp://$RSR_USER:$RSR_PASS@ftps.rsrgroup.com:2222; + mirror --verbose --only-missing $REMOTEDIR $LOCALDIR" + +done + + +find $WEBROOT/images | perl -pe 's/^\/var\/www//' | sort > $WEBROOT/images.txt \ No newline at end of file diff --git a/crontab b/crontab new file mode 100644 index 0000000..fa2de3f --- /dev/null +++ b/crontab @@ -0,0 +1,22 @@ +# /etc/crontab: system-wide crontab +# Unlike any other crontab you don't have to run the `crontab' +# command to install the new version when you edit this file +# and files in /etc/cron.d. These files also have username fields, +# that none of the other crontabs do. + +SHELL=/bin/sh +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + +# Example of job definition: +# .---------------- minute (0 - 59) +# | .------------- hour (0 - 23) +# | | .---------- day of month (1 - 31) +# | | | .------- month (1 - 12) OR jan,feb,mar,apr ... +# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat +# | | | | | +# * * * * * user-name command to be executed +17 * * * * root cd / && run-parts --report /etc/cron.hourly +25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) +47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) +52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) +0 */6 * * * root /opt/app/runonce UPDATE_RSR_IMAGES /opt/app/update_rsr_images > /root/update_rsr_images.log diff --git a/default.conf b/default.conf new file mode 100644 index 0000000..a3523b3 --- /dev/null +++ b/default.conf @@ -0,0 +1,43 @@ +server { + listen 80; + server_name localhost; + + access_log /var/log/nginx/host.access.log main; + + location / { + root /var/www; + index index.html index.htm; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + location ~ /\.ht { + deny all; + } +} \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..15f027a --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +service cron start +nginx -g "daemon off;" \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..740f842 --- /dev/null +++ b/start.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +docker stop statictrm +docker rm statictrm + +docker build -t statictrm . + +docker run -d --name=statictrm \ + -v $PWD/www:/var/www \ + -e TZ=America/New_York \ + -p 10080:80 \ + --restart=unless-stopped \ + statictrm