From 658333467611bc3232abd7eb6509d15c5e9328e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iago=20L=C3=B3pez=20Galeiras?= Date: Tue, 17 Oct 2017 11:15:26 +0200 Subject: [PATCH 1/2] stage1: reorder iomux service This changes the start order of the iomux service so it starts before the app service instead of after (in the diff, "before" and "after" are swapped because this code refers to the app service). If the app has a pre-start hook that fails, iomux will never start and we won't get any logs of the pre-start hook so users will have a hard time debugging. With this change, iomux will be started before the app service starts, capturing all the relevant logs. --- stage1/init/common/units.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stage1/init/common/units.go b/stage1/init/common/units.go index 9e29e169d2..a53f7a3102 100644 --- a/stage1/init/common/units.go +++ b/stage1/init/common/units.go @@ -200,7 +200,7 @@ func ImmutableEnv(p *stage1commontypes.Pod) error { // 3. if any of stdin/stdout/stderr is in TTY or streaming mode: // 3a. the env file for iottymux is written to `/rkt/iottymux//env` with the above content // 3b. for TTY mode, a `TTYPath` property and an `After=ttymux@.service` dependency are added -// 3c. for streaming mode, a `Before=iomux@.service` dependency is added +// 3c. for streaming mode, an `After=iomux@.service` dependency is added // // For complete details, see dev-docs at Documentation/devel/log-attach-design.md func (uw *UnitWriter) SetupAppIO(p *stage1commontypes.Pod, ra *schema.RuntimeApp, binPath string, opts ...*unit.UnitOption) []*unit.UnitOption { @@ -321,9 +321,9 @@ func (uw *UnitWriter) SetupAppIO(p *stage1commontypes.Pod, ra *schema.RuntimeApp } if needsIOMux { - // streaming mode brings in a `iomux@.service` before-dependency + // streaming mode brings in a `iomux@.service` after-dependency opts = append(opts, unit.NewUnitOption("Unit", "Requires", fmt.Sprintf("iomux@%s.service", ra.Name))) - opts = append(opts, unit.NewUnitOption("Unit", "Before", fmt.Sprintf("iomux@%s.service", ra.Name))) + opts = append(opts, unit.NewUnitOption("Unit", "After", fmt.Sprintf("iomux@%s.service", ra.Name))) logMode, ok := p.Manifest.Annotations.Get("coreos.com/rkt/experiment/logmode") if ok { file.WriteString(fmt.Sprintf("STAGE1_LOGMODE=%s\n", logMode)) From e1d3b2333ee3f03815e3ad807521bb524a625d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iago=20L=C3=B3pez=20Galeiras?= Date: Tue, 17 Oct 2017 16:31:26 +0200 Subject: [PATCH 2/2] stage1: make socket units start before iomux service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It might happen that the iomux service starts before the socket unit is started. This means that the file specified in ListenFIFO (e.g. `/rkt/iottymux/0-myapp-container/stage2-stdin`) won't exist and iomux will fail with something like this: Listening on stderr socket for 0-myapp-container. Listening on stdout socket for 0-myapp-container. iottymux: runtime failure └─invalid stdin FIFO: open /rkt/iottymux/0-myapp-container/stage2-stdin: no such file or directory Starting Create /etc/passwd and /etc/group... Listening on stdin socket for 0-myapp-container. iomux@0-myapp-container.service: Main process exited, code=exited, status=254/n/a iomux@0-myapp-container.service: Unit entered failed state. iomux@0-myapp-container.service: Failed with result 'exit-code'. This adds a Before=iomux.service dependency to the socket units so they start before it, making sure the FIFO exists by the time iomux starts. --- stage1/init/common/units.go | 1 + 1 file changed, 1 insertion(+) diff --git a/stage1/init/common/units.go b/stage1/init/common/units.go index a53f7a3102..a51f0b7fba 100644 --- a/stage1/init/common/units.go +++ b/stage1/init/common/units.go @@ -771,6 +771,7 @@ func (uw *UnitWriter) AppSocketUnit(appName types.ACName, binPath string, stream unit.NewUnitOption("Unit", "RefuseManualStart", "yes"), unit.NewUnitOption("Unit", "RefuseManualStop", "yes"), unit.NewUnitOption("Unit", "BindsTo", fmt.Sprintf("%s.service", appName)), + unit.NewUnitOption("Unit", "Before", fmt.Sprintf("iomux@%s.service", appName)), unit.NewUnitOption("Socket", "RemoveOnStop", "yes"), unit.NewUnitOption("Socket", "Service", fmt.Sprintf("%s.service", appName)), unit.NewUnitOption("Socket", "FileDescriptorName", streamName),