Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.

Conversation

@iaguis
Copy link
Member

@iaguis iaguis commented Feb 19, 2016

If the version of the systemd running in stage1 is >=v227, the command
"systemctl exit STATUS" will set the exit status of the container. See
https://lists.freedesktop.org/archives/systemd-devel/2015-October/034509.html:

  • The "systemctl exit" command now optionally takes an
    additional parameter that sets the exit code to return from
    the systemd manager when exiting. This is only relevant when
    running the systemd user instance, or when running the
    system instance in a container.

If not, we will continue with the previous logic, so we can merge this now
and benefit from it when we actually update to v229.

Closes #1783

CHANGELOG.md Outdated

#### New features and UX changes

- Propagate app exit status to rkt's exit status ([#HEHE](https://github.com/coreos/rkt/pull/HEHE).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

;)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you know.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

echo "${status#*=}" > "/rkt/status/$app"
if [ "${status#*=}" != 0 ] ; then
${SYSCTL} exit ${status#*=}
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment?

# The command "systemctl exit $status" is available since systemd-v227. On older
# systemd, the command will fail and rkt will just exit with return code 0.

@iaguis
Copy link
Member Author

iaguis commented Feb 22, 2016

Updated.

err := child.Wait()
status := getExitStatus(err)
if status != expectedStatus {
t.Fatalf("rkt terminated with unexpected status %d, expected %d\nOutput:\n%s", status, expectedStatus, child.Collect())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a point in running Collect() here. For this to work, Capture() needs to be called first. So this will most likely print no output at all.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it looks like it is following what is being done in this function below. Nevermind then.

@iaguis iaguis force-pushed the iaguis/exit-code branch 3 times, most recently from 20c2312 to 616a03c Compare February 22, 2016 14:14
@krnowak
Copy link
Collaborator

krnowak commented Feb 22, 2016

Will this work with kvm flavor (assuming that there is systemd 229)?

@alban
Copy link
Member

alban commented Feb 22, 2016

@krnowak I assume the command systemctl exit will fail when systemd (pid1) is not in a container and it will just continue stopping the VM without problems, but I have not tested it...

@iaguis
Copy link
Member Author

iaguis commented Feb 22, 2016

We'll recheck when we update to v229.

Any other concerns?

// Currently we have systemd v222 in the coreos flavor which doesn't
// include the exit status propagation code.
// TODO(iaguis): we should expect 5 as the exit status when we update to v229
waitOrFail(t, child, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this break tests with tests/aws.sh on Fedora-Rawhide with the host flavor (it should have the last systemd)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like if tests/aws.sh could test the host flavor on all versions of Fedora... this would require something like...?

if systemdVersion() >= 227 {
  waitOrFail(t, child, 5)
} else {
  waitOrFail(t, child, 0)
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be nice but detecting the stage1 systemd version from the tests seems a bit overkill...

@iaguis
Copy link
Member Author

iaguis commented Feb 22, 2016

This is not finished yet, it works with the src flavor because we copy all the generated unit files to stage1 but it doesn't work otherwise.

I need to figure out which services/targets are needed.

@iaguis
Copy link
Member Author

iaguis commented Feb 23, 2016

PTAL.

@krnowak
Copy link
Collaborator

krnowak commented Feb 23, 2016

Just one question otherwise LFAD (or fixup the commit message) - the exit.target unit file is for systemctl exit, right?

@iaguis
Copy link
Member Author

iaguis commented Feb 23, 2016

Just one question otherwise LFAD (or fixup the commit message) - the exit.target unit file is for systemctl exit, right?

Yes, systemctl exit activates exit.target so we need it.


if err = writeShutdownService(p); err != nil {
return errwrap.Wrap(errors.New("failed to write shutdown service"), err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be in PodToSystemd() instead of appToSystemd()? In a pod with several apps, the shutdown service should still be written only one time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're very right, no need to write it over and over again.

If the version of the systemd running in stage1 is >=v227, the command
"systemctl exit STATUS" will set the exit status of the container. See
https://lists.freedesktop.org/archives/systemd-devel/2015-October/034509.html:

 * The "systemctl exit" command now optionally takes an
   additional parameter that sets the exit code to return from
   the systemd manager when exiting. This is only relevant when
   running the systemd user instance, or when running the
   system instance in a container.

If not, we will continue with the previous logic, so we can merge this now
and benefit from it when we actually update to v229.
Modify functions that wait for rkt to expect a particular exit code
instead of only success and fail.
Depending on stage1's systemd version, we call "halt" or "exit".

In the host flavor, we need to parse the output of "systemctl --version"
because there's not systemd version information in stage1.
@alban
Copy link
Member

alban commented Feb 23, 2016

LGTM

iaguis added a commit that referenced this pull request Feb 23, 2016
stage1: propagate app exit code to rkt exit code
@iaguis iaguis merged commit 765bb2a into rkt:master Feb 23, 2016
@yifan-gu
Copy link
Contributor

mikel from samsung is hitting this issue today when he has a service file that requires rkt run to restart on failure.

So when will we import v229?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants