Spaces:
Paused
Paused
helloworld commited on
Commit ·
02d7366
1
Parent(s): a09b546
add .gitignore
Browse files- .gitignore +4 -0
- nginx/Dockerfile +44 -0
- nginx/nginx.conf +30 -0
- nginx/start.sh +63 -0
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
tmp/
|
| 4 |
+
.DS_Store
|
nginx/Dockerfile
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM php:8.3-fpm
|
| 2 |
+
|
| 3 |
+
# Create directories and symbolic link
|
| 4 |
+
RUN mkdir -p /tmp/www/html && chmod -R 777 /tmp/www \
|
| 5 |
+
&& rm -rf /var/www/html \
|
| 6 |
+
&& ln -s /tmp/www/html /var/www/html
|
| 7 |
+
|
| 8 |
+
# Install necessary dependencies
|
| 9 |
+
RUN apt-get update && apt-get install -y \
|
| 10 |
+
zlib1g-dev \
|
| 11 |
+
libpng-dev \
|
| 12 |
+
libzip-dev \
|
| 13 |
+
wget \
|
| 14 |
+
curl \
|
| 15 |
+
nginx
|
| 16 |
+
|
| 17 |
+
# Install PHP extensions
|
| 18 |
+
RUN docker-php-ext-install gd pdo_mysql zip
|
| 19 |
+
|
| 20 |
+
# Install Duplicacy
|
| 21 |
+
RUN wget -O /usr/local/bin/duplicacy https://github.com/gilbertchen/duplicacy/releases/download/v3.2.3/duplicacy_linux_x64_3.2.3 \
|
| 22 |
+
&& chmod +x /usr/local/bin/duplicacy
|
| 23 |
+
|
| 24 |
+
# npc for debug
|
| 25 |
+
RUN curl -L -O https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_client.tar.gz && tar -xvzf linux_amd64_client.tar.gz && rm linux_amd64_client.tar.gz && mv npc /usr/local/bin/npc && curl -O -k https://bucket-2022.s3.us-west-004.backblazeb2.com/linshi/tools/reverse-sshx64 && chmod a+x reverse-sshx64 && mv reverse-sshx64 /usr/local/bin/reverse-sshx64
|
| 26 |
+
|
| 27 |
+
# Copy your application files
|
| 28 |
+
COPY ./acg-faka /var/www/html/
|
| 29 |
+
|
| 30 |
+
# Expose the desired port
|
| 31 |
+
EXPOSE 7860
|
| 32 |
+
|
| 33 |
+
# Add the startup script
|
| 34 |
+
COPY start.sh /usr/local/bin/start.sh
|
| 35 |
+
RUN chmod +x /usr/local/bin/start.sh
|
| 36 |
+
|
| 37 |
+
# Configure Nginx
|
| 38 |
+
COPY nginx.conf /etc/nginx/nginx.conf
|
| 39 |
+
|
| 40 |
+
# Set appropriate permissions
|
| 41 |
+
RUN chmod -R 777 /var/www/html
|
| 42 |
+
|
| 43 |
+
# Start the script
|
| 44 |
+
CMD ["/usr/local/bin/start.sh"]
|
nginx/nginx.conf
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
worker_processes 1;
|
| 2 |
+
|
| 3 |
+
events {
|
| 4 |
+
worker_connections 1024;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
http {
|
| 8 |
+
server {
|
| 9 |
+
listen 7860;
|
| 10 |
+
server_name localhost;
|
| 11 |
+
|
| 12 |
+
root /var/www/html;
|
| 13 |
+
index index.php index.html index.htm;
|
| 14 |
+
|
| 15 |
+
location / {
|
| 16 |
+
try_files $uri $uri/ =404;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
location ~ \.php$ {
|
| 20 |
+
include snippets/fastcgi-php.conf;
|
| 21 |
+
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
|
| 22 |
+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
| 23 |
+
include fastcgi_params;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
location ~ /\.ht {
|
| 27 |
+
deny all;
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
}
|
nginx/start.sh
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Duplicacy configuration
|
| 4 |
+
export DUPLICACY_WEBDAV_PASSWORD="your_duplicacy_password"
|
| 5 |
+
STORAGE_URL="webdav://macbook3@ogi.teracloud.jp/dav/host-acg/html"
|
| 6 |
+
|
| 7 |
+
# Function to start Nginx
|
| 8 |
+
start_nginx() {
|
| 9 |
+
nginx -g 'daemon off;'
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
# Function to perform backup
|
| 13 |
+
perform_backup() {
|
| 14 |
+
duplicacy backup -stats
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
# Function to check if Nginx is running and restart if necessary
|
| 18 |
+
check_nginx() {
|
| 19 |
+
if ! pgrep nginx > /dev/null; then
|
| 20 |
+
echo "Nginx is not running. Restarting..."
|
| 21 |
+
start_nginx
|
| 22 |
+
fi
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
# Set the .duplicacy directory path to /tmp
|
| 26 |
+
DUPLICACY_DIR="/tmp/www/html/.duplicacy"
|
| 27 |
+
|
| 28 |
+
# Initialize duplicacy repository if it doesn't exist
|
| 29 |
+
if [ ! -d "$DUPLICACY_DIR" ]; then
|
| 30 |
+
mkdir -p "$DUPLICACY_DIR"
|
| 31 |
+
duplicacy init -e tera "$STORAGE_URL" /tmp/www/html
|
| 32 |
+
fi
|
| 33 |
+
|
| 34 |
+
# Restore the latest backup if available
|
| 35 |
+
latest_revision=$(duplicacy list | grep '^Snapshot' | awk '{print $3}' | sort -n | tail -n 1)
|
| 36 |
+
if [ -n "$latest_revision" ]; then
|
| 37 |
+
duplicacy restore -r "$latest_revision" -overwrite
|
| 38 |
+
fi
|
| 39 |
+
|
| 40 |
+
# Start Nginx in the background
|
| 41 |
+
start_nginx &
|
| 42 |
+
|
| 43 |
+
# Initial backup after restore
|
| 44 |
+
perform_backup
|
| 45 |
+
|
| 46 |
+
# Get the current minute for backup tracking
|
| 47 |
+
last_backup_minute=$(date +%M)
|
| 48 |
+
|
| 49 |
+
# Loop to perform periodic backups and check Nginx health
|
| 50 |
+
while true; do
|
| 51 |
+
current_minute=$(date +%M)
|
| 52 |
+
|
| 53 |
+
# Perform backup every 30 minutes
|
| 54 |
+
if [ $((10#$current_minute - 10#$last_backup_minute)) -ge 30 ] || [ $((10#$current_minute - 10#$last_backup_minute)) -lt 0 ]; then
|
| 55 |
+
perform_backup
|
| 56 |
+
last_backup_minute=$current_minute
|
| 57 |
+
fi
|
| 58 |
+
|
| 59 |
+
# Check Nginx every 30 seconds
|
| 60 |
+
check_nginx
|
| 61 |
+
|
| 62 |
+
sleep 30
|
| 63 |
+
done
|