diff --git a/ansible/roles/configure-nfs-client/tasks/main.yml b/ansible/roles/configure-nfs-client/tasks/main.yml index aab11b1..5d78f3f 100644 --- a/ansible/roles/configure-nfs-client/tasks/main.yml +++ b/ansible/roles/configure-nfs-client/tasks/main.yml @@ -6,7 +6,7 @@ - nfs-common when: ansible_os_family == "Debian" -- name: create mount point +- name: create /storage mount point become: true ansible.builtin.file: path: /storage @@ -14,6 +14,14 @@ mode: "0755" when: ansible_os_family == "Debian" +- name: create /oldstorage mount directory + become: true + ansible.builtin.file: + path: /oldstorage + state: directory + mode: "0755" + when: ansible_os_family == "Debian" + - name: add nfs entry to fstab become: true ansible.builtin.lineinfile: @@ -23,6 +31,7 @@ create: yes with_items: - "10.10.0.7:/storage /storage nfs defaults 0 0" + - "192.168.0.150:/zbackup /oldstorage nfs defaults 0 0" - name: mount nfs become: true diff --git a/fixperms.sh b/fixperms.sh index ff4cfbc..4dc8ef2 100644 --- a/fixperms.sh +++ b/fixperms.sh @@ -1,6 +1,6 @@ #!/bin/bash -sudo chown -R root:nomad ./jobs +sudo chown -R root:nomad ./ sudo find . -type d -exec chmod 775 {} \; diff --git a/jobs/games/minecraft.hcl b/jobs/games/minecraft.hcl index f09e1c1..8cd5cac 100644 --- a/jobs/games/minecraft.hcl +++ b/jobs/games/minecraft.hcl @@ -31,16 +31,16 @@ job "minecraft" { resources { cpu = 3000 # 3000 MHz - memory = 8192 # 8gb + memory = 8192 # 8GB } env { EULA = "TRUE" TYPE = "PAPER" ICON = "https://docs.redbrick.dcu.ie/assets/logo.png" - MEMORY = "6G" USE_AIKAR_FLAGS=true MOTD = "LONG LIVE THE REDBRICK" + MAX_PLAYERS = "20" } } } @@ -76,111 +76,63 @@ job "minecraft" { } resources { - cpu = 7000 # 7000 MHz - memory = 17408 # 17GB + cpu = 3000 # 3000 MHz + memory = 8192 # 8GB } env { EULA = "TRUE" TYPE = "PURPUR" VERSION = "1.20.1" - MOTD = "DCU Games Minecraft Server" + MOTD = "DCU Games Soc Minecraft Server" USE_AIKAR_FLAGS=true OPS = "" + MAX_PLAYERS = "20" } } } - - group "fugitives-mc" { + group "olim909-mc" { count = 1 network { - port "mc-fugitives-port" { - static = 25566 - to = 25565 - } - - port "mc-fugitives-rcon" { - to = 25575 - } - } - - service { - name = "fugitives-mc" - } - - task "minecraft-fugitives" { - driver = "docker" - - config { - image = "itzg/minecraft-server" - ports = ["mc-fugitives-port","mc-fugitives-rcon"] - } - - resources { - cpu = 3000 # 3000 MHz - memory = 8168 # 8gb - } - - env { - EULA = "TRUE" - MEMORY = "6G" - USE_AIKAR_FLAGS=true - } - } - } - - group "shemek-mc" { - count = 1 - - network { - port "mc-shemek-port" { + port "mc-olim909-port" { static = 25568 to = 25565 } - port "mc-shemek-rcon" { + port "mc-olim909-rcon" { to = 25575 } } service { - name = "shemek-mc" + name = "olim909-mc" } - task "minecraft-shemek" { + task "minecraft-olim909" { driver = "docker" config { image = "itzg/minecraft-server" - ports = ["mc-shemek-port","mc-shemek-rcon"] - + ports = ["mc-olim909-port","mc-olim909-rcon"] + volumes = [ "/storage/nomad/${NOMAD_TASK_NAME}:/data" ] } resources { - cpu = 7000 # 7000 MHz - memory = 17408 # 17GB + cpu = 3000 # 3000 MHz + memory = 4096 # 4GB } env { EULA = "TRUE" - TYPE = "FORGE" - VERSION = "1.20.1" - FORGE_INSTALLER = "forge-1.20.1-47.2.19-installer.jar" - OVERRIDE_SERVER_PROPERTIES = "TRUE" - JVM_XX_OPTS = "-Xms12G -Xmx16G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1" + TYPE = "PAPER" + VERSION = "1.20.4" USE_AIKAR_FLAGS=true - MAX_MEMORY = "16G" + OPS = "Olim909" MAX_PLAYERS = "5" - MOTD = "Minecraft ATM 9" - DIFFICULTY = "normal" - SPAWN_PROTECTION = "0" - ENFORCE_WHITELIST = "true" - WHITELIST = "Shmickey02" - OPS = "Shmickey02" } } } diff --git a/jobs/games/gate-proxy.hcl b/jobs/ingress/gate-proxy.hcl similarity index 86% rename from jobs/games/gate-proxy.hcl rename to jobs/ingress/gate-proxy.hcl index 636d379..d78afb0 100644 --- a/jobs/games/gate-proxy.hcl +++ b/jobs/ingress/gate-proxy.hcl @@ -48,12 +48,10 @@ config: lite: enabled: true routes: - - host: fugitives.rb.dcu.ie - backend: fugitives-mc.service.consul:25566 - host: mc.rb.dcu.ie backend: vanilla-mc.service.consul:25567 - - host: shemek.rb.dcu.ie - backend: shemek-mc.service.consul:25568 + - host: olim909.rb.dcu.ie + backend: olim909-mc.service.consul:25568 - host: games.rb.dcu.ie backend: games-mc.service.consul:25569 EOH diff --git a/jobs/traefik.hcl b/jobs/ingress/traefik.hcl similarity index 99% rename from jobs/traefik.hcl rename to jobs/ingress/traefik.hcl index 7074f9c..5a69962 100644 --- a/jobs/traefik.hcl +++ b/jobs/ingress/traefik.hcl @@ -27,7 +27,7 @@ job "traefik" { config { image = "traefik" network_mode = "host" - + volumes = [ "local/traefik.toml:/etc/traefik/traefik.toml", ] diff --git a/jobs/nginx/atlas.hcl b/jobs/nginx/atlas.hcl new file mode 100644 index 0000000..0f1b5a7 --- /dev/null +++ b/jobs/nginx/atlas.hcl @@ -0,0 +1,53 @@ +job "atlas" { + datacenters = ["aperture"] + type = "service" + + meta { + git-sha = "" + } + + group "nginx-atlas" { + count = 1 + + network { + port "http" { + to = 80 + } + } + + service { + port = "http" + + check { + type = "http" + path = "/" + interval = "10s" + timeout = "2s" + } + + tags = [ + "traefik.enable=true", + "traefik.http.routers.nginx-atlas.rule=Host(`redbrick.dcu.ie`) || Host(`rb.dcu.ie`)", + "traefik.http.routers.nginx-atlas.entrypoints=web,websecure", + "traefik.http.routers.nginx-atlas.tls.certresolver=lets-encrypt", + "traefik.http.routers.nginx-atlas.middlewares=redirect-user-web", + "traefik.http.middlewares.redirect-user-web.redirectregex.regex=https://redbrick\\.dcu\\.ie/~([^/]*)/?([^/].*)?", + "traefik.http.middlewares.redirect-user-web.redirectregex.replacement=https://$1.redbrick.dcu.ie/$2", + ] + } + + task "web" { + driver = "docker" + + config { + image = "ghcr.io/redbrick/atlas:latest" + ports = ["http"] + } + + resources { + cpu = 100 + memory = 50 + } + } + } +} diff --git a/jobs/services/api.hcl b/jobs/services/api.hcl new file mode 100644 index 0000000..1015b48 --- /dev/null +++ b/jobs/services/api.hcl @@ -0,0 +1,82 @@ +job "api" { + datacenters = ["aperture"] + + type = "service" + + group "api" { + count = 1 + + network { + port "http" { + to = 80 + } + } + + service { + name = "api" + port = "http" + + check { + type = "http" + path = "/" + interval = "10s" + timeout = "2s" + } + + tags = [ + "traefik.enable=true", + "traefik.http.routers.api.rule=Host(`api.redbrick.dcu.ie`)", + "traefik.http.routers.api.entrypoints=web,websecure", + "traefik.http.routers.api.tls.certresolver=lets-encrypt", + ] + } + + task "api" { + driver = "docker" + + config { + image = "ghcr.io/redbrick/api:latest" + ports = ["http"] + volumes = [ + "/oldstorage:/storage", + "/oldstorage/home:/home", + "local/ldap.secret:/etc/ldap.secret", + ] + auth { + username = "${DOCKER_USER}" + password = "${DOCKER_PASS}" + } + } + template { + destination = "local/.env" + env = true + change_mode = "restart" + data = < "${file}" + +find /storage/backups/nomad/postgres/hedgedoc/postgresql-hedgedoc* -ctime +3 -exec rm {} \; || true + +if [ -s "$file" ]; then # check if file exists and is not empty + echo "Backup successful" + exit 0 +else + rm $file + curl -H "Content-Type: application/json" -d \ + '{"content": "<@&585512338728419341> `PostgreSQL` backup for **'"${job_name}"'** has just **FAILED**\nFile name: `'"$file"'`\nDate: `'"$(TZ=Europe/Dublin date)"'`\nTurn off this script with `nomad job stop '"${job_name}"'` \n\n## Remember to restart this backup job when fixed!!!"}' \ + {{ key "postgres/webhook/discord" }} +fi +EOH + destination = "local/script.sh" + } + } + } +} + diff --git a/jobs/services/hedgedoc.hcl b/jobs/services/hedgedoc.hcl new file mode 100644 index 0000000..18add3d --- /dev/null +++ b/jobs/services/hedgedoc.hcl @@ -0,0 +1,115 @@ +job "hedgedoc" { + datacenters = ["aperture"] + + type = "service" + + group "web" { + network { + # mode = "bridge" + port "http" { + to = 3000 + } + + port "db" { + to = 5432 + } + } + + service { + name = "hedgedoc" + port = "http" + + check { + type = "http" + path = "/" + interval = "10s" + timeout = "2s" + } + + tags = [ + "traefik.frontend.headers.STSSeconds=63072000", + "traefik.frontend.headers.browserXSSFilter=true", + "traefik.frontend.headers.contentTypeNosniff=true", + "traefik.frontend.headers.customResponseHeaders=alt-svc:h2=l3sb47bzhpbelafss42pspxzqo3tipuk6bg7nnbacxdfbz7ao6semtyd.onion:443; ma=2592000", + "traefik.enable=true", + "traefik.port=${NOMAD_PORT_http}", + "traefik.http.routers.md.rule=Host(`md.redbrick.dcu.ie`,`md.rb.dcu.ie`)", + "traefik.http.routers.md.tls=true", + "traefik.http.routers.md.tls.certresolver=lets-encrypt", + ] + } + + task "app" { + driver = "docker" + + constraint { + attribute = "${attr.unique.hostname}" + value = "chell" + } + + config { + image = "quay.io/hedgedoc/hedgedoc:1.6.0" + ports = ["http"] + } + + template { + data = < + + warning + true + + + + + + + + + + + + +EOH + destination = "local/clickhouse.xml" + } + + template { + data = < + + + 0 + 0 + + + +EOH + destination = "local/clickhouse-user-config.xml" + } + + resources { + memory = 800 + } + } + } +} diff --git a/jobs/services/postgres-backup.hcl b/jobs/services/postgres-backup.hcl new file mode 100644 index 0000000..e29964b --- /dev/null +++ b/jobs/services/postgres-backup.hcl @@ -0,0 +1,50 @@ +job "postgres-backup" { + datacenters = ["aperture"] + type = "batch" + + periodic { + crons = ["0 */3 * * * *"] + prohibit_overlap = true + } + + group "db-backup" { + task "postgres-backup" { + driver = "raw_exec" + + config { + command = "/bin/bash" + args = ["local/script.sh"] + } + + template { + data = < "${file}" + +find /storage/backups/nomad/postgres/hedgedoc/postgres* -ctime +3 -exec rm {} \; || true + +if [ -s "$file" ]; then # check if file exists and is not empty + echo "Backup successful" + exit 0 +else + rm $file + curl -H "Content-Type: application/json" -d \ + '{"content": "<@&585512338728419341> `PostgreSQL` backup for **'"${job_name}"'** has just **FAILED**\nFile name: `'"$file"'`\nDate: `'"$(TZ=Europe/Dublin date)"'`\nTurn off this script with `nomad job stop '"${job_name}"'` \n\n## Remember to restart this backup job when fixed!!!"}' \ + {{ key "postgres/webhook/discord" }} +fi +EOH + destination = "local/script.sh" + } + } + } +} + diff --git a/jobs/services/postgres.hcl b/jobs/services/postgres.hcl new file mode 100644 index 0000000..cf861c6 --- /dev/null +++ b/jobs/services/postgres.hcl @@ -0,0 +1,96 @@ +job "postgres" { + datacenters = ["aperture"] + + constraint { + attribute = "${attr.unique.hostname}" + value = "wheatley" + } + + group "db" { + network { + port "db" { + static = 5432 + } + } + + task "postgres-db" { + driver = "docker" + + template { + data = <