Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ignition_linux.go failed on systemd-free Linux due to lack of timedatectl executable #17244

Closed
nabbisen opened this issue Jan 27, 2023 · 5 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@nabbisen
Copy link
Contributor

nabbisen commented Jan 27, 2023

Issue Description

My machine is Artix Linux, based on Arch Linux and using OpenRC instead of systemd.

getLocalTimeZone in ignition_linux.go executes timedatectl, which is a part of systemd. Therefore, it failed in my env, and .ign was not created.

Steps to reproduce the issue

Steps to reproduce the issue

  1. Use systemd-free Linux.
  2. Install Podman and run podman machine init

Describe the results you received

  1. The error was:
    Extracting compressed file
    Image resized.
    Error: exec: "timedatectl": executable file not found in $PATH
  2. Additionally, since podman-machine-default.ign was not created, running podman machine start in the next step also failed with the error:
    Starting machine "podman-machine-default"
    Waiting for VM ...
    Error: qemu exited unexpectedly with exit code 1, stderr: qemu-system-x86_64: -fw_cfg name=opt/com.coreos/config,file=/home/(...)/.config/containers/podman/machine/qemu/podman-machine-default.ign: can't load /home/(...)/.config/containers/podman/machine/qemu/podman-machine-default.ign: Failed to open file “/home/(...)/.config/containers/podman/machine/qemu/podman-machine-default.ign”: No such file or directory

Describe the results you expected

podman machine init is successful with systemd-free Linux.

podman info output

OS: Artix Linux with OpenRC x86_64
Podman: 4.3.1

Podman in a container

No

Privileged Or Rootless

Rootless

Upstream Latest Release

Yes

Additional environment details

-

Additional information

I made a custom Rust script to print my timezone named "timedatectl". After it built and placed in $PATH, podman machine init succeeded. The .ign file was created with content written.

In my opinion, on systemd-free Linux, exec.Command("timedatectl", "show", "--property=Timezone").Output() should be replaced with exec.Command("cat", "/etc/timezone").Output() in ignition_linux.go. For example:

var output
o, err := exec.Command("pidof", "systemd").Output()
if string(o) == "1\n" || err != nil {
	// default
	output, err = exec.Command("timedatectl", "show", "--property=Timezone").Output()
} else {
	// systemd-free
	output, err = exec.Command("cat", "/etc/timezone").Output()
}
@nabbisen nabbisen added the kind/bug Categorizes issue or PR as related to a bug. label Jan 27, 2023
@vrothberg
Copy link
Member

Thanks for reaching out!

The idea sounds good to me. I suggest to do a path.Lookup("timedatectl") though to check whether it's available.

Are you interested in opening a PR?

@nabbisen
Copy link
Contributor Author

Thanks for reaching out!

The idea sounds good to me. I suggest to do a path.Lookup("timedatectl") though to check whether it's available.

Are you interested in opening a PR?

Thanks, too, for your precious time.
Yes, I am. I'll send in a few days.
Well, thank you, again. path.Lookup("timedatectl") is nice.

@Luap99
Copy link
Member

Luap99 commented Jan 27, 2023

This sounds reasonable but AFAIK /etc/timezone does not have to exist either. It doesn't exists on my fedora install, properly the reason why we used timedatectl in the first place.
Also you should not use exec cat to read a file, just read it directly from the go code, i.e. use os.ReadFile().

@nabbisen
Copy link
Contributor Author

nabbisen commented Jan 27, 2023

This sounds reasonable but AFAIK /etc/timezone does not have to exist either. It doesn't exists on my fedora install, properly the reason why we used timedatectl in the first place. Also you should not use exec cat to read a file, just read it directly from the go code, i.e. use os.ReadFile().

Thank you for your detailed feedbacks. I agree /etc/timezone doesn't always exist. To get time zone from it is OpenRC's way. I imagine your Fedora uses systemd as init system so /etc/timezone is not necessary.

My opinion is not to replace timedatectl with /etc/timezone but to use the latter when the former is missing.
My trial must be like:

if timedatectl is missing {
    read /etc/timezone
} else {
    default aka timedatectl
}

It aims to mitigate failure of the specific case.
As to testing, I will verify on both Artix (systemd-free) and Fedora 37 (systemd).
How about it ?

you should not use exec cat to read a file

Definitely 😅 I am grateful to you.

@nabbisen
Copy link
Contributor Author

I sent PR #17264 .

Test done:

  1. Artix Linux (systemd-free)
  • podman machine init was successful.
  • My time zone was written in podman-machine-default.ign.
  1. Fedora 37 (systemd)
  • podman machine init was successful, too. (regression testing)
  • Diff was only in passwd - users - sshAuthorizedKeys between original .go and modified.

openshift-merge-robot added a commit that referenced this issue Jan 30, 2023
…t_on_systemd_free_linux

fix #17244: use /etc/timezone where `timedatectl` is missing on Linux
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/podman that referenced this issue Jan 30, 2023
…g on Linux

Signed-off-by: nabbisen <nabbisen@scqr.net>
vrothberg pushed a commit to vrothberg/libpod that referenced this issue Jan 30, 2023
…g on Linux

[NO NEW TESTS NEEDED]

Signed-off-by: nabbisen <nabbisen@scqr.net>
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
openshift-merge-robot added a commit that referenced this issue Jan 30, 2023
[v4.4] fix #17244: use /etc/timezone where `timedatectl` is missing on Linux
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 2, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

No branches or pull requests

3 participants