Skip to content

Instantly share code, notes, and snippets.

@Platypuschan
Forked from Jip-Hop/boot.sh
Created October 24, 2022 22:09
Show Gist options
  • Select an option

  • Save Platypuschan/3352d76f35d1265b04fade6099bbda59 to your computer and use it in GitHub Desktop.

Select an option

Save Platypuschan/3352d76f35d1265b04fade6099bbda59 to your computer and use it in GitHub Desktop.

Revisions

  1. @Jip-Hop Jip-Hop revised this gist Oct 15, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion boot.sh
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@
    #
    # For these changes to persist after SCALE reboots and upgrades, run the script at start-up
    # Schedule this script to run via System Settings -> Advanced -> Init/Shutdown Scripts
    # Click Add -> Type: Script and choose this script -> When: choose to run as Post Init
    # Click Add -> Type: Script and choose this script -> When: choose to run as Pre Init

    ## set the path to your docker directory and specify the zvol
    docker_directory='/mnt/data/_docker'
    @@ -36,6 +36,7 @@ grep -q 'docker-zvol-ext4' /etc/fstab || {
    ## HEREDOC: docker/daemon.json
    read -r -d '' JSON << END_JSON
    {
    "storage-driver": "overlay2",
    "data-root": "${docker_directory}",
    "exec-opts": [
    "native.cgroupdriver=cgroupfs"
  2. @Jip-Hop Jip-Hop revised this gist Oct 15, 2022. 1 changed file with 71 additions and 16 deletions.
    87 changes: 71 additions & 16 deletions boot.sh
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,76 @@
    #!/usr/bin/env bash

    # Using Docker on TrueNAS SCALE (no Kubernetes)
    #
    # Don't setup Apps via the TrueNAS Web GUI (don't choose a pool for Apps when asked)
    # Make a dedicated docker dataset on one of your data pools
    # Store this script somewhere else on your pool (not in the Docker dataset)
    # Make a daemon.json file in the same directory with the following contents:
    # {"data-root": "/mnt/path/to/desired/docker/dataset/", "exec-opts": ["native.cgroupdriver=cgroupfs"]}
    # Then schedule this script to start via System Settings -> Advanced -> Init/Shutdown Scripts -> Add:
    # Choose Type: Script and choose this script, choose to run at Pre Init under When
    #
    # Now install e.g. Portainer to manage your containers
    #
    # Enable docker and docker-compose on TrueNAS SCALE (no Kubernetes)
    #
    # This script is a hack! Use it at your own risk!!
    # Using this script to enable Docker is NOT SUPPORTED by ix-systems!
    # You CANNOT use SCALE Apps while using this script!
    #
    # 1 Create a dedicated Docker zvol on one of your zpools: zfs create -V 100G data/_docker
    # 2 Create an ext4 filesystem on your new zvol: mkfs.ext4 /dev/zvol/data/_docker
    # 3 Create a directory where you can mount the ext4 filesystem: mkdir /mnt/data/_docker
    # 4 Save this script somewhere else on your zpool, not in the Docker dataset
    # 5 Edit line 24 and 25 of the script, set paths to the Docker directory and zvol you created
    # 7 If this is NOT the first time you run this script (updating to new location/zvol):
    # - Check the contents of /etc/fstab, and remove the old # docker-zvol-ext4 rule if it's there
    # 6 You can now start Docker by running the script from the SCALE console
    #
    # For these changes to persist after SCALE reboots and upgrades, run the script at start-up
    # Schedule this script to run via System Settings -> Advanced -> Init/Shutdown Scripts
    # Click Add -> Type: Script and choose this script -> When: choose to run as Post Init

    SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
    ## set the path to your docker directory and specify the zvol
    docker_directory='/mnt/data/_docker'
    docker_zvol='/dev/zvol/data/_docker'

    # Setup custom Docker config (overwrite if contents changed due to system update)
    cmp --silent "${SCRIPT_DIR}/daemon.json" /etc/docker/daemon.json || echo "Updating Docker config..." && cp "${SCRIPT_DIR}/daemon.json" /etc/docker/daemon.json
    ## this part will add a new fstab rule, if the fstab file doesn't contain our special docker-zvol-ext4 comment
    ## if this is not the first time you run this script, our special comment is already there
    ## so if you ever change the docker_directory and docker_zvol paths in the future, also remove the old
    ## fstab rule and comment from /etc/fstab
    grep -q 'docker-zvol-ext4' /etc/fstab || {
    printf "# docker-zvol-ext4\n${docker_zvol} ${docker_directory} ext4 rw,relatime,stripe=4 0 0\n" >> /etc/fstab
    mount "${docker_directory}" && echo 'Mounted docker directory'
    }

    echo "Starting Docker"
    systemctl start docker
    ## HEREDOC: docker/daemon.json
    read -r -d '' JSON << END_JSON
    {
    "data-root": "${docker_directory}",
    "exec-opts": [
    "native.cgroupdriver=cgroupfs"
    ]
    }
    END_JSON

    ## path to docker daemon file
    docker_daemon='/etc/docker/daemon.json'

    if [ ${EUID} -ne 0 ]; then
    echo "Please run this script as root or using sudo"
    elif [ "$(systemctl is-enabled k3s)" == "enabled" ]; then
    echo "You can not use this script while k3s is enabled"
    elif [ "$(systemctl is-active k3s)" == "active" ]; then
    echo "You can not use this script while k3s is active"
    elif ! which docker &> /dev/null; then
    echo "Docker executable not found"
    elif ! chmod +x /usr/bin/docker-compose &> /dev/null; then
    echo "Failed to make docker-compose executable"
    elif ! install -d -m 755 -- /etc/docker &> /dev/null; then
    echo "Failed to install directory: /etc/docker"
    elif [ ! -d "${docker_directory}" ] ; then
    echo "Directory not found: ${docker_directory}"
    else
    echo "Checking file: ${docker_daemon}"
    if test "${JSON}" != "$(cat ${docker_daemon} 2> /dev/null)"; then
    echo "Updating file: ${docker_daemon}"
    jq -n "${JSON}" > ${docker_daemon}
    if [ "$(systemctl is-active docker)" == "active" ]; then
    echo "Restarting Docker"
    systemctl restart docker
    elif [ "$(systemctl is-enabled docker)" != "enabled" ]; then
    echo "Enable and starting Docker"
    systemctl enable --now docker
    fi
    fi
    fi
  3. @Jip-Hop Jip-Hop revised this gist Feb 4, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion boot.sh
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    # Don't setup Apps via the TrueNAS Web GUI (don't choose a pool for Apps when asked)
    # Make a dedicated docker dataset on one of your data pools
    # Store this script somewhere else on your pool (not in the Docker dataset)
    # Make a daeomon.json file in the same directory with the following contents:
    # Make a daemon.json file in the same directory with the following contents:
    # {"data-root": "/mnt/path/to/desired/docker/dataset/", "exec-opts": ["native.cgroupdriver=cgroupfs"]}
    # Then schedule this script to start via System Settings -> Advanced -> Init/Shutdown Scripts -> Add:
    # Choose Type: Script and choose this script, choose to run at Pre Init under When
  4. @Jip-Hop Jip-Hop created this gist Jun 8, 2021.
    21 changes: 21 additions & 0 deletions boot.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/usr/bin/env bash

    # Using Docker on TrueNAS SCALE (no Kubernetes)
    #
    # Don't setup Apps via the TrueNAS Web GUI (don't choose a pool for Apps when asked)
    # Make a dedicated docker dataset on one of your data pools
    # Store this script somewhere else on your pool (not in the Docker dataset)
    # Make a daeomon.json file in the same directory with the following contents:
    # {"data-root": "/mnt/path/to/desired/docker/dataset/", "exec-opts": ["native.cgroupdriver=cgroupfs"]}
    # Then schedule this script to start via System Settings -> Advanced -> Init/Shutdown Scripts -> Add:
    # Choose Type: Script and choose this script, choose to run at Pre Init under When
    #
    # Now install e.g. Portainer to manage your containers

    SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

    # Setup custom Docker config (overwrite if contents changed due to system update)
    cmp --silent "${SCRIPT_DIR}/daemon.json" /etc/docker/daemon.json || echo "Updating Docker config..." && cp "${SCRIPT_DIR}/daemon.json" /etc/docker/daemon.json

    echo "Starting Docker"
    systemctl start docker