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

Implementation of ps commmand #172

Merged
merged 1 commit into from
Jul 31, 2021

Conversation

zidoshare
Copy link
Contributor

hello, I added the implementation of the ps command.

However, there is a small problem at present, I have not found a way to remove ”--“.
Currently, only the ps option can be added after ”--“. like this:

youki ps youki-container -- -ef

Does it need to be implemented like runc?

runc ps runc-container -ef

@zidoshare zidoshare force-pushed the implementation-of-ps-commmand branch from deaf06b to 850f54a Compare July 29, 2021 17:53
@YJDoc2
Copy link
Collaborator

YJDoc2 commented Jul 30, 2021

Hey, can you give an example of using this?
For example, I tried running this as in your comment, but it showed container doesn't exist. Then I started a container using docker with runtime youki and tried it again, but still it showed the error. (I was running busybox interactively with a top command running in container). Then I tried creating a new container , with docker create using youki, and running it but still got the same error.
Can you show how is this command intended to run ? Thanks!

@zidoshare
Copy link
Contributor Author

zidoshare commented Jul 30, 2021

issue: #146
ref: https://github.com/opencontainers/runc/blob/master/man/runc-ps.8.md

like this:

$ mkdir tutorial
$ cd tutorial
$ mkdir rootfs
$ docker export $(docker create busybox) | tar -C rootfs -xvf -
$ youki create youki-container # need to create container
$ youki ps youki-conainer 
UID        PID  PPID  C STIME TTY          TIME CMD
root         4354     0  0 13:18 ?        00:00:00  youki create youki-container

I have passed the test on my linux system, if there is any problem, please let me know.

@YJDoc2
Copy link
Collaborator

YJDoc2 commented Jul 30, 2021

Interesting, I followed you instructions, and now it recognizes the container, but it gives an OS error when running the ps command :

[DEBUG src/commands/ps.rs:22] 2021-07-30T11:51:59.337432252+05:30 load spec from "/tmp/rootless/youki-container/config.json"
[DEBUG src/commands/ps.rs:24] 2021-07-30T11:51:59.340319199+05:30 spec: Spec { version: "1.0.2-dev", platform: None, process: Process { terminal: false, console_size: Box { height: 0, width: 0 }, user: User { uid: 0, gid: 0, additional_gids: [], username: "" }, args: ["sleep", "5"], env: ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "TERM=xterm"], cwd: "/", no_new_privileges: true, apparmor_profile: "", selinux_label: "", capabilities: Some(LinuxCapabilities { bounding: [CAP_AUDIT_WRITE, CAP_KILL, CAP_NET_BIND_SERVICE], effective: [CAP_AUDIT_WRITE, CAP_KILL, CAP_NET_BIND_SERVICE], inheritable: [CAP_AUDIT_WRITE, CAP_KILL, CAP_NET_BIND_SERVICE], permitted: [CAP_AUDIT_WRITE, CAP_KILL, CAP_NET_BIND_SERVICE], ambient: [CAP_AUDIT_WRITE, CAP_KILL, CAP_NET_BIND_SERVICE] }), rlimits: [LinuxRlimit { typ: RlimitNofile, hard: 1024, soft: 1024 }] }, root: Root { path: "/home/yashodhan/Programming/youki/tutorial/rootfs", readonly: true }, hostname: "runc", mounts: [Mount { destination: "/proc", typ: "proc", source: "proc", options: [] }, Mount { destination: "/dev", typ: "tmpfs", source: "tmpfs", options: ["nosuid", "strictatime", "mode=755", "size=65536k"] }, Mount { destination: "/dev/pts", typ: "devpts", source: "devpts", options: ["nosuid", "noexec", "newinstance", "ptmxmode=0666", "mode=0620", "gid=5"] }, Mount { destination: "/dev/shm", typ: "tmpfs", source: "shm", options: ["nosuid", "noexec", "nodev", "mode=1777", "size=65536k"] }, Mount { destination: "/dev/mqueue", typ: "mqueue", source: "mqueue", options: ["nosuid", "noexec", "nodev"] }, Mount { destination: "/sys", typ: "sysfs", source: "sysfs", options: ["nosuid", "noexec", "nodev", "ro"] }, Mount { destination: "/sys/fs/cgroup", typ: "cgroup", source: "cgroup", options: ["nosuid", "noexec", "nodev", "relatime", "ro"] }], annotations: {}, linux: Linux { uid_mappings: [], gid_mappings: [], sysctl: {}, resources: Some(LinuxResources { devices: [LinuxDeviceCgroup { allow: false, typ: A, major: None, minor: None, access: "rwm" }], disable_oom_killer: false, oom_score_adj: None, memory: None, cpu: None, pids: None, block_io: None, hugepage_limits: [], network: None, freezer: None }), cgroups_path: None, namespaces: [LinuxNamespace { typ: Pid, path: None }, LinuxNamespace { typ: Network, path: None }, LinuxNamespace { typ: Ipc, path: None }, LinuxNamespace { typ: Uts, path: None }, LinuxNamespace { typ: Mount, path: None }], devices: [], rootfs_propagation: "", masked_paths: ["/proc/acpi", "/proc/asound", "/proc/kcore", "/proc/keys", "/proc/latency_stats", "/proc/timer_list", "/proc/timer_stats", "/proc/sched_debug", "/sys/firmware", "/proc/scsi"], readonly_paths: ["/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger"], mount_label: "" } }
[INFO src/cgroups/common.rs:164] 2021-07-30T11:51:59.347005968+05:30 cgroup manager V1 will be used
[DEBUG src/cgroups/v1/manager.rs:43] 2021-07-30T11:51:59.347046795+05:30 Get path for subsystem: cpu
[DEBUG src/cgroups/v1/manager.rs:43] 2021-07-30T11:51:59.350426002+05:30 Get path for subsystem: cpuacct
[DEBUG src/cgroups/v1/manager.rs:43] 2021-07-30T11:51:59.353818296+05:30 Get path for subsystem: cpuset
[DEBUG src/cgroups/v1/manager.rs:43] 2021-07-30T11:51:59.357427789+05:30 Get path for subsystem: devices
[DEBUG src/cgroups/v1/manager.rs:43] 2021-07-30T11:51:59.360869146+05:30 Get path for subsystem: hugetlb
[DEBUG src/cgroups/v1/manager.rs:43] 2021-07-30T11:51:59.364143664+05:30 Get path for subsystem: memory
[DEBUG src/cgroups/v1/manager.rs:43] 2021-07-30T11:51:59.367717854+05:30 Get path for subsystem: pids
[DEBUG src/cgroups/v1/manager.rs:43] 2021-07-30T11:51:59.371002850+05:30 Get path for subsystem: blkio
[DEBUG src/cgroups/v1/manager.rs:43] 2021-07-30T11:51:59.375207927+05:30 Get path for subsystem: net_prio
[DEBUG src/cgroups/v1/manager.rs:43] 2021-07-30T11:51:59.378128851+05:30 Get path for subsystem: net_cls
[DEBUG src/cgroups/v1/manager.rs:43] 2021-07-30T11:51:59.380842752+05:30 Get path for subsystem: freezer
[DEBUG src/cgroups/common.rs:174] 2021-07-30T11:51:59.383515439+05:30 scan pids in folder: "/sys/fs/cgroup/devices/youki/youki-container"
Error: No such file or directory (os error 2)

