1 # KISSmo Perl Docker Setup 2 3 This guide provides instructions on how to build and run the KISSmo Perl pastebin application using Docker, including automatic updates of the Git repository every 20 days. 4 5 ## Table of Contents 6 7 - [Features](#features "null") 8 9 - [Prerequisites](#prerequisites "null") 10 11 - [Files Needed](#files-needed "null") 12 13 - [Building the Docker Image](#building-the-docker-image "null") 14 15 - [Running the Docker Container](#running-the-docker-container "null") 16 17 - [Accessing the Application](#accessing-the-application "null") 18 19 - [Automatic Updates](#automatic-updates "null") 20 21 - [Checking Logs](#checking-logs "null") 22 23 - [Stopping and Removing the Container](#stopping-and-removing-the-container "null") 24 25 26 ## Features 27 28 - **Containerized Environment**: Runs KISSmo Perl in an isolated Docker container. 29 30 - **Automatic Dependency Management**: All Perl modules and system dependencies are installed automatically during image build. 31 32 - **Persistent Data**: The SQLite database and paste files are created inside the container. 33 34 - **Port Exposure**: Easily accessible via a defined port on your host machine. 35 36 - **Automatic Git Updates**: The application's source code is automatically pulled from the Git repository and the application restarted every 20 days (specifically, on the 1st and 21st of each month). 37 38 39 ## Prerequisites 40 41 Before you begin, ensure you have: 42 43 - **Docker installed**: You can download Docker Desktop (for Windows/macOS) or install Docker Engine (for Linux) from the [official Docker website](https://docs.docker.com/get-docker/ "null"). 44 45 46 ## Files Needed 47 48 You need to create three files in a dedicated directory for your Docker project: 49 50 1. `Dockerfile` 51 52 2. `update_kissmo.sh` 53 54 3. `entrypoint.sh` 55 56 57 **`Dockerfile` Content:** 58 59 ``` 60 # Use the Debian base image 61 FROM debian:stable-slim 62 63 # Set environment variables to prevent interactive prompts during apt operations 64 ENV DEBIAN_FRONTEND=noninteractive 65 66 # Install necessary packages: 67 # git: for cloning and updating the repository 68 # libmojolicious-perl, libdbi-perl, libfile-slurp-perl, libdbd-sqlite3-perl: Perl modules required by KISSmo Perl 69 # ca-certificates: essential for SSL certificate verification during git clone 70 # cron: for scheduling periodic updates and restarts 71 RUN apt update && \ 72 apt install -y --no-install-recommends \ 73 git \ 74 libmojolicious-perl \ 75 libdbi-perl \ 76 libfile-slurp-perl \ 77 libdbd-sqlite3-perl \ 78 ca-certificates \ 79 cron && \ 80 # Ensure CA certificates are up-to-date 81 update-ca-certificates && \ 82 # Clean up apt cache to reduce image size 83 rm -rf /var/lib/apt/lists/* 84 85 # Clone the KISSmo Perl repository into the /app directory 86 RUN git clone https://git.hax.al/KISSmoPerl/ /app 87 88 # Set the working directory for subsequent commands 89 WORKDIR /app 90 91 # Create the SQLite database file and the 'pastes' directory 92 # These are required by the KISSmo Perl application for data storage 93 RUN touch pastes.db && mkdir pastes 94 95 # Copy the update script into the container and make it executable 96 # This script will handle git pull and restarting the perl application 97 COPY update_kissmo.sh /usr/local/bin/update_kissmo.sh 98 RUN chmod +x /usr/local/bin/update_kissmo.sh 99 100 # Add the cron job to run the update script 101 # The job is scheduled to run at midnight (00:00) on the 1st and 21st day of every month. 102 # Output from the script will be logged to /var/log/cron.log 103 RUN (crontab -l 2>/dev/null; echo "0 0 1,21 * * /usr/local/bin/update_kissmo.sh >> /var/log/cron.log 2>&1") | crontab - 104 105 # Copy the entrypoint script and make it executable 106 COPY entrypoint.sh /usr/local/bin/entrypoint.sh 107 RUN chmod +x /usr/local/bin/entrypoint.sh 108 109 # Expose port 7878, which is the port KISSmo Perl listens on 110 EXPOSE 7878 111 112 # Use the exec form for CMD, pointing to the entrypoint script 113 CMD ["/usr/local/bin/entrypoint.sh"] 114 115 ``` 116 117 **`update_kissmo.sh` Content:** 118 119 ``` 120 #!/bin/bash 121 # Script to update the KISSmo Perl repository and restart the application 122 123 # Navigate to the application directory. Exit if the directory is not found. 124 cd /app || { echo "$(date): Error: /app directory not found. Aborting update." >> /var/log/cron.log; exit 1; } 125 126 echo "$(date): Starting KISSmo Perl update..." >> /var/log/cron.log 127 128 # Pull the latest changes from the Git repository 129 git pull 130 if [ $? -ne 0 ]; then 131 echo "$(date): Git pull failed. Aborting update." >> /var/log/cron.log 132 exit 1 133 fi 134 echo "$(date): Git repository updated successfully." >> /var/log/cron.log 135 136 # Find the PID of the running KISSmo Perl process and kill it. 137 # We use 'pgrep -f' to match the full command line of the perl process. 138 PIDS=$(pgrep -f "perl paste.pl daemon -m production -l http://0.0.0.0:7878") 139 if [ -n "$PIDS" ]; then 140 echo "$(date): Found running KISSmo Perl processes: $PIDS. Killing them..." >> /var/log/cron.log 141 kill $PIDS 142 # Give the process some time to shut down gracefully 143 sleep 5 144 else 145 echo "$(date): No running KISSmo Perl processes found to kill." >> /var/log/cron.log 146 fi 147 148 # Start the application again in daemon mode 149 echo "$(date): Restarting KISSmo Perl application..." >> /var/log/cron.log 150 perl paste.pl daemon -m production -l http://0.0.0.0:7878 151 if [ $? -ne 0 ]; then 152 echo "$(date): Failed to restart KISSmo Perl application." >> /var/log/cron.log 153 exit 1 154 fi 155 echo "$(date): KISSmo Perl restarted successfully." >> /var/log/cron.log 156 ``` 157 158 **`entrypoint.sh` Content:** 159 160 ``` 161 #!/bin/bash 162 163 # Start cron 164 echo "$(date): Starting cron service..." 165 service cron start 166 167 # Start the KISSmo Perl application in daemon mode 168 echo "$(date): Starting KISSmo Perl application..." 169 perl paste.pl daemon -m production -l http://0.0.0.0:7878 170 171 # Keep the container running indefinitely 172 echo "$(date): Tail -f /dev/null to keep container alive..." 173 tail -f /dev/null 174 ``` 175 176 ## Building the Docker Image 177 178 1. **Navigate to your project directory**: Open your terminal or command prompt and go to the directory where you saved the three files (`Dockerfile`, `update_kissmo.sh`, `entrypoint.sh`). 179 180 ``` 181 cd /path/to/your/kissmo-docker-project 182 ``` 183 184 2. **Build the Docker image**: Run the following command. This will download the base Debian image, install dependencies, clone the KISSmo Perl repository, and set up the cron job. 185 186 ``` 187 docker build -t kissmoperl-auto-update . 188 189 ``` 190 191 - `-t kissmoperl-auto-update`: Tags the image with the name `kissmoperl-auto-update`. You can choose any name you prefer. 192 193 - `.`: Specifies that the Dockerfile is in the current directory. 194 195 196 ## Running the Docker Container 197 198 Once the image is built, you can run a container from it: 199 200 ``` 201 docker run -d -p 7878:7878 --name kissmo_autoupdate_app kissmoperl-auto-update 202 203 ``` 204 205 - `-d`: Runs the container in detached mode (in the background). 206 207 - `-p 7878:7878`: Maps port `7878` on your host machine to port `7878` inside the container. This is the port KISSmo Perl listens on. 208 209 - `--name kissmo_autoupdate_app`: Assigns a convenient name to your running container. 210 211 - `kissmoperl-auto-update`: The name of the Docker image you built. 212 213 214 ## Accessing the Application 215 216 After the container starts, open your web browser and navigate to: 217 218 ``` 219 http://localhost:7878 220 ``` 221 222 If you are running Docker on a remote server, replace `localhost` with the actual IP address or hostname of your server. 223 224 ## Automatic Updates 225 226 The Docker container is configured to automatically update the KISSmo Perl application from its Git repository and restart it. 227 228 - **Schedule**: The update script (`update_kissmo.sh`) is executed by `cron` at **00:00 (midnight) on the 1st and 21st day of every month**. This provides an approximate "every 20 days" update cycle. 229 230 - **Process**: 231 232 1. The script navigates to the `/app` directory. 233 234 2. It performs a `git pull` to fetch the latest changes. 235 236 3. It finds and kills any running `perl paste.pl` processes. 237 238 4. It restarts the `perl paste.pl` application in daemon mode. 239 240 241 ## Checking Logs 242 243 You can monitor the cron job's activity and the application's startup by checking the container logs: 244 245 1. **View cron job logs**: 246 247 ``` 248 docker exec kissmo_autoupdate_app cat /var/log/cron.log 249 ``` 250 251 2. **View container startup logs**: 252 253 ``` 254 docker logs kissmo_autoupdate_app 255 ``` 256 257 258 ## Stopping and Removing the Container 259 260 To stop and remove the running container: 261 262 1. **Stop the container**: 263 264 ``` 265 docker stop kissmo_autoupdate_app 266 ``` 267 268 2. **Remove the container**: 269 270 ``` 271 docker rm kissmo_autoupdate_app 272 ``` 273 274 275 To remove the Docker image from your system (optional, after stopping and removing all containers based on it): 276 277 ``` 278 docker rmi kissmoperl-auto-update 279 ``` 280 281 This README provides all the necessary information to deploy and manage your KISSmo Perl application using Docker with automatic updates. 282 283 284 285 Or simply use the ready image: 286 287 https://hub.docker.com/r/savagedot/kissmo 288 289 ``` 290 docker pull savagedot/kissmo 291 292 docker run -d -p 7878:7878 --name kissmoperl savagedot/kissmo 293 ```