# KISSmo Perl Docker Setup 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. ## Table of Contents - [Features](#features "null") - [Prerequisites](#prerequisites "null") - [Files Needed](#files-needed "null") - [Building the Docker Image](#building-the-docker-image "null") - [Running the Docker Container](#running-the-docker-container "null") - [Accessing the Application](#accessing-the-application "null") - [Automatic Updates](#automatic-updates "null") - [Checking Logs](#checking-logs "null") - [Stopping and Removing the Container](#stopping-and-removing-the-container "null") ## Features - **Containerized Environment**: Runs KISSmo Perl in an isolated Docker container. - **Automatic Dependency Management**: All Perl modules and system dependencies are installed automatically during image build. - **Persistent Data**: The SQLite database and paste files are created inside the container. - **Port Exposure**: Easily accessible via a defined port on your host machine. - **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). ## Prerequisites Before you begin, ensure you have: - **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"). ## Files Needed You need to create three files in a dedicated directory for your Docker project: 1. `Dockerfile` 2. `update_kissmo.sh` 3. `entrypoint.sh` **`Dockerfile` Content:** ``` # Use the Debian base image FROM debian:stable-slim # Set environment variables to prevent interactive prompts during apt operations ENV DEBIAN_FRONTEND=noninteractive # Install necessary packages: # git: for cloning and updating the repository # libmojolicious-perl, libdbi-perl, libfile-slurp-perl, libdbd-sqlite3-perl: Perl modules required by KISSmo Perl # ca-certificates: essential for SSL certificate verification during git clone # cron: for scheduling periodic updates and restarts RUN apt update && \ apt install -y --no-install-recommends \ git \ libmojolicious-perl \ libdbi-perl \ libfile-slurp-perl \ libdbd-sqlite3-perl \ ca-certificates \ cron && \ # Ensure CA certificates are up-to-date update-ca-certificates && \ # Clean up apt cache to reduce image size rm -rf /var/lib/apt/lists/* # Clone the KISSmo Perl repository into the /app directory RUN git clone https://git.hax.al/KISSmoPerl/ /app # Set the working directory for subsequent commands WORKDIR /app # Create the SQLite database file and the 'pastes' directory # These are required by the KISSmo Perl application for data storage RUN touch pastes.db && mkdir pastes # Copy the update script into the container and make it executable # This script will handle git pull and restarting the perl application COPY update_kissmo.sh /usr/local/bin/update_kissmo.sh RUN chmod +x /usr/local/bin/update_kissmo.sh # Add the cron job to run the update script # The job is scheduled to run at midnight (00:00) on the 1st and 21st day of every month. # Output from the script will be logged to /var/log/cron.log RUN (crontab -l 2>/dev/null; echo "0 0 1,21 * * /usr/local/bin/update_kissmo.sh >> /var/log/cron.log 2>&1") | crontab - # Copy the entrypoint script and make it executable COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh # Expose port 7878, which is the port KISSmo Perl listens on EXPOSE 7878 # Use the exec form for CMD, pointing to the entrypoint script CMD ["/usr/local/bin/entrypoint.sh"] ``` **`update_kissmo.sh` Content:** ``` #!/bin/bash # Script to update the KISSmo Perl repository and restart the application # Navigate to the application directory. Exit if the directory is not found. cd /app || { echo "$(date): Error: /app directory not found. Aborting update." >> /var/log/cron.log; exit 1; } echo "$(date): Starting KISSmo Perl update..." >> /var/log/cron.log # Pull the latest changes from the Git repository git pull if [ $? -ne 0 ]; then echo "$(date): Git pull failed. Aborting update." >> /var/log/cron.log exit 1 fi echo "$(date): Git repository updated successfully." >> /var/log/cron.log # Find the PID of the running KISSmo Perl process and kill it. # We use 'pgrep -f' to match the full command line of the perl process. PIDS=$(pgrep -f "perl paste.pl daemon -m production -l http://0.0.0.0:7878") if [ -n "$PIDS" ]; then echo "$(date): Found running KISSmo Perl processes: $PIDS. Killing them..." >> /var/log/cron.log kill $PIDS # Give the process some time to shut down gracefully sleep 5 else echo "$(date): No running KISSmo Perl processes found to kill." >> /var/log/cron.log fi # Start the application again in daemon mode echo "$(date): Restarting KISSmo Perl application..." >> /var/log/cron.log perl paste.pl daemon -m production -l http://0.0.0.0:7878 if [ $? -ne 0 ]; then echo "$(date): Failed to restart KISSmo Perl application." >> /var/log/cron.log exit 1 fi echo "$(date): KISSmo Perl restarted successfully." >> /var/log/cron.log ``` **`entrypoint.sh` Content:** ``` #!/bin/bash # Start cron echo "$(date): Starting cron service..." service cron start # Start the KISSmo Perl application in daemon mode echo "$(date): Starting KISSmo Perl application..." perl paste.pl daemon -m production -l http://0.0.0.0:7878 # Keep the container running indefinitely echo "$(date): Tail -f /dev/null to keep container alive..." tail -f /dev/null ``` ## Building the Docker Image 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`). ``` cd /path/to/your/kissmo-docker-project ``` 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. ``` docker build -t kissmoperl-auto-update . ``` - `-t kissmoperl-auto-update`: Tags the image with the name `kissmoperl-auto-update`. You can choose any name you prefer. - `.`: Specifies that the Dockerfile is in the current directory. ## Running the Docker Container Once the image is built, you can run a container from it: ``` docker run -d -p 7878:7878 --name kissmo_autoupdate_app kissmoperl-auto-update ``` - `-d`: Runs the container in detached mode (in the background). - `-p 7878:7878`: Maps port `7878` on your host machine to port `7878` inside the container. This is the port KISSmo Perl listens on. - `--name kissmo_autoupdate_app`: Assigns a convenient name to your running container. - `kissmoperl-auto-update`: The name of the Docker image you built. ## Accessing the Application After the container starts, open your web browser and navigate to: ``` http://localhost:7878 ``` If you are running Docker on a remote server, replace `localhost` with the actual IP address or hostname of your server. ## Automatic Updates The Docker container is configured to automatically update the KISSmo Perl application from its Git repository and restart it. - **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. - **Process**: 1. The script navigates to the `/app` directory. 2. It performs a `git pull` to fetch the latest changes. 3. It finds and kills any running `perl paste.pl` processes. 4. It restarts the `perl paste.pl` application in daemon mode. ## Checking Logs You can monitor the cron job's activity and the application's startup by checking the container logs: 1. **View cron job logs**: ``` docker exec kissmo_autoupdate_app cat /var/log/cron.log ``` 2. **View container startup logs**: ``` docker logs kissmo_autoupdate_app ``` ## Stopping and Removing the Container To stop and remove the running container: 1. **Stop the container**: ``` docker stop kissmo_autoupdate_app ``` 2. **Remove the container**: ``` docker rm kissmo_autoupdate_app ``` To remove the Docker image from your system (optional, after stopping and removing all containers based on it): ``` docker rmi kissmoperl-auto-update ``` This README provides all the necessary information to deploy and manage your KISSmo Perl application using Docker with automatic updates. Or simply use the ready image: https://hub.docker.com/r/savagedot/kissmo ``` docker pull savagedot/kissmo docker run -d -p 7878:7878 --name kissmoperl savagedot/kissmo ```