Initial commit

This commit is contained in:
Ryan 2023-05-08 17:57:52 +00:00
commit 194457e662
8 changed files with 171 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
www/*

19
Dockerfile Normal file
View File

@ -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

50
app/runonce Executable file
View File

@ -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 <tag> <cmd>\n";
}
my $file = "$pidpath/$tag";
for(;;) {
if(-e $file) {
open(IN, $file) || die "Unable to read $file: $!\n";
my $pid=<IN>;
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);

19
app/update_rsr_images Executable file
View File

@ -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

22
crontab Normal file
View File

@ -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

43
default.conf Normal file
View File

@ -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;
}
}

4
docker-entrypoint.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
service cron start
nginx -g "daemon off;"

13
start.sh Executable file
View File

@ -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