diff --git a/wikijs/README.txt b/wikijs/README.txt index 663f234..9c7c35c 100644 --- a/wikijs/README.txt +++ b/wikijs/README.txt @@ -2,11 +2,18 @@ Wiki.js Dropshell Template ========================== A modern, lightweight and powerful wiki application built on Node.js. -Uses the LinuxServer.io container image for easy deployment. +Uses Docker Compose with PostgreSQL database for reliability. Source: https://hub.docker.com/r/linuxserver/wikijs Docs: https://docs.linuxserver.io/images/docker-wikijs +Architecture +------------ + +This template runs two containers: + - wikijs: The Wiki.js application (linuxserver/wikijs) + - wikijs_db: PostgreSQL 15 database + Configuration ------------- @@ -19,7 +26,9 @@ HTTP_PORT - Web interface port (default: 3080) PUID - User ID for file permissions (default: 1000) PGID - Group ID for file permissions (default: 1000) TZ - Timezone (default: Pacific/Auckland) -DB_TYPE - Database type: sqlite or postgres (default: sqlite) +DB_NAME - PostgreSQL database name (default: wikijs) +DB_USER - PostgreSQL username (default: wikijs) +DB_PASS - PostgreSQL password (default: changeme) ** CHANGE THIS! ** Ports ----- @@ -30,8 +39,9 @@ Data Storage ------------ All persistent data is stored in DATA_PATH: - - config/ - Wiki.js configuration files - - data/ - Wiki content and database + - config/ - Wiki.js configuration files + - data/ - Wiki.js data and uploads + - postgres/ - PostgreSQL database files First Run --------- @@ -45,30 +55,24 @@ You will be guided through the initial setup wizard to: Database -------- -By default, Wiki.js uses SQLite (DB_TYPE=sqlite) which requires no -additional setup and stores data in DATA_PATH/data/. +PostgreSQL 15 is included and configured automatically. +Database credentials are set in service.env. -For PostgreSQL support, set DB_TYPE=postgres and configure these -additional environment variables in service.env: - DB_HOST - PostgreSQL server hostname - DB_PORT - PostgreSQL server port (default: 5432) - DB_NAME - Database name - DB_USER - Database username - DB_PASS - Database password - -Note: Database settings only apply on first run. After initial setup, -modify DATA_PATH/config/config.yml directly. +IMPORTANT: Change DB_PASS from the default before first install! Backup & Restore ---------------- Use the backup.sh and restore.sh scripts to backup and restore -your wiki data. Backups include all configuration and content. +your wiki data. Backups include: + - Wiki.js configuration + - PostgreSQL database + - Uploaded assets Notes ----- -- The container runs as non-root using PUID/PGID -- Configuration changes after first run should be made through - the Wiki.js admin panel or by editing config/config.yml +- Both containers restart automatically unless stopped +- The database container must be running for Wiki.js to work - SSL/TLS should be handled by a reverse proxy (e.g., Caddy) +- Use 'docker compose logs' to view logs from both containers diff --git a/wikijs/backup.sh b/wikijs/backup.sh index c545f11..a982f86 100755 --- a/wikijs/backup.sh +++ b/wikijs/backup.sh @@ -1,18 +1,21 @@ #!/bin/bash -# shellcheck disable=SC1091 source "${AGENT_PATH}/common.sh" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${SCRIPT_DIR}/_volumes.sh" _check_required_env_vars "CONTAINER_NAME" "DATA_PATH" -# BACKUP SCRIPT -# Creates a backup of the Wiki.js data volume +# Export variables for docker compose +export CONTAINER_NAME DATA_PATH HTTP_PORT PUID PGID TZ IMAGE_TAG DB_NAME DB_USER DB_PASS -_stop_container "$CONTAINER_NAME" +cd "$SCRIPT_DIR" + +# Stop containers for consistent backup +docker compose stop # shellcheck disable=SC2046 backup_items $(get_wikijs_volumes) || _die "Failed to create backup" -_start_container "$CONTAINER_NAME" +# Restart containers +docker compose start echo "Backup created successfully" diff --git a/wikijs/config/.template_info.env b/wikijs/config/.template_info.env index fc7d191..633310c 100644 --- a/wikijs/config/.template_info.env +++ b/wikijs/config/.template_info.env @@ -8,6 +8,6 @@ REQUIRES_HOST_ROOT=false REQUIRES_DOCKER=true REQUIRES_DOCKER_ROOT=false -# Image settings +# Image settings (used by docker-compose.yml) IMAGE_REGISTRY="lscr.io" IMAGE_REPO="linuxserver/wikijs" diff --git a/wikijs/config/service.env b/wikijs/config/service.env index 60b54b8..d9c47f5 100644 --- a/wikijs/config/service.env +++ b/wikijs/config/service.env @@ -1,5 +1,4 @@ # Service settings specific to this server -# (can also override anything in the .template_info.env file in the template to make it specific to this server) CONTAINER_NAME=wikijs IMAGE_TAG="latest" @@ -17,5 +16,7 @@ PUID=1000 PGID=1000 TZ="Pacific/Auckland" -# Database configuration (sqlite requires no external database) -DB_TYPE="sqlite" +# PostgreSQL database settings +DB_NAME="wikijs" +DB_USER="wikijs" +DB_PASS="changeme" diff --git a/wikijs/destroy.sh b/wikijs/destroy.sh index abbc9b1..87ac364 100755 --- a/wikijs/destroy.sh +++ b/wikijs/destroy.sh @@ -1,20 +1,20 @@ #!/bin/bash -# shellcheck disable=SC1091 source "${AGENT_PATH}/common.sh" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "${SCRIPT_DIR}/_volumes.sh" _check_required_env_vars "CONTAINER_NAME" "DATA_PATH" -# DESTROY SCRIPT -# Completely removes the service AND all data -# WARNING: This is irreversible! +# Export variables for docker compose +export CONTAINER_NAME DATA_PATH HTTP_PORT PUID PGID TZ IMAGE_TAG DB_NAME DB_USER DB_PASS echo "WARNING: This will PERMANENTLY DELETE all data for ${CONTAINER_NAME}" -echo "This includes all wiki pages, users, and configuration!" +echo "This includes all wiki pages, users, database, and configuration!" -./uninstall.sh +cd "$SCRIPT_DIR" -# shellcheck disable=SC2046 -destroy_items $(get_wikijs_volumes) || _die "Failed to destroy docker volumes" +# Stop and remove containers +docker compose down -v 2>/dev/null || true + +# Remove data directory +rm -rf "${DATA_PATH}" echo "Destroyed ${CONTAINER_NAME} and all data." diff --git a/wikijs/docker-compose.yml b/wikijs/docker-compose.yml new file mode 100644 index 0000000..4b21a5a --- /dev/null +++ b/wikijs/docker-compose.yml @@ -0,0 +1,33 @@ +services: + db: + image: postgres:15-alpine + container_name: ${CONTAINER_NAME}_db + restart: unless-stopped + environment: + POSTGRES_DB: ${DB_NAME} + POSTGRES_USER: ${DB_USER} + POSTGRES_PASSWORD: ${DB_PASS} + volumes: + - ${DATA_PATH}/postgres:/var/lib/postgresql/data + + wikijs: + image: lscr.io/linuxserver/wikijs:${IMAGE_TAG} + container_name: ${CONTAINER_NAME} + restart: unless-stopped + depends_on: + - db + environment: + - PUID=${PUID} + - PGID=${PGID} + - TZ=${TZ} + - DB_TYPE=postgres + - DB_HOST=${CONTAINER_NAME}_db + - DB_PORT=5432 + - DB_USER=${DB_USER} + - DB_PASS=${DB_PASS} + - DB_NAME=${DB_NAME} + volumes: + - ${DATA_PATH}/config:/config + - ${DATA_PATH}/data:/data + ports: + - "${HTTP_PORT}:3000" diff --git a/wikijs/install.sh b/wikijs/install.sh index 56e6004..49c9be5 100755 --- a/wikijs/install.sh +++ b/wikijs/install.sh @@ -1,19 +1,26 @@ #!/bin/bash -# shellcheck disable=SC1091 source "${AGENT_PATH}/common.sh" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "${SCRIPT_DIR}/_volumes.sh" -_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "DATA_PATH" - -# shellcheck disable=SC2046 -create_items $(get_wikijs_volumes) || _die "Failed to create data directory $DATA_PATH" +_check_required_env_vars "CONTAINER_NAME" "DATA_PATH" _check_docker_installed || _die "Docker test failed, aborting installation..." -docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || _die "Failed to pull image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" +# Create data directories +mkdir -p "${DATA_PATH}/config" "${DATA_PATH}/data" "${DATA_PATH}/postgres" -bash ./stop.sh || _die "Failed to stop container ${CONTAINER_NAME}" -_remove_container "$CONTAINER_NAME" || _die "Failed to remove container ${CONTAINER_NAME}" -bash ./start.sh || _die "Failed to start container ${CONTAINER_NAME}" +# Export variables for docker compose +export CONTAINER_NAME DATA_PATH HTTP_PORT PUID PGID TZ IMAGE_TAG DB_NAME DB_USER DB_PASS + +cd "$SCRIPT_DIR" + +# Pull images +docker compose pull || _die "Failed to pull images" + +# Stop existing containers +docker compose down 2>/dev/null || true + +# Start containers (--build ensures fresh state) +docker compose up -d --build || _die "Failed to start containers" echo "Installation of ${CONTAINER_NAME} complete" +echo "Access Wiki.js at http://localhost:${HTTP_PORT}" diff --git a/wikijs/logs.sh b/wikijs/logs.sh index e64541c..22c7ae1 100755 --- a/wikijs/logs.sh +++ b/wikijs/logs.sh @@ -1,11 +1,14 @@ #!/bin/bash source "${AGENT_PATH}/common.sh" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" _check_required_env_vars "CONTAINER_NAME" -# LOGS SCRIPT -# Shows the container logs +# Export variables for docker compose +export CONTAINER_NAME DATA_PATH HTTP_PORT PUID PGID TZ IMAGE_TAG DB_NAME DB_USER DB_PASS + +cd "$SCRIPT_DIR" echo "Container ${CONTAINER_NAME} logs:" _grey_start -docker logs "${CONTAINER_NAME}" "$@" +docker compose logs "$@" _grey_end diff --git a/wikijs/restore.sh b/wikijs/restore.sh index 145c9b5..927e145 100755 --- a/wikijs/restore.sh +++ b/wikijs/restore.sh @@ -1,15 +1,16 @@ #!/bin/bash -# shellcheck disable=SC1091 source "${AGENT_PATH}/common.sh" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${SCRIPT_DIR}/_volumes.sh" _check_required_env_vars "CONTAINER_NAME" "DATA_PATH" -# RESTORE SCRIPT -# Restores Wiki.js data from a backup +# Export variables for docker compose +export CONTAINER_NAME DATA_PATH HTTP_PORT PUID PGID TZ IMAGE_TAG DB_NAME DB_USER DB_PASS -# Uninstall container before restore -./uninstall.sh || _die "Failed to uninstall service before restore" +cd "$SCRIPT_DIR" + +# Stop containers before restore +docker compose down # Restore data from backup file # shellcheck disable=SC2046 diff --git a/wikijs/ssh.sh b/wikijs/ssh.sh index 5cd6b11..413e29b 100755 --- a/wikijs/ssh.sh +++ b/wikijs/ssh.sh @@ -2,7 +2,5 @@ source "${AGENT_PATH}/common.sh" _check_required_env_vars "CONTAINER_NAME" -# SSH SCRIPT -# Opens a shell inside the container - +# SSH into the wikijs container docker exec -it "${CONTAINER_NAME}" /bin/bash diff --git a/wikijs/start.sh b/wikijs/start.sh index 8dc557d..1d5a316 100755 --- a/wikijs/start.sh +++ b/wikijs/start.sh @@ -1,31 +1,13 @@ #!/bin/bash source "${AGENT_PATH}/common.sh" -_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "DATA_PATH" "HTTP_PORT" "PUID" "PGID" "TZ" "DB_TYPE" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +_check_required_env_vars "CONTAINER_NAME" "DATA_PATH" -# START SCRIPT -# The start script is required for all templates. -# It is used to start the service on the server. +# Export variables for docker compose +export CONTAINER_NAME DATA_PATH HTTP_PORT PUID PGID TZ IMAGE_TAG DB_NAME DB_USER DB_PASS -DOCKER_RUN_CMD="docker run -d \ - --restart unless-stopped \ - --name ${CONTAINER_NAME} \ - -p ${HTTP_PORT}:3000 \ - -v ${DATA_PATH}/config:/config \ - -v ${DATA_PATH}/data:/data \ - -e PUID=${PUID} \ - -e PGID=${PGID} \ - -e TZ=${TZ} \ - -e DB_TYPE=${DB_TYPE} \ - ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}" - -if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then - _die "Failed to start container ${CONTAINER_NAME}" -fi - -# Check if the container is running -if ! _is_container_running "$CONTAINER_NAME"; then - _die "Container ${CONTAINER_NAME} is not running" -fi +cd "$SCRIPT_DIR" +docker compose up -d || _die "Failed to start containers" echo "Container ${CONTAINER_NAME} started" echo "Access Wiki.js at http://localhost:${HTTP_PORT}" diff --git a/wikijs/status.sh b/wikijs/status.sh index b1a13d5..7d0b924 100755 --- a/wikijs/status.sh +++ b/wikijs/status.sh @@ -2,30 +2,13 @@ source "${AGENT_PATH}/common.sh" _check_required_env_vars "CONTAINER_NAME" -# STATUS SCRIPT -# The status script is REQUIRED. -# It is used to return the status of the service. -# Must output exactly one of: Running, Stopped, Error, Unknown - -# Check if container exists -if ! docker ps -a --format "{{.Names}}" | grep -q "^${CONTAINER_NAME}$"; then - echo "Unknown" - exit 0 -fi - -# Check container state -STATE=$(docker inspect -f '{{.State.Status}}' "$CONTAINER_NAME" 2>/dev/null) -case "$STATE" in - running) - echo "Running" - ;; - exited|stopped) +# Check if main wikijs container is running +if docker ps --format "{{.Names}}" | grep -q "^${CONTAINER_NAME}$"; then + echo "Running" +else + if docker ps -a --format "{{.Names}}" | grep -q "^${CONTAINER_NAME}$"; then echo "Stopped" - ;; - restarting|paused) - echo "Error" - ;; - *) + else echo "Unknown" - ;; -esac + fi +fi diff --git a/wikijs/stop.sh b/wikijs/stop.sh index fe3d4df..91bb966 100755 --- a/wikijs/stop.sh +++ b/wikijs/stop.sh @@ -1,11 +1,12 @@ #!/bin/bash source "${AGENT_PATH}/common.sh" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" _check_required_env_vars "CONTAINER_NAME" -# STOP SCRIPT -# The stop script is required for all templates. -# It is used to stop the service on the server. +# Export variables for docker compose +export CONTAINER_NAME DATA_PATH HTTP_PORT PUID PGID TZ IMAGE_TAG DB_NAME DB_USER DB_PASS -_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}" +cd "$SCRIPT_DIR" +docker compose stop || _die "Failed to stop containers" echo "Container ${CONTAINER_NAME} stopped" diff --git a/wikijs/uninstall.sh b/wikijs/uninstall.sh index d948214..550080f 100755 --- a/wikijs/uninstall.sh +++ b/wikijs/uninstall.sh @@ -1,18 +1,18 @@ #!/bin/bash source "${AGENT_PATH}/common.sh" -_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +_check_required_env_vars "CONTAINER_NAME" -# UNINSTALL SCRIPT -# The uninstall script is required for all templates. -# It is used to uninstall the service from the server. -# IMPORTANT: This script MUST preserve data volumes! +# Export variables for docker compose +export CONTAINER_NAME DATA_PATH HTTP_PORT PUID PGID TZ IMAGE_TAG DB_NAME DB_USER DB_PASS -_remove_container "$CONTAINER_NAME" || _die "Failed to remove container ${CONTAINER_NAME}" -_is_container_running "$CONTAINER_NAME" && _die "Couldn't stop existing container" -_is_container_exists "$CONTAINER_NAME" && _die "Couldn't remove existing container" +cd "$SCRIPT_DIR" -# Remove the image -docker rmi "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || echo "Failed to remove image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" +# Stop and remove containers (but preserve volumes/data) +docker compose down || _die "Failed to stop containers" + +# Remove images +docker compose config --images | xargs -r docker rmi 2>/dev/null || true echo "Uninstallation of ${CONTAINER_NAME} complete." -echo "Data volume preserved. To remove all data, use destroy.sh" +echo "Data preserved in ${DATA_PATH}. To remove all data, use destroy.sh"