Skip to content

Commit

Permalink
rkt: add --nuclear-exit flag
Browse files Browse the repository at this point in the history
If activated, an exited app will cause the whole pod to exit.
  • Loading branch information
iaguis committed Sep 21, 2015
1 parent b35b92a commit 07607ad
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions rkt/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ End the image arguments with a lone "---" to resume argument parsing.`,
flagInheritEnv bool
flagExplicitEnv envMap
flagInteractive bool
flagNuclearExit bool
flagNoOverlay bool
flagLocal bool
flagPodManifest string
Expand Down Expand Up @@ -91,6 +92,7 @@ func init() {
cmdRun.Flags().BoolVar(&flagPrivateUsers, "private-users", false, "Run within user namespaces (experimental).")
cmdRun.Flags().Var(&flagExplicitEnv, "set-env", "an environment variable to set for apps in the form name=value")
cmdRun.Flags().BoolVar(&flagInteractive, "interactive", false, "run pod interactively. If true, only one image may be supplied.")
cmdRun.Flags().BoolVar(&flagNuclearExit, "nuclear-exit", false, "make pod exit if an app exits")
cmdRun.Flags().BoolVar(&flagLocal, "local", false, "use only local images (do not discover or download from remote URLs)")
cmdRun.Flags().StringVar(&flagPodManifest, "pod-manifest", "", "the path to the pod manifest. If it's non-empty, then only '--private-net', '--no-overlay' and '--interactive' will have effects")
cmdRun.Flags().BoolVar(&flagMDSRegister, "mds-register", true, "register pod with metadata service")
Expand Down Expand Up @@ -297,6 +299,7 @@ func runRun(cmd *cobra.Command, args []string) (exit int) {
PrivateNet: flagPrivateNet,
LockFd: lfd,
Interactive: flagInteractive,
NuclearExit: flagNuclearExit,
MDSRegister: flagMDSRegister,
LocalConfig: globalFlags.LocalConfigDir,
}
Expand Down
4 changes: 4 additions & 0 deletions stage0/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type RunConfig struct {
PrivateNet common.PrivateNetList // pod should have its own network stack
LockFd int // lock file descriptor
Interactive bool // whether the pod is interactive or not
NuclearExit bool // whether the pod should exit if an app exits or not
MDSRegister bool // whether to register with metadata service or not
Apps schema.AppList // applications (prepare gets them via Apps)
LocalConfig string // Path to local configuration
Expand Down Expand Up @@ -374,6 +375,9 @@ func Run(cfg RunConfig, dir string) {
if cfg.Interactive {
args = append(args, "--interactive")
}
if cfg.NuclearExit {
args = append(args, "--nuclear-exit")
}
if len(privateUsers) > 0 {
args = append(args, "--private-users="+privateUsers)
}
Expand Down
4 changes: 3 additions & 1 deletion stage1/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ var (
debug bool
privNet common.PrivateNetList
interactive bool
nuclearExit bool
privateUsers string
mdsToken string
localhostIP net.IP
Expand All @@ -138,6 +139,7 @@ func init() {
flag.BoolVar(&debug, "debug", false, "Run in debug mode")
flag.Var(&privNet, "private-net", "Setup private network")
flag.BoolVar(&interactive, "interactive", false, "The pod is interactive")
flag.BoolVar(&nuclearExit, "nuclear-exit", false, "The pod should exit if an app exits")
flag.StringVar(&privateUsers, "private-users", "", "Run within user namespace. Can be set to [=UIDBASE[:NUIDS]]")
flag.StringVar(&mdsToken, "mds-token", "", "MDS auth token")
flag.StringVar(&localConfig, "local-config", common.DefaultLocalConfigDir, "Local config path")
Expand Down Expand Up @@ -583,7 +585,7 @@ func stage1() int {
return 2
}

if err = p.PodToSystemd(interactive, flavor, privateUsers); err != nil {
if err = p.PodToSystemd(interactive, nuclearExit, flavor, privateUsers); err != nil {
fmt.Fprintf(os.Stderr, "Failed to configure systemd: %v\n", err)
return 2
}
Expand Down
10 changes: 7 additions & 3 deletions stage1/init/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (p *Pod) writeAppReaper(appName string) error {
}

// appToSystemd transforms the provided RuntimeApp+ImageManifest into systemd units
func (p *Pod) appToSystemd(ra *schema.RuntimeApp, interactive bool, flavor string, privateUsers string) error {
func (p *Pod) appToSystemd(ra *schema.RuntimeApp, interactive bool, nuclearExit bool, flavor string, privateUsers string) error {
app := ra.App
appName := ra.Name
image, ok := p.Images[appName.String()]
Expand Down Expand Up @@ -282,6 +282,10 @@ func (p *Pod) appToSystemd(ra *schema.RuntimeApp, interactive bool, flavor strin
opts = append(opts, unit.NewUnitOption("Service", "SyslogIdentifier", filepath.Base(app.Exec[0])))
}

if nuclearExit {
opts = append(opts, unit.NewUnitOption("Service", "ExecStop", "/usr/bin/systemctl start halt.target"))
}

for _, eh := range app.EventHandlers {
var typ string
switch eh.Name {
Expand Down Expand Up @@ -426,7 +430,7 @@ func (p *Pod) writeEnvFile(env types.Environment, appName types.ACName, privateU

// PodToSystemd creates the appropriate systemd service unit files for
// all the constituent apps of the Pod
func (p *Pod) PodToSystemd(interactive bool, flavor string, privateUsers string) error {
func (p *Pod) PodToSystemd(interactive bool, nuclearExit bool, flavor string, privateUsers string) error {

if flavor == "kvm" {
// prepare all applications names to become dependency for mount units
Expand All @@ -446,7 +450,7 @@ func (p *Pod) PodToSystemd(interactive bool, flavor string, privateUsers string)

for i := range p.Manifest.Apps {
ra := &p.Manifest.Apps[i]
if err := p.appToSystemd(ra, interactive, flavor, privateUsers); err != nil {
if err := p.appToSystemd(ra, interactive, nuclearExit, flavor, privateUsers); err != nil {
return fmt.Errorf("failed to transform app %q into systemd service: %v", ra.Name, err)
}
}
Expand Down

0 comments on commit 07607ad

Please sign in to comment.