spud/service/service.go

55 lines
1.1 KiB
Go

package service
import (
"log"
podman "spud/podman"
service_definition "spud/service_definition"
)
type PodmanServiceClient struct{}
func (c PodmanServiceClient) Create(definition service_definition.ServiceDefinition) {
CreateService(definition)
}
func (c PodmanServiceClient) Stop(name string) {
StopService(name)
}
func CreateService(definition service_definition.ServiceDefinition) {
var err error
err = podman.CreatePod(definition.Name, definition.Ports)
if err != nil {
log.Fatalf("%s", err)
}
knownVolumes := map[string]string{}
for _, volume := range definition.Volumes {
namespacedName := definition.Name + "_" + volume.Name
podman.CreateVolume(namespacedName, true)
knownVolumes[volume.Name] = namespacedName
}
for _, container := range definition.Containers {
if err = podman.CreateContainer(container, knownVolumes, definition.Name); err != nil {
log.Fatalf("%s", err)
}
}
}
/*
* Stops a running service.
*
* The service and all its containers are stopped but not deleted.
*/
func StopService(name string) {
err := podman.StopPod(name)
if err != nil {
log.Fatalf("%s", err)
}
}