github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/service/agent.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package service 5 6 import ( 7 "fmt" 8 9 "github.com/juju/errors" 10 "github.com/juju/utils/shell" 11 12 "github.com/juju/juju/juju/osenv" 13 "github.com/juju/juju/service/common" 14 ) 15 16 const ( 17 agentServiceTimeout = 300 // 5 minutes 18 ) 19 20 // AgentConf returns the data that defines an init service config 21 // for the identified agent. 22 func AgentConf(info AgentInfo, renderer shell.Renderer) common.Conf { 23 conf := common.Conf{ 24 Desc: fmt.Sprintf("juju agent for %s", info.name), 25 ExecStart: info.cmd(renderer), 26 Logfile: info.logFile(renderer), 27 Env: osenv.FeatureFlags(), 28 Timeout: agentServiceTimeout, 29 ServiceBinary: info.jujud(renderer), 30 ServiceArgs: info.execArgs(renderer), 31 } 32 33 switch info.Kind { 34 case AgentKindMachine: 35 conf.Limit = map[string]string{ 36 "nofile": "64000", 37 } 38 case AgentKindUnit: 39 conf.Desc = "juju unit agent for " + info.ID 40 } 41 42 return conf 43 } 44 45 // TODO(ericsnow) Eliminate ContainerAgentConf once it is no longer 46 // used in worker/deployer/simple.go. 47 48 // ContainerAgentConf returns the data that defines an init service config 49 // for the identified agent running in a container. 50 func ContainerAgentConf(info AgentInfo, renderer shell.Renderer, containerType string) common.Conf { 51 conf := AgentConf(info, renderer) 52 53 // TODO(thumper): 2013-09-02 bug 1219630 54 // As much as I'd like to remove JujuContainerType now, it is still 55 // needed as MAAS still needs it at this stage, and we can't fix 56 // everything at once. 57 envVars := map[string]string{ 58 osenv.JujuContainerTypeEnvKey: containerType, 59 } 60 osenv.MergeEnvironment(envVars, conf.Env) 61 conf.Env = envVars 62 63 return conf 64 } 65 66 // ShutdownAfterConf builds a service conf that will cause the host to 67 // shut down after the named service stops. 68 func ShutdownAfterConf(serviceName string) (common.Conf, error) { 69 if serviceName == "" { 70 return common.Conf{}, errors.New(`missing "after" service name`) 71 } 72 desc := "juju shutdown job" 73 return shutdownAfterConf(serviceName, desc), nil 74 } 75 76 func shutdownAfterConf(serviceName, desc string) common.Conf { 77 return common.Conf{ 78 Desc: desc, 79 Transient: true, 80 AfterStopped: serviceName, 81 ExecStart: "/sbin/shutdown -h now", 82 } 83 }