65 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HCL
		
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HCL
		
	
	
	
job "hybrid-nfs-app" {
 | 
						||
  datacenters = ["dc1"]
 | 
						||
  type = "service"
 | 
						||
 | 
						||
  # 使用约束条件区分存储类型
 | 
						||
  constraint {
 | 
						||
    attribute = "${attr.unique.hostname}"
 | 
						||
    operator  = "regexp"
 | 
						||
    value     = "semaphore"
 | 
						||
  }
 | 
						||
 | 
						||
  group "app" {
 | 
						||
    count = 1
 | 
						||
 | 
						||
    network {
 | 
						||
      port "http" {
 | 
						||
        static = 8080
 | 
						||
      }
 | 
						||
    }
 | 
						||
 | 
						||
    # 对于本机(semaphore)使用host volume
 | 
						||
    volume "local-storage" {
 | 
						||
      type      = "host"
 | 
						||
      read_only = false
 | 
						||
      source    = "local-fnsync"
 | 
						||
    }
 | 
						||
 | 
						||
    task "web-app" {
 | 
						||
      driver = "exec"
 | 
						||
 | 
						||
      config {
 | 
						||
        command = "python3"
 | 
						||
        args    = ["-m", "http.server", "8080", "--directory", "local/fnsync"]
 | 
						||
      }
 | 
						||
 | 
						||
      template {
 | 
						||
        data = <<EOH
 | 
						||
<h1>Hybrid NFS App - Running on {{ env "attr.unique.hostname" }}</h1>
 | 
						||
<p>Storage Type: {{ with eq (env "attr.unique.hostname") "semaphore" }}PVE Mount{{ else }}NFS{{ end }}</p>
 | 
						||
<p>Timestamp: {{ now | date "2006-01-02 15:04:05" }}</p>
 | 
						||
EOH
 | 
						||
        destination = "local/fnsync/index.html"
 | 
						||
      }
 | 
						||
 | 
						||
      resources {
 | 
						||
        cpu    = 100
 | 
						||
        memory = 128
 | 
						||
      }
 | 
						||
 | 
						||
      service {
 | 
						||
        name = "hybrid-nfs-app"
 | 
						||
        port = "http"
 | 
						||
        
 | 
						||
        tags = ["hybrid", "nfs", "web"]
 | 
						||
        
 | 
						||
        check {
 | 
						||
          type     = "http"
 | 
						||
          path     = "/"
 | 
						||
          interval = "10s"
 | 
						||
          timeout  = "2s"
 | 
						||
        }
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
} |