Is there anything else needs to be done, in terms of permissions etc? I am also running linux system.

@zidoshare
Copy link
Contributor Author

Does the "/sys/fs/cgroup/devices/youki/youki-container" folder exist? I checked it through the path mounted by cgroups.

I don't have a linux system to try now, because I am working with macos. I will try again later.

@zidoshare
Copy link
Contributor Author

It looks like you created a rootless container, but I don't know how to create a rootless container.

 ~/youki create mycontainer2
[DEBUG src/container/init_builder.rs:89] 2021-07-30T12:08:44.645044441+00:00 container directory will be "/tmp/rootless/mycontainer2"
[DEBUG src/container/container.rs:84] 2021-07-30T12:08:44.649286746+00:00 Save container status: Container { state: State { oci_version: "v1.0.2", id: "mycontainer2", status: Creating, pid: None, bundle: ".", annotations: {}, created: None, creator: None, use_systemd: None }, root: "/tmp/rootless/mycontainer2" } in "/tmp/rootless/mycontainer2"
[DEBUG src/rootless.rs:34] 2021-07-30T12:08:44.649510062+00:00 rootless container should be created
[WARN src/rootless.rs:35] 2021-07-30T12:08:44.649991197+00:00 resource constraints and multi id mapping is unimplemented for rootless containers
Error: rootless containers require at least one uid mapping

how to set the uid mapping? @YJDoc2

@YJDoc2
Copy link
Collaborator

YJDoc2 commented Jul 30, 2021

This is very interesting, as now when I try I get the same error, but I'm sure that at the time of my last comment, I was running without root access, and the create command was working 🤔 🤔
Now when I try rootless, I get same error as you, and with root access it is working as expected. Sorry for all the trouble caused.

@zidoshare
Copy link
Contributor Author

No, I think It may be a hidden bug.

The "/tmp/rootless/youki-container" folder exists, but "/sys/fs/cgroup/devices/youki/youki-container" folder does not exist. This should be a bug of create command.

@Furisto
Copy link
Collaborator

Furisto commented Jul 30, 2021

@zidoshare The reason it does not work for rootless containers is that creating cgroups is not yet supported. The implementation is ongoing at #120. I will take a look at this soon, no need to investigate further for now.

@zidoshare
Copy link
Contributor Author

Well, my code should be correct, I am sure 😆

src/commands/ps.rs Show resolved Hide resolved
src/cgroups/common.rs Outdated Show resolved Hide resolved
@Furisto
Copy link
Collaborator

Furisto commented Jul 31, 2021

@zidoshare Looks good. Please resolve the merge conflicts, then I will approve.

@zidoshare zidoshare force-pushed the implementation-of-ps-commmand branch from ea6f5f7 to 7d52b3f Compare July 31, 2021 15:43
@zidoshare zidoshare force-pushed the implementation-of-ps-commmand branch from 7d52b3f to 1398da8 Compare July 31, 2021 15:46
@zidoshare
Copy link
Contributor Author

@Furisto resolved.

@zidoshare Looks good. Please resolve the merge conflicts, then I will approve.

@Furisto
Copy link
Collaborator

Furisto commented Jul 31, 2021

Thanks @zidoshare

@Furisto Furisto merged commit ae7089b into youki-dev:main Jul 31, 2021
@zidoshare zidoshare deleted the implementation-of-ps-commmand branch July 31, 2021 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants