KillingSpark / rustysd

A service manager that is able to run "traditional" systemd services, written in rust
MIT License
506 stars 15 forks source link

Testing rustysd inside of a docker container? #15

Closed pwFoo closed 4 years ago

pwFoo commented 4 years ago

Hi @KillingSpark , have you build a minimal docker image to run rustysd with a simple example unit as docker container pid1 (#9)?

I would like to test it as docker container and maybe build a small system based on rustysd. I use the build tool linuxkit to build an os image based of docker containers. So a minimal image with rustysd as entrypoint would be great as starting point.

Regards

MggMuggins commented 4 years ago

I'm pretty sure what you're talking about is in https://github.com/KillingSpark/rustysd/tree/master/dockerfiles. See the readme there to run it. It worked pretty marvelously for me.

cdbattags commented 4 years ago

Hi @KillingSpark , have you build a minimal docker image to run rustysd with a simple example unit as docker container pid1 (#9)?

I would like to test it as docker container and maybe build a small system based on rustysd. I use the build tool linuxkit to build an os image based of docker containers. So a minimal image with rustysd as entrypoint would be great as starting point.

Regards

I would be very interested in you linuxkit yml files whenever you get this up and running, please!

Also, what use case do you have for a linuxkit unikernel setup? If you don't mind me asking.

pwFoo commented 4 years ago

Yes, I get binaries build, but I need to prepare build env before. Would be nice to run a runstysd/build container with docker and get the binaries to /target directory at the end...

Created a simple alpine based image which starts rustysd with the default unit

# docker run --rm -ti rustysd                                              
[2020-01-31][19:26:03][rustysd::units::loading][TRACE] "./unitfiles/default.target", 1
[2020-01-31][19:26:03][rustysd][TRACE] Finished loading units
[2020-01-31][19:26:03][rustysd::units::dependency_resolving][TRACE] Id 1 references ids: []
[2020-01-31][19:26:03][rustysd][TRACE] Finished pruning units
[2020-01-31][19:26:03][rustysd][TRACE] Unit dependencies passed sanity checks
[2020-01-31][19:26:03][rustysd::units::activate][TRACE] Root unit: default.target
[2020-01-31][19:26:03][rustysd::units::activate][TRACE] Activate id: 1
[2020-01-31][19:26:03][rustysd::units::activate][TRACE] Lock unit: 1
[2020-01-31][19:26:03][rustysd::units::activate][TRACE] Locked unit: 1
[2020-01-31][19:26:03][rustysd::units::activate][TRACE] Lock status for: default.target
[2020-01-31][19:26:03][rustysd::units::activate][TRACE] Locked status for: default.target
[2020-01-31][19:26:03][rustysd::units::units][TRACE] Reached target default.target

But I'm new with systemd / rustysd and have to learn how to spawn a shell from unit...

I played with linuxkit before to build fully custom systems for example without the typical onboot / services structure or replaced runc / containerd with a custom runc or docker / podman build. Linuxkit is a awesome build environment for that use case!

I think it should be easy to build a running minimal system with rustysd + shell (if I understand how to do it with units and create a rustysd-builder first...

pwFoo commented 4 years ago

Tried a getty service, but fails with:

[getty.service][STDERR] EXECV: "/sbin/getty" ["getty", "-l", "/bin/sh", "-n", "115200", "/dev/tty1"]
[2020-01-31][20:40:17][rustysd::notification_handler][TRACE] Interrupted stdout select because the eventfd fired
[2020-01-31][20:40:17][rustysd::platform::eventfd::pipe_eventfd][TRACE] reset pipe eventfd
[2020-01-31][20:40:17][rustysd::notification_handler][TRACE] Reset eventfd value
[getty.service][STDERR] getty: setsid: Operation not permitted

So I changed it to /bin/sh

# docker run --rm -ti --privileged rustysd 
[2020-01-31][20:41:09][rustysd::units::loading][TRACE] "./unitfiles/default.target", 1
[2020-01-31][20:41:09][rustysd::units::loading][TRACE] "./unitfiles/getty.service", 2
[2020-01-31][20:41:09][rustysd::units::unit_parsing::service_unit][TRACE] UID: Uid(0)
[2020-01-31][20:41:09][rustysd::units::loading][TRACE] "./unitfiles/getty.target", 3
[2020-01-31][20:41:09][rustysd][TRACE] Finished loading units
[2020-01-31][20:41:09][rustysd::units::dependency_resolving][TRACE] Id 1 references ids: [3]
[2020-01-31][20:41:09][rustysd::units::dependency_resolving][TRACE] Id 3 references ids: [1, 2]
[2020-01-31][20:41:09][rustysd::units::dependency_resolving][TRACE] Id 2 references ids: [3]
[2020-01-31][20:41:09][rustysd][TRACE] Finished pruning units
[2020-01-31][20:41:09][rustysd][TRACE] Unit dependencies passed sanity checks
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Root unit: getty.service
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Activate id: 2
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Lock unit: 2
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Locked unit: 2
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Lock status for: getty.service
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Locked status for: getty.service
[2020-01-31][20:41:09][rustysd::services::services][TRACE] Start service getty.service
[2020-01-31][20:41:09][rustysd::platform::eventfd::pipe_eventfd][TRACE] notify eventfd
[2020-01-31][20:41:09][rustysd::platform::eventfd::pipe_eventfd][TRACE] notify eventfd
[2020-01-31][20:41:09][rustysd::notification_handler][TRACE] Interrupted stderr select because the eventfd fired
[2020-01-31][20:41:09][rustysd::platform::eventfd::pipe_eventfd][TRACE] reset pipe eventfd
[2020-01-31][20:41:09][rustysd::notification_handler][TRACE] Reset eventfd value
[2020-01-31][20:41:09][rustysd::notification_handler][TRACE] Interrupted stdout select because the eventfd fired
[2020-01-31][20:41:09][rustysd::platform::eventfd::pipe_eventfd][TRACE] reset pipe eventfd
[2020-01-31][20:41:09][rustysd::notification_handler][TRACE] Reset eventfd value
[2020-01-31][20:41:09][rustysd::platform::eventfd::pipe_eventfd][TRACE] notify eventfd
[2020-01-31][20:41:09][rustysd::platform::eventfd::pipe_eventfd][TRACE] notify eventfd
[2020-01-31][20:41:09][rustysd::services::fork_parent][TRACE] [FORK_PARENT] Service: getty.service forked with pid: 18
[2020-01-31][20:41:09][rustysd::services::fork_parent][TRACE] [FORK_PARENT] service getty.service doesnt notify
[2020-01-31][20:41:09][rustysd::socket_activation][TRACE] Interrupted socketactivation select because the eventfd fired
[2020-01-31][20:41:09][rustysd::platform::eventfd::pipe_eventfd][TRACE] reset pipe eventfd
[2020-01-31][20:41:09][rustysd::socket_activation][TRACE] Reset eventfd value
[2020-01-31][20:41:09][rustysd::notification_handler][TRACE] Interrupted notification select because the eventfd fired
[2020-01-31][20:41:09][rustysd::platform::eventfd::pipe_eventfd][TRACE] reset pipe eventfd
[2020-01-31][20:41:09][rustysd::notification_handler][TRACE] Reset eventfd value
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Activate id: 3
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Lock unit: 3
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Locked unit: 3
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Lock status for: getty.target
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Locked status for: getty.target
[2020-01-31][20:41:09][rustysd::units::units][TRACE] Reached target getty.target
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Activate id: 1
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Lock unit: 1
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Locked unit: 1
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Lock status for: default.target
[2020-01-31][20:41:09][rustysd::units::activate][TRACE] Locked status for: default.target
[2020-01-31][20:41:09][rustysd::units::units][TRACE] Reached target default.target
[getty.service][STDERR] EXECV: "/bin/sh" ["sh"]

And I have a running container with rustysd and a sh process...

# docker exec -ti unruffled_joliot ps
PID   USER     TIME  COMMAND
    1 root      0:00 /rustysd
   18 root      0:00 sh
   30 root      0:00 ps

unit file getty.service (=shell)

[Unit]
Description= Start getty on /dev/tty1

[Service]
#ExecStart=/sbin/getty -l /bin/sh -n 115200 /dev/tty1
ExecStart=/bin/sh
Type=simple
Restart=always

#StandardInput=/dev/tty1
#StandardInput=/dev/tty1
#StandardOutput=/dev/tty1
#TTYPath=/dev/tty1
#TTYReset=yes
#TTYVHangup=yes

[Install]
WantedBy=getty.target

So is it possible with rustysd to start getty-service in foreground / interactive / focused tty?

cdbattags commented 4 years ago

Mind tossing me the linuxkit .yml file so I can try and assist?

pwFoo commented 4 years ago

At the moment it isn't a linuxkit file, just a docker image with alpine linux + rustysd binaries. Works fine so far as pid1, but can't get a shell if I run it with docker run --rm -ti <IMG>

I try to get a shell in the end of the rustysd boot, but don't know if that really could work as I think and if rustysd supports to move PID1 to the background and end up in a working shell (service)?

KillingSpark commented 4 years ago

I am sorry I can't be of too much assistance here but I don't exactly know how docker and getty interact. I think you should look into the error getty throws out

getty: setsid: Operation not permitted

pwFoo commented 4 years ago

Yes, thats right. But I don't find why. Maybe it's getty related,.. agetty works.

@cdbattags Simplest linuxkit yml

kernel:
  image: linuxkit/kernel:4.19.99
  cmdline: "console=tty0 console=ttyS0 console=ttyAMA0"
init:
  - pwfoo/rustysd:latest

It boots fine with qemu, but you won't end in a working shell / terminal...

[...]
[    1.456426] cdrom: Uniform CD-ROM driver Revision: 3.20
[    1.459274] sr 1:0:0:0: Attached scsi generic sg0 type 5
[    1.467787] Freeing unused kernel image memory: 1584K
[    1.471136] Write protecting the kernel read-only data: 18432k
[    1.474425] Freeing unused kernel image memory: 2028K
[    1.476305] Freeing unused kernel image memory: 1080K
[    1.477948] Run /init as init process
[    1.510152] random: rustysd: uninitialized urandom read (16 bytes read)
[2020-02-01][08:52:14][rustysd::units::loading][TRACE] "./unitfiles/default.target", 1
[2020-02-01][08:52:14][rustysd::units::loading][TRACE] "./unitfiles/getty.service", 2
[2020-02-01][08:52:14][rustysd::units::unit_parsing::service_unit][TRACE] UID: Uid(0)
[2020-02-01][08:52:14][rustysd::units::loading][TRACE] "./unitfiles/getty.target", 3
[2020-02-01][08:52:14][rustysd][TRACE] Finished loading units
[2020-02-01][08:52:14][rustysd::units::dependency_resolving][TRACE] Id 1 references ids: [3]
[2020-02-01][08:52:14][rustysd::units::dependency_resolving][TRACE] Id 3 references ids: [1, 2]
[2020-02-01][08:52:14][rustysd::units::dependency_resolving][TRACE] Id 2 references ids: [3]
[2020-02-01][08:52:14][rustysd][TRACE] Finished pruning units
[2020-02-01][08:52:14][rustysd][TRACE] Unit dependencies passed sanity checks
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Root unit: getty.service[    1.528810] random: rustysd: uninitialized urandom read (16 bytes read)
[    1.530799] random: rustysd: uninitialized urandom read (16 bytes read)

[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Activate id: 2
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Lock unit: 2
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Locked unit: 2
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Lock status for: getty.service
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Locked status for: getty.service
[2020-02-01][08:52:14][rustysd::services::services][TRACE] Start service getty.service
[2020-02-01][08:52:14][rustysd::notification_handler][TRACE] Interrupted notification select because the eventfd fired
[2020-02-01][08:52:14][rustysd::platform::eventfd::pipe_eventfd][TRACE] reset pipe eventfd
[2020-02-01][08:52:14][rustysd::notification_handler][TRACE] Reset eventfd value
[2020-02-01][08:52:14][rustysd::platform::eventfd::pipe_eventfd][TRACE] notify eventfd
[2020-02-01][08:52:14][rustysd::notification_handler][TRACE] Interrupted stdout select because the eventfd fired
[2020-02-01][08:52:14][rustysd::platform::eventfd::pipe_eventfd][TRACE] reset pipe eventfd
[2020-02-01][08:52:14][rustysd::notification_handler][TRACE] Reset eventfd value
[2020-02-01][08:52:14][rustysd::platform::eventfd::pipe_eventfd][TRACE] notify eventfd
[2020-02-01][08:52:14][rustysd::notification_handler][TRACE] Interrupted stderr select because the eventfd fired
[2020-02-01][08:52:14][rustysd::platform::eventfd::pipe_eventfd][TRACE] reset pipe eventfd
[2020-02-01][08:52:14][rustysd::notification_handler][TRACE] Reset eventfd value
[2020-02-01][08:52:14][rustysd::platform::eventfd::pipe_eventfd][TRACE] notify eventfd
[2020-02-01][08:52:14][rustysd::socket_activation][TRACE] Interrupted socketactivation select because the eventfd fired
[2020-02-01][08:52:14][rustysd::platform::eventfd::pipe_eventfd][TRACE] reset pipe eventfd
[2020-02-01][08:52:14][rustysd::platform::eventfd::pipe_eventfd][TRACE] notify eventfd
[2020-02-01][08:52:14][rustysd::services::fork_parent][TRACE] [FORK_PARENT] Service: getty.service forked with pid: 222
[2020-02-01][08:52:14][rustysd::socket_activation][TRACE] Reset eventfd value
[2020-02-01][08:52:14][rustysd::services::fork_parent][TRACE] [FORK_PARENT] service getty.service doesnt notify
[getty.service][STDERR] EXECV: "/sbin/agetty" ["agetty", "--autologin", "root", "--skip-login", "--keep-baud", "tty1"]
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Activate id: 3
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Lock unit: 3
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Locked unit: 3
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Lock status for: getty.target
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Locked status for: getty.target
[2020-02-01][08:52:14][rustysd::units::units][TRACE] Reached target getty.target
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Activate id: 1
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Lock unit: 1
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Locked unit: 1
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Lock status for: default.target
[2020-02-01][08:52:14][rustysd::units::activate][TRACE] Locked status for: default.target
[2020-02-01][08:52:14][rustysd::units::units][TRACE] Reached target default.target
login[223]: root login on 'tty1'
pwFoo commented 4 years ago

rustysd works fine as systemd replacement inside of docker containers! rustysd runs as pid1 and services started.

tty problem was related to qemu / console settings and works fine with hardware on tty1.

So time to play with rustysd 👍