def __init__(self, master=True, data=True): type_name = { (True, True): "node", (True, False): "master", (False, True): "data", (False, False): "client" }[(master, data)] ContainerRunnerUnit.__init__(self, container="crewjam/presence", name="elasticsearch-" + type_name + "-presence", description="elasticsearch presence") self.extra_unit.append( "BindsTo=elasticsearch-{}@%i.service".format(type_name)) self.command = [ "/bin/presence", "--etcd-prefix=/services/elasticsearch/{}".format(type_name), "--etcd=${COREOS_PRIVATE_IPV4}", "--instance=%i", "--host=$(hostname)", "--private-ip=${COREOS_PRIVATE_IPV4}" ] self.x_fleet.append( "X-ConditionMachineOf=elasticsearch-{}@%i.service".format( type_name))
def __init__(self, service_name): self.service_name = service_name self.base_service_name = service_name.split("@")[0] ContainerRunnerUnit.__init__( self, container="crewjam/ambassador", name="elasticsearch-{}-amb".format(self.base_service_name), description="Elasticsearch ambassador for {}".format( self.base_service_name)) self.options.extend(["-p", "9200:9200"]) self.command = [ "/bin/ambassador", "--etcd-prefix=/services/elasticsearch/client", "--etcd=${COREOS_PRIVATE_IPV4}", "--port=9200" ] self.extra_unit.append("Before={}".format(self.service_name)) self.x_fleet.append("X-ConditionMachineOf={}".format( self.service_name)) # Sadly we cannot run on hosts with any of these other things because we # bind to port 9200 just like they do. self.x_fleet.extend([ "X-Conflicts=elasticsearch-client@*.service", "X-Conflicts=elasticsearch-data@*.service", "X-Conflicts=elasticsearch-master@*.service", ])
def __init__(self, service_name): service_name = service_name or "gerrit" PodUnit.__init__(self, service_name=service_name) self.app = ContainerRunnerUnit(container=self.APP_CONTAINER, name=service_name + "-app") self.app.ports.append("8080:8080") self.app.ports.append("29418:29418") self.AddChild(self.app) self.app_presence = PresenceUnit(self.app) self.AddChild(self.app_presence, bind=True) # TODO(ross): what if we need access to multiple postgres instances? We # should use docker --link instead I think, if we can get it to work self.postgres_amb = MasterOnlyAmbassadorUnit( foreign_service_name=service_name + "-db", local_service_name=service_name, port=5432) self.AddChild(self.postgres_amb) self.app.set("Unit", "After", self.postgres_amb.name + "@%i.service") self.app.environment["POSTGRES_SERVER"] = "${COREOS_PRIVATE_IPV4}" self.app.environment["SERVICE_NAME"] = service_name self.data_volume = DataVolumeUnit(volume_name=service_name + "-git", name=service_name + "-data-volume-git") self.AddChild(self.data_volume) self.app.set("Unit", "After", self.data_volume.name + "@%i.service") self.app.volumes.append((self.data_volume.host_path, "/data/git"))
def __init__(self): ContainerRunnerUnit.__init__(self, container="crewjam/chaosmonkey", name="chaosmonkey") self.presence_unit = PresenceUnit(self) self.AddChild(self.presence_unit, bind=True)
def __init__(self, master=True, data=True): type_name = { (True, True): "node", (True, False): "master", (False, True): "data", (False, False): "client" }[(master, data)] ContainerRunnerUnit.__init__(self, container="crewjam/elasticsearch", name="elasticsearch-" + type_name, description="elasticsearch container") self.extra_service.append("EnvironmentFile=/etc/environment") self.command = [ "/main", "--etcd=${COREOS_PRIVATE_IPV4}", "--publish-host=${COREOS_PRIVATE_IPV4}", "--node-name=%H", ] if master: self.command.append("--master-node") if data: self.command.append("--data-node") self.options.extend(["-p", "9200:9200"]) self.options.extend(["-p", "9300:9300"]) if data: self.options.extend(["-v", "/data0:/data0"]) self.options.extend(["-v", "/data1:/data1"]) for type_name_ in ["node", "master", "data", "client"]: self.x_fleet.append( "X-Conflicts=elasticsearch-{}@*.service".format(type_name_))
class GerritFrontendPod(PodUnit): APP_CONTAINER = "crewjam/gerrit" def __init__(self, service_name): service_name = service_name or "gerrit" PodUnit.__init__(self, service_name=service_name) self.app = ContainerRunnerUnit(container=self.APP_CONTAINER, name=service_name + "-app") self.app.ports.append("8080:8080") self.app.ports.append("29418:29418") self.AddChild(self.app) self.app_presence = PresenceUnit(self.app) self.AddChild(self.app_presence, bind=True) # TODO(ross): what if we need access to multiple postgres instances? We # should use docker --link instead I think, if we can get it to work self.postgres_amb = MasterOnlyAmbassadorUnit( foreign_service_name=service_name + "-db", local_service_name=service_name, port=5432) self.AddChild(self.postgres_amb) self.app.set("Unit", "After", self.postgres_amb.name + "@%i.service") self.app.environment["POSTGRES_SERVER"] = "${COREOS_PRIVATE_IPV4}" self.app.environment["SERVICE_NAME"] = service_name self.data_volume = DataVolumeUnit( volume_name=service_name + "-git", name=service_name + "-data-volume-git") self.AddChild(self.data_volume) self.app.set("Unit", "After", self.data_volume.name + "@%i.service") self.app.volumes.append((self.data_volume.host_path, "/data/git"))
def __init__(self): ContainerRunnerUnit.__init__(self, container="crewjam/nginx", name="nginx") self.ports.append("80:80") self.ports.append("443:443") self.ports.append("1022:1022") self.set("X-Fleet", "X-Conflicts", self.name + "@*.service") self.presence_unit = PresenceUnit(self) self.AddChild(self.presence_unit, bind=True)
def __init__(self, unit): name = unit.name + "-presence" ContainerRunnerUnit.__init__(self, container=self.CONTAINER, name=name) self.environment["SERVICE_NAME"] = unit.name self.set("Unit", "After", "{}@%i.service".format(unit.name)) self.set("Unit", "BindsTo", "{}@%i.service".format(unit.name)) self.set("X-Fleet", "X-ConditionMachineOf", "{}@%i.service".format(unit.name))
def Build(options, output): unit = NginxUnit() file(pathjoin(output, unit.name + "@.service"), "w").write(str(unit)) for child_unit in unit.children: file(pathjoin(output, child_unit.name + "@.service"), "w").write( str(child_unit)) dns_unit = ContainerRunnerUnit(container="crewjam/presence-dns", name=unit.name + "-presence-dns") dns_unit.environment["SERVICE_NAME"] = unit.name file(pathjoin(output, dns_unit.name + ".service"), "w").write(str(dns_unit))
def __init__(self, foreign_service_name, local_service_name, port): self.port = port self.foreign_service_name = foreign_service_name self.local_service_name = local_service_name ContainerRunnerUnit.__init__(self, container=self.CONTAINER, name="{}-{}-amb".format(self.foreign_service_name, self.local_service_name)) self.ports.append("{}:{}".format(self.port, self.port)) self.command = self.GetCommand()
def Build(options, output): unit = NginxUnit() file(pathjoin(output, unit.name + "@.service"), "w").write(str(unit)) for child_unit in unit.children: file(pathjoin(output, child_unit.name + "@.service"), "w").write(str(child_unit)) dns_unit = ContainerRunnerUnit(container="crewjam/presence-dns", name=unit.name + "-presence-dns") dns_unit.environment["SERVICE_NAME"] = unit.name file(pathjoin(output, dns_unit.name + ".service"), "w").write(str(dns_unit))
def __init__(self, volume_name, name=None): ContainerRunnerUnit.__init__(self, container=self.CONTAINER, name=name or "data-volume-{}".format(volume_name), description="btsync data volume {}".format(volume_name)) self.host_path = "/data0/{}".format(self.name) self.volumes.append(lambda: "{}:/data".format(self.host_path)) self.environment["VOLUME_NAME"] = volume_name # We rely on having etcd available either via etcd or etcd-amb self.environment["ETCDCTL_PEERS"] = "http://${COREOS_PRIVATE_IPV4}:4001" self.set("Unit", "After", "etcd-amb.service") self.set("Unit", "After", "etcd.service")
def __init__(self, foreign_service_name, local_service_name, port): self.port = port self.foreign_service_name = foreign_service_name self.local_service_name = local_service_name ContainerRunnerUnit.__init__(self, container=self.CONTAINER, name="{}-{}-amb".format( self.foreign_service_name, self.local_service_name)) self.ports.append("{}:{}".format(self.port, self.port)) self.command = self.GetCommand()
def __init__(self, discovery_url): ContainerRunnerUnit.__init__(self, "crewjam/etcd-amb") self.environment["ETCD_DISCOVERY_URL"] = discovery_url # start before fleet self.set("Unit", "Before", "fleet.service") # start after docker self.set("Unit", "After", "docker.service") self.set("Unit", "Wants", "docker.service") # can't be on the same host as etcd self.set("Unit", "Conflicts", "etcd.service") self.ports.append("4001:4001")
def __init__(self, volume_name, name=None): ContainerRunnerUnit.__init__( self, container=self.CONTAINER, name=name or "data-volume-{}".format(volume_name), description="btsync data volume {}".format(volume_name)) self.host_path = "/data0/{}".format(self.name) self.volumes.append(lambda: "{}:/data".format(self.host_path)) self.environment["VOLUME_NAME"] = volume_name # We rely on having etcd available either via etcd or etcd-amb self.environment[ "ETCDCTL_PEERS"] = "http://${COREOS_PRIVATE_IPV4}:4001" self.set("Unit", "After", "etcd-amb.service") self.set("Unit", "After", "etcd.service")
class PostgresPod(PodUnit): APP_CONTAINER = "crewjam/postgres" def __init__(self, name): PodUnit.__init__(self, service_name=name) self.app = ContainerRunnerUnit(container=self.APP_CONTAINER, name=name) self.app.ports.append("${COREOS_PRIVATE_IPV4}:5432:5432") self.app.environment["SERVICE_NAME"] = name self.app.environment["INSTANCE"] = "%i" self.app.environment["PRIVATE_IP"] = "${COREOS_PRIVATE_IPV4}" # We rely on having etcd available either via etcd or etcd-amb self.app.environment[ "ETCDCTL_PEERS"] = "http://${COREOS_PRIVATE_IPV4}:4001" self.app.set("Unit", "After", "etcd-amb.service") self.app.set("Unit", "After", "etcd.service") self.AddChild(self.app) self.data_volume = DataVolumeUnit(volume_name=name, name=name + "-data-volume") self.AddChild(self.data_volume) self.app.set("Unit", "After", self.data_volume.name + "@%i.service") self.app.volumes.append( (self.data_volume.host_path, "/var/lib/postgresql/data"))
class PostgresPod(PodUnit): APP_CONTAINER = "crewjam/postgres" def __init__(self, name): PodUnit.__init__(self, service_name=name) self.app = ContainerRunnerUnit(container=self.APP_CONTAINER, name=name) self.app.ports.append("${COREOS_PRIVATE_IPV4}:5432:5432") self.app.environment["SERVICE_NAME"] = name self.app.environment["INSTANCE"] = "%i" self.app.environment["PRIVATE_IP"] = "${COREOS_PRIVATE_IPV4}" # We rely on having etcd available either via etcd or etcd-amb self.app.environment["ETCDCTL_PEERS"] = "http://${COREOS_PRIVATE_IPV4}:4001" self.app.set("Unit", "After", "etcd-amb.service") self.app.set("Unit", "After", "etcd.service") self.AddChild(self.app) self.data_volume = DataVolumeUnit( volume_name=name, name=name + "-data-volume") self.AddChild(self.data_volume) self.app.set("Unit", "After", self.data_volume.name + "@%i.service") self.app.volumes.append((self.data_volume.host_path, "/var/lib/postgresql/data"))