Fedora-Remix-for-WSL icon indicating copy to clipboard operation
Fedora-Remix-for-WSL copied to clipboard

How to start service (e.g. SSHD or MariaDB)?

Open bures opened this issue 5 years ago • 48 comments

How should one start a service in WSLFedoraRemix. I tried systemctl, but that complaints about systemd not being started. Is there another trick?

Thanks.

bures avatar Jan 24 '19 22:01 bures

The old fashioned way, with a script.

There is no init in WSL, when you launch WSL you are taken straight to your default terminal.

If you want to launch a service you can call it via script and do so in the background using tmux.

You could also create a Windows batch file and run `fedoraremix run and set that somewhere.

You can then create a Windows service around that batch file using sc.

I am going to leave this issue open because this is a common question and I welcome community ideas and input.

sirredbeard avatar Jan 25 '19 00:01 sirredbeard

There is a development for "systemd" hopefully in future we can run "directly via "systemctl" I'm aware of that problem but It is depend on WSL people to handle that. I saw "real example picture" from one of the microsoft developer and I'll share link into here with "all comments" so you can understand better.

alt text

https://github.com/Microsoft/WSL/issues/994 https://github.com/systemd/systemd/issues/8036

onuralpszr avatar Jan 26 '19 15:01 onuralpszr

He's not a MS developer, just a collaborator. It would be great if he shared his repro steps but as he pointed out later in the issue, it may be trivial since we may get it in the Fall build (probably too late to get in Spring or someone would of said something)

WSLUser avatar Feb 06 '19 14:02 WSLUser

He released the code if we want to include for use in WSL1: https://github.com/microsoft/WSL/issues/994#issuecomment-491985603

WSLUser avatar Jun 06 '19 13:06 WSLUser

This issue has not been solved, even after WSL2 ... peculiar

starvsion avatar Oct 14 '19 20:10 starvsion

One could also just run /usr/sbin/sshd

modzilla99 avatar Nov 26 '19 12:11 modzilla99

But be sure to generate the ssh keys first

modzilla99 avatar Nov 26 '19 12:11 modzilla99

While I understand that I can't have services started automatically in the background, is there an easy way to start and stop services on the console like with systemd (service command)? Otherwise looks like I have to check and simulate the individual configs in /usr/lib/systemd/system which is not very handy.

(The service command works within Pengwin Linux, I would love to see it behaving the same way in Fedora Remix.)

nicolaskeller avatar Jan 16 '20 12:01 nicolaskeller

Hello,

As Pengwin is Debian based you have the service command. In Fedora depending on the service, you may have the former /etc/init.d/xxxx start or yes simulate the individual configs. I can find a tool that can simulate systemd for starting services or try to enable something like service compatible with Fedora.

For starting them automatically the script must be put in /etc/profile.d/xxx.sh and make an exception in sudoers so it starts automatically without asking a password.

Regards

crramirez avatar Jan 16 '20 12:01 crramirez

Maybe the answer can be around including this in Fedora Remix: https://github.com/gdraheim/docker-systemctl-replacement

crramirez avatar Jan 16 '20 12:01 crramirez

Problem with that is that would mean we're running Fedora in Docker. We aren't. We're running it in WSL, which admittedly is container-based approach but the implementation details are very different. This doesn't even cover the VM approach for WSL2. Unless we want to fork and adapt for WSL, (i.e. get rid of docker commands and replace something else, perhaps genie), I think a different solution is required. In our case though, I think the best solution is the hardest one: Implement the initd scripts ourselves. I posted a few for starters that can be added by the user optionally. We need to determine what other ones people are most likely to use and add those as well. I would not propose having a script available for everything living under the sun (unless somebody has already done this, in which case, we just ensure we credit the author(s)). We should just include those things that people find most useful (for example, we provide several applications in pengwin-setup that require services to run).

WSLUser avatar Jan 16 '20 14:01 WSLUser

Still with problem System has not been booted with systemd as init system (PID 1). Can't operate.

This problem can be solved on Ubuntu (no paid subsystem) with: https://github.com/DamionGans/ubuntu-wsl2-systemd-script

But this one which is a paid subsystem, is not working? 😒

this must be fixed, or i'll request refund.

ningacoding avatar May 24 '20 22:05 ningacoding

I am sure that must be better ways to ask for a feature. Ubuntu doesn't include it either. We can take a look and evaluate if it really solves our user's needs. For refunds: Forward your Microsoft Store confirmation email to [email protected]

Regards, Carlos

crramirez avatar May 24 '20 22:05 crramirez

thank you, request sent.

Regards.

ningacoding avatar May 24 '20 23:05 ningacoding

I made some tests using a fake systemd script:

sudo curl https://raw.githubusercontent.com/WhitewaterFoundry/docker-systemctl-replacement/master/files/docker/systemctl3.py -o /usr/bin/systemctl

I tested it with ssh but I needed to generate the keys using:

sudo /usr/bin/ssh-keygen -A

If anyone can test if it suits the needs?

It is only to start services not to run them at startup

Regards

crramirez avatar Jun 22 '20 08:06 crramirez

Thanks in advance, this looks like a very handy work-around! I tried sudo systemctl start postgresql and some other services but it doesn't seem to work for me. I get some warnings in verbose mode, nothing critical, but the processes don't start. I'm not sure how to provide more useful information in particular, feel free to ask if I can help.

nicolaskeller avatar Jun 22 '20 09:06 nicolaskeller

I can directly test PostgreSQL don't worry. I tried with MariaDB and it worked.

We are trying with another approach as well but it requires WSL2 and takes more time. Maybe we can ship with this script for WSL1 with some how-to guides and the more complete for WSL2.

Thanks for testing

crramirez avatar Jun 22 '20 09:06 crramirez

If you can provide a list of the services that you want to start, with these we can prioritize the services that our users need.

crramirez avatar Jun 22 '20 09:06 crramirez

Sorry I forgot to mention I'm already on WSL2. Performance is so much better, I guess most users will switch in the upcoming months. My pain point currently is postgresql, followed by sshd and redis.

nicolaskeller avatar Jun 22 '20 09:06 nicolaskeller

Seems lack of systemctl cause podman doesn't run on remix. image They claim it can run at https://www.redhat.com/sysadmin/podman-windows-wsl2, but seems it isn't on Fedora Remix.

Related to https://github.com/MicrosoftDocs/WSL/issues/457 But some people write daemonize on https://github.com/MicrosoftDocs/WSL/issues/457#issuecomment-730731900 script to be put on /etc/profile, seems work for some

Edit : Podman work with some minor change on fedora remix 33.1 https://github.com/containers/podman/issues/3288#issuecomment-768186645

benyaminl avatar Feb 04 '21 14:02 benyaminl

@benyaminl This is not a systemd issue. It will also run on Fedora remix, you just didn't do the steps:

$ dnf reinstall -y shadow-utils

gbraad avatar Feb 14 '21 08:02 gbraad

@bures

To get systemd working you can do: https://github.com/arkane-systems/genie/issues/98#issuecomment-778641443. At the moment I'll see if I can make a package build on copr. If you don't wanna install dotnet on your machine, you can use: https://github.com/gbraad/fedora-wsl-genie have set up a build (WIP) on https://gitlab.com/gbraad/fedora-wsl-genie/-/jobs/1028753060 where you can get the artifacts. Place them in /usr/libexec/genie and link as ln -s /usr/libexec/genie/genie /usr/sbin/genie

Will work on a package and a specific wsl.target for this.

gbraad avatar Feb 14 '21 08:02 gbraad

I created a PR for genie that creates an RPM package to deal with the systemd setup: https://github.com/arkane-systems/genie/pull/112 I uploaded a test package to https://github.com/gbraad/fedora-wsl-genie/releases/tag/1.34 Please let me know if this works.

PS> wsl -d fedora33
$ dnf install -y genie-1.34-1.fc33.x86_64.rpm
$ genie -i

a time out might occur here (after 180seconds). This can be fixed:

...
$ genie -s
$ sudo systemctl disable auditd
$ sudo systemctl mask systemd-modules-load
$ exit         # leave the systemd namespace
$ genie -u # stop systemd to verify
$ exit         # exit wsl

Now you can start the distro as follows:

PS> wsl -d fedora33 genie -i

and no timeout should occur. Let me know if this works for you.

Note: Next step is to create a minimized target; wsl.target which handles all of this.


Screenshots: image image

gbraad avatar Feb 18 '21 00:02 gbraad

Wow this is amazing. Thank you for the collaboration. We will make some tests with it

crramirez avatar Feb 18 '21 10:02 crramirez

@crramirez please test the initial package. At the moment I can not automate the build, as the build process relies on pulling in dependencies with nuget restore and there is no specific minimal wsl.target that avoids the issues with auditd, dmpath and load-modules.

gbraad avatar Feb 18 '21 12:02 gbraad

I created a PR for genie that creates an RPM package to deal with the systemd setup: arkane-systems/genie#112 I uploaded a test package to https://github.com/gbraad/fedora-wsl-genie/releases/tag/1.34 Please let me know if this works.

PS> wsl -d fedora33
$ dnf install -y genie-1.34-1.fc33.x86_64.rpm
$ genie -i

a time out might occur here (after 180seconds). This can be fixed:

...
$ genie -s
$ sudo systemctl disable auditd
$ sudo systemctl mask systemd-modules-load
$ exit         # leave the systemd namespace
$ genie -u # stop systemd to verify
$ exit         # exit wsl

Now you can start the distro as follows:

PS> wsl -d fedora33 genie -i

and no timeout should occur. Let me know if this works for you.

Note: Next step is to create a minimized target; wsl.target which handles all of this.

Screenshots: image image

Hello, why it nag me with

A fatal error occurred. The required library libhostfxr.so could not be found.
If this is a self-contained application, that library should exist in [/usr/libexec/genie/].
If this is a framework-dependent application, install the runtime in the global location [/usr/share/dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location or register the runtime location in [/etc/dotnet/install_location].

The .NET runtime can be found at:
  - https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=fedoraremixforwsl.33-x64&apphost_version=5.0.2

I install from the RPM you provide, do I still need to install dotnetcore to run genie -i?

Seem using rpm -ql genie rpm doesn't provide it

[ben@BEN-ASUS-A43SV ~]$ rpm -ql genie
/etc/genie.ini
/usr/lib/.build-id
/usr/lib/.build-id/98
/usr/lib/.build-id/98/c14a6574a0327487734680aea323c623135945
/usr/lib/.build-id/98/c14a6574a0327487734680aea323c623135945.1
/usr/libexec/genie/10-genie-envar.sh
/usr/libexec/genie/genie
/usr/libexec/genie/runinwsl

Seems I still need to install .net 5.0 runtime. Let me try.

benyaminl avatar Feb 18 '21 12:02 benyaminl

@benyaminl Can you try:

$ dnf install -y dotnet-runtime-5.0

Note: my bad... I generated the package from the same environment I tested it on.

gbraad avatar Feb 18 '21 12:02 gbraad

@benyaminl Can you try:

$ dnf install -y dotnet-runtime

But that means I don't need Basic Desktop right? Only Server no Gui is enough right?

benyaminl avatar Feb 18 '21 12:02 benyaminl

I enabled Basic-Desktop as that provides most of the needed dependencies. but no GUI should work.

Note: ~~updated the PR and will generate a new package.~~ Done with the update

gbraad avatar Feb 18 '21 13:02 gbraad

I enabled Basic-Desktop as that provides most of the needed dependencies. but no GUI should work.

Note: ~updated the PR and will generate a new package.~ Done with the update

Anyway what I'm missing. I got degraded and failing services like image

● BEN-ASUS-A43SV-wsl
    State: degraded
     Jobs: 0 queued
   Failed: 3 units
    Since: Thu 2021-02-18 20:10:33 +07; 21min ago
   CGroup: /
           ├─user.slice 
           │ └─user-1000.slice 
           │   ├─[email protected] 
           │   │ ├─dbus-broker.service 
           │   │ │ ├─977 /usr/bin/dbus-broker-launch --scope user
           │   │ │ └─978 dbus-broker --log 4 --controller 10 --machine-id e826643fae8647c8b9c9572496b4bb73 --max-bytes 100000000000000 --max-fds 25000000000000 --max-matches 5000000000
           │   │ ├─init.scope 
           │   │ │ ├─955 /usr/lib/systemd/systemd --user
           │   │ │ └─956 (sd-pam)
           │   │ └─pipewire.service 
           │   │   ├─963 /usr/bin/pipewire
           │   │   └─979 /usr/bin/pipewire-media-session
           │   └─session-c1.scope 
           │     └─995 /usr/bin/dbus-daemon --syslog --fork --print-pid 4 --print-address 6 --session
           ├─init.scope 
           │ └─24 systemd
           └─system.slice 
             ├─abrt-journal-core.service 
             │ └─174 /usr/bin/abrt-dump-journal-core -D -T -f -e
             ├─systemd-udevd.service 
             │ └─69 /usr/lib/systemd/systemd-udevd
             ├─dbus-broker.service 
             │ ├─137 /usr/bin/dbus-broker-launch --scope system --audit
             │ └─138 dbus-broker --log 4 --controller 9 --machine-id e826643fae8647c8b9c9572496b4bb73 --max-bytes 536870912 --max-fds 4096 --max-matches 131072 --audit
             ├─systemd-homed.service 
             │ └─150 /usr/lib/systemd/systemd-homed
             ├─polkit.service 
             │ └─170 /usr/lib/polkit-1/polkitd --no-debug
             ├─rtkit-daemon.service 
             │ └─148 /usr/libexec/rtkit-daemon
             ├─chronyd.service 
             │ └─158 /usr/sbin/chronyd
             ├─accounts-daemon.service 
             │ └─196 /usr/libexec/accounts-daemon
             ├─abrt-xorg.service 
             │ └─176 /usr/bin/abrt-dump-journal-xorg -fxtD
             ├─ModemManager.service 
             │ └─139 /usr/sbin/ModemManager
             ├─systemd-journald.service 
             │ └─61 /usr/lib/systemd/systemd-journald
             ├─atd.service 
             │ └─229 /usr/sbin/atd -f
             ├─sshd.service 
             │ └─214 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
             ├─crond.service 
             │ └─230 /usr/sbin/crond -n
             ├─NetworkManager.service 
             │ └─202 /usr/sbin/NetworkManager --no-daemon
             ├─systemd-machined.service 
             │ └─948 /usr/lib/systemd/systemd-machined
             ├─gssproxy.service 
             │ └─219 /usr/sbin/gssproxy -D
             ├─rsyslog.service 
             │ └─147 /usr/sbin/rsyslogd -n
             ├─abrtd.service 
             │ └─153 /usr/sbin/abrtd -d -s
             ├─firewalld.service 
             │ └─144 /usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid
             ├─systemd-userdbd.service 
             │ ├─ 950 /usr/lib/systemd/systemd-userdbd
             │ ├─1414 systemd-userwork
             │ ├─1415 systemd-userwork
             │ └─1416 systemd-userwork
             ├─console-getty.service 
             │ └─233 /sbin/agetty -o -p -- \u --noclear --keep-baud console 115200,38400,9600 xterm-256color
             ├─sssd.service 
             │ ├─149 /usr/sbin/sssd -i --logger=files
             │ ├─180 /usr/libexec/sssd/sssd_be --domain implicit_files --uid 0 --gid 0 --logger=files
             │ └─192 /usr/libexec/sssd/sssd_nss --uid 0 --gid 0 --logger=files
             ├─systemd-resolved.service 
             │ └─135 /usr/lib/systemd/systemd-resolved
             ├─systemd-logind.service 
             │ └─1431 /usr/lib/systemd/systemd-logind
             └─abrt-oops.service 
               └─175 /usr/bin/abrt-dump-journal-oops -fxtD

benyaminl avatar Feb 18 '21 13:02 benyaminl