add thecollegeview.ie
This commit is contained in:
		
							parent
							
								
									f3e5ae5e2b
								
							
						
					
					
						commit
						d57a936aa1
					
				
					 2 changed files with 191 additions and 0 deletions
				
			
		
							
								
								
									
										49
									
								
								jobs/socs/mps-thecollegeview-backup.hcl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								jobs/socs/mps-thecollegeview-backup.hcl
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,49 @@
 | 
				
			||||||
 | 
					job "mps-thecollegeview-backup" {
 | 
				
			||||||
 | 
					  datacenters = ["aperture"]
 | 
				
			||||||
 | 
					  type        = "batch"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  periodic {
 | 
				
			||||||
 | 
					    crons            = ["0 */3 * * * *"]
 | 
				
			||||||
 | 
					    prohibit_overlap = true
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  group "db-backup" {
 | 
				
			||||||
 | 
					    task "mysql-backup" {
 | 
				
			||||||
 | 
					      driver = "raw_exec"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      config {
 | 
				
			||||||
 | 
					        command = "/bin/bash"
 | 
				
			||||||
 | 
					        args    = ["local/mysql-backup.sh"]
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      template {
 | 
				
			||||||
 | 
					        data        = <<EOH
 | 
				
			||||||
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					file=/storage/backups/nomad/mps-thecollegeview/mysql/tcv-mysql-$(date +%Y-%m-%d_%H-%M-%S).sql
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					mkdir -p /storage/backups/nomad/mps-thecollegeview/mysql
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					alloc_id=$(nomad job status mps-thecollegeview | grep running | tail -n 1 | cut -d " " -f 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					job_name=$(echo ${NOMAD_JOB_NAME} | cut -d "/" -f 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					nomad alloc exec -task rbwiki-db $alloc_id mariadb-dump -u {{ key "mps/thecollegeview/db/username" }} -p'{{ key "mps/thecollegeview/db/password"}}' {{ key "mps/thecollegeview/db/name" }} > "${file}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					find /storage/backups/nomad/mps-thecollegeview/mysql/tcv-mysql* -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> `MySQL` 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 "mysql/webhook/discord" }}
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					EOH
 | 
				
			||||||
 | 
					        destination = "local/mysql-backup.sh"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										142
									
								
								jobs/socs/mps-thecollegeview.hcl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								jobs/socs/mps-thecollegeview.hcl
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,142 @@
 | 
				
			||||||
 | 
					job "mps-thecollegeview" {
 | 
				
			||||||
 | 
					  datacenters = ["aperture"]
 | 
				
			||||||
 | 
					  type        = "service"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  meta {
 | 
				
			||||||
 | 
					    domain = "thecollegeview.ie"
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  group "tcv" {
 | 
				
			||||||
 | 
					    count = 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    network {
 | 
				
			||||||
 | 
					      mode = "bridge"
 | 
				
			||||||
 | 
					      port "http" {
 | 
				
			||||||
 | 
					        to = 80
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      port "fpm" {
 | 
				
			||||||
 | 
					        to = 9000
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      port "db" {
 | 
				
			||||||
 | 
					        to = 3306
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    service {
 | 
				
			||||||
 | 
					      name = "tcv-web"
 | 
				
			||||||
 | 
					      port = "http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      check {
 | 
				
			||||||
 | 
					        type     = "http"
 | 
				
			||||||
 | 
					        path     = "/"
 | 
				
			||||||
 | 
					        interval = "10s"
 | 
				
			||||||
 | 
					        timeout  = "5s"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      tags = [
 | 
				
			||||||
 | 
					        "traefik.enable=true",
 | 
				
			||||||
 | 
					        "traefik.http.routers.tcv.rule=Host(`${NOMAD_META_domain}`)",
 | 
				
			||||||
 | 
					        "traefik.http.routers.tcv.entrypoints=web,websecure",
 | 
				
			||||||
 | 
					        "traefik.http.routers.tcv.tls.certresolver=lets-encrypt",
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    task "tcv-web" {
 | 
				
			||||||
 | 
					      driver = "docker"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      config {
 | 
				
			||||||
 | 
					        image = "wordpress:php8.3"
 | 
				
			||||||
 | 
					        ports = ["http"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        volumes = [
 | 
				
			||||||
 | 
					          "/storage/nomad/mps-thecollegeview:/var/www/html/",
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      resources {
 | 
				
			||||||
 | 
					        cpu    = 800
 | 
				
			||||||
 | 
					        memory = 500
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      template {
 | 
				
			||||||
 | 
					        data        = <<EOH
 | 
				
			||||||
 | 
					WORDPRESS_DB_HOST={{ env "NOMAD_ADDR_db" }}
 | 
				
			||||||
 | 
					WORDPRESS_DB_USER={{ key "mps/thecollegeview/db/username" }}
 | 
				
			||||||
 | 
					WORDPRESS_DB_PASSWORD={{  key "mps/thecollegeview/db/password" }}
 | 
				
			||||||
 | 
					WORDPRESS_DB_NAME={{ key "mps/thecollegeview/db/name" }}
 | 
				
			||||||
 | 
					WORDPRESS_TABLE_PREFIX=wp_2
 | 
				
			||||||
 | 
					EOH
 | 
				
			||||||
 | 
					        destination = "local/.env"
 | 
				
			||||||
 | 
					        env         = true
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    service {
 | 
				
			||||||
 | 
					      name = "rbwiki-db"
 | 
				
			||||||
 | 
					      port = "db"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      check {
 | 
				
			||||||
 | 
					        name     = "mariadb_probe"
 | 
				
			||||||
 | 
					        type     = "tcp"
 | 
				
			||||||
 | 
					        interval = "10s"
 | 
				
			||||||
 | 
					        timeout  = "2s"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    task "tcv-db" {
 | 
				
			||||||
 | 
					      driver = "docker"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      config {
 | 
				
			||||||
 | 
					        image = "mariadb"
 | 
				
			||||||
 | 
					        ports = ["db"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        volumes = [
 | 
				
			||||||
 | 
					          "/storage/nomad/mps-thecollegeview/db:/var/lib/mysql",
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      template {
 | 
				
			||||||
 | 
					        data = <<EOH
 | 
				
			||||||
 | 
					[mysqld]
 | 
				
			||||||
 | 
					max_connections = 100
 | 
				
			||||||
 | 
					key_buffer_size = 2G
 | 
				
			||||||
 | 
					query_cache_size = 0
 | 
				
			||||||
 | 
					innodb_buffer_pool_size = 6G
 | 
				
			||||||
 | 
					innodb_log_file_size = 512M
 | 
				
			||||||
 | 
					innodb_flush_log_at_trx_commit = 1
 | 
				
			||||||
 | 
					innodb_flush_method = O_DIRECT
 | 
				
			||||||
 | 
					innodb_io_capacity = 200
 | 
				
			||||||
 | 
					tmp_table_size = 5242K
 | 
				
			||||||
 | 
					max_heap_table_size = 5242K
 | 
				
			||||||
 | 
					innodb_log_buffer_size = 16M
 | 
				
			||||||
 | 
					innodb_file_per_table = 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bind-address = 0.0.0.0
 | 
				
			||||||
 | 
					# Logging
 | 
				
			||||||
 | 
					slow_query_log = 1
 | 
				
			||||||
 | 
					slow_query_log_file = /var/log/mysql/slow.log
 | 
				
			||||||
 | 
					long_query_time = 1
 | 
				
			||||||
 | 
					EOH
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        destination = "local/conf.cnf"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      resources {
 | 
				
			||||||
 | 
					        cpu    = 800
 | 
				
			||||||
 | 
					        memory = 800
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      template {
 | 
				
			||||||
 | 
					        data = <<EOH
 | 
				
			||||||
 | 
					MYSQL_DATABASE={{ key "mps/thecollegeview/db/name" }}
 | 
				
			||||||
 | 
					MYSQL_USER={{ key "mps/thecollegeview/db/username" }}
 | 
				
			||||||
 | 
					MYSQL_PASSWORD={{ key "mps/thecollegeview/db/password" }}
 | 
				
			||||||
 | 
					MYSQL_RANDOM_ROOT_PASSWORD=yes
 | 
				
			||||||
 | 
					EOH
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        destination = "local/.env"
 | 
				
			||||||
 | 
					        env         = true
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in a new issue