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

Can't start a service #20

Closed
branchard opened this issue May 13, 2018 · 25 comments
Closed

Can't start a service #20

branchard opened this issue May 13, 2018 · 25 comments

Comments

@branchard
Copy link

branchard commented May 13, 2018

I'm trying to start nginx service like this:

systemctl start nginx

but i get the following error:

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

I know that WSL currently uses a proprietary init process, but I don't know how to use it to start/restart/stop services.

It's also interesting to note that with Ubuntu WSL the command service nginx start works fine. Is it possible to do the same thing with Arch WSL ?

@branchard
Copy link
Author

I finally got nginx started 🎉

I just opened the nginx service file (\usr\lib\systemd\system\nginx.service) and run the command at the line that contains ExecStart:

/usr/bin/nginx -g 'pid /run/nginx.pid; error_log stderr;'

It's probably possible to make a script that run services this way automatically.

@ScriptSmith
Copy link

microsoft/WSL#1579

WSL does not support systemd / an init system, so you cannot use services. You have to run the commands yourself.

@grzekru
Copy link

grzekru commented Jun 4, 2018

It seems to be possible in Debian WSL.

image

@yuk7
Copy link
Owner

yuk7 commented Jun 4, 2018

We can't use service command on Arch Linux,because Arch Linux doesn't supports openrc,.
Arch Linux designed for use systemd.
but you can install openrc from AUR,probably you can use rc-* command for control services.

@mithunpp4u
Copy link

i m getting below error when i run
'systemctl start postgresql '

please help me...

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

@mithunpp4u
Copy link

@yuk7

Sir i m a newbie ,
And when i exicute run /usr/bin/postgres -D /usr/pgsql/data

I m getting, bash: run command not found

@yuk7
Copy link
Owner

yuk7 commented Jun 23, 2018

@mithunpp4u
excute this line↓
postgres -D /usr/local/pgsql/data

@imbavirus
Copy link

imbavirus commented Jun 28, 2018

I'm currently using batch scripts in the windows startup folder as an alternative, for example:

bash <environment variables of service> <ExecStart of service>

Could probably even configure it to launch as a windows service somehow to have auto restart and stopping working correctly

@imbavirus
Copy link

I wasn't mentioning an issue @yuk7 , was merely offering a temporary workaround until the problem is fixed.

@unixfox
Copy link

unixfox commented Oct 15, 2018

I couldn't get working OpenRC so I used Supervisor which is working great for automatically starting my services and managing it.

@ertwro
Copy link

ertwro commented Dec 4, 2018

I couldn't get working OpenRC so I used Supervisor which is working great for automatically starting my services and managing it.

I don't seem to be able to start cronie or crontab with supervisor, how would you add it to supervisor and start it @unixfox ?

@hdk5
Copy link

hdk5 commented Dec 4, 2018

People, who need to run services on Arch on WSL, might also be interested in runit and/or Artix.

I provide daily Artix for WSL builds on my repo, along with the simple script to start service supervisor right from Windows Powershell

@acomagu
Copy link

acomagu commented Jun 13, 2019

Replacing /init is safe?

@ertwro
Copy link

ertwro commented Jun 14, 2019

For anyone, still interested runit is pretty good. I even use it in my real arch linux machine. All you need to do is download runit-systemd. The services can be written with simple shell scripts that can run super fast if you use link dash to sh in arch. It's amazing.

@karuboniru
Copy link

Replacing /init is safe?

safe but not working at all---wsl will still use Microsoft's init

@PSzczepanski1996
Copy link

What about WSL2? I heard that there can be ported systemd by using fake namespacing or so?

@bimimicah
Copy link

You can work around the issues with systemctl by replacing it with this script by @gdraheim:
https://github.com/gdraheim/docker-systemctl-replacement/blob/master/files/docker/systemctl.py

just do the following (assumes /usr/bin/systemctl) :

mv /usr/bin/systemctl /usr/bin/systemctl.old
curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl
chmod +x /usr/bin/systemctl

@arlllk
Copy link

arlllk commented Sep 19, 2019

It's possible to bypass that in a hacky way using genie

@yuk7
Copy link
Owner

yuk7 commented Oct 23, 2019

I created systemctl alternative package and documented it.
If you use WSL2,you can use genie.
that's all we can do.

This is a common problem with container Linux and WSL.

@datdinhquoc
Copy link

You can work around the issues with systemctl by replacing it with this script by @gdraheim:
https://github.com/gdraheim/docker-systemctl-replacement/blob/master/files/docker/systemctl.py

just do the following (assumes /usr/bin/systemctl) :

mv /usr/bin/systemctl /usr/bin/systemctl.old
curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl
chmod +x /usr/bin/systemctl

Thanks, i can confirm this script is working, i have my systemctl now :)

@chaitanyarahalkar
Copy link

microsoft/WSL#1579

WSL does not support systemd / an init system, so you cannot use services. You have to run the commands yourself.

I don't get it. If you use the Ubuntu image from the Microsoft Store, it ships with Systemd. No idea why it does not work with this Arch distro!

@maphew
Copy link

maphew commented Sep 27, 2021

I created systemctl alternative package and documented it.

The document link in comment #20 (comment) is broken. From some looking around this might be the next/newest info:
https://wsldl-pg.github.io/ArchW-docs/Known-issues/#systemdsystemctl

@barcellos-pedro
Copy link

You can work around the issues with systemctl by replacing it with this script by @gdraheim: https://github.com/gdraheim/docker-systemctl-replacement/blob/master/files/docker/systemctl.py

just do the following (assumes /usr/bin/systemctl) :

mv /usr/bin/systemctl /usr/bin/systemctl.old
curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl
chmod +x /usr/bin/systemctl

That worked for me! Thanks!

@snowman
Copy link

snowman commented Mar 30, 2022

You can work around the issues with systemctl by replacing it with this script by @gdraheim: https://github.com/gdraheim/docker-systemctl-replacement/blob/master/files/docker/systemctl.py
just do the following (assumes /usr/bin/systemctl) :

mv /usr/bin/systemctl /usr/bin/systemctl.old
curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl
chmod +x /usr/bin/systemctl

That worked for me! Thanks!

You need to install python2 first

$ sudo pacman -Syuu
$ sudo pacman -S python2
$ sudo mv /usr/bin/systemctl /usr/bin/systemctl.old
$ sudo curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py -o /usr/bin/systemctl
$ sudo chown root /usr/bin/systemctl
$ sudo chgrp root /usr/bin/systemctl
$ sudo chmod +x /usr/bin/systemctl

@muhimron90
Copy link

You can work around the issues with systemctl by replacing it with this script by @gdraheim: https://github.com/gdraheim/docker-systemctl-replacement/blob/master/files/docker/systemctl.py

just do the following (assumes /usr/bin/systemctl) :

mv /usr/bin/systemctl /usr/bin/systemctl.old
curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl
chmod +x /usr/bin/systemctl

its worked, thanks a lot sir , savior !
systemctl_solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests