can't connect to WSL2 after after executing wsl several times - windows-subsystem-for-linux

Environment
Windows10 home
▼WSL info
//Powershell
> wsl -l -v
NAME STATE VERSION
* Ubuntu-18.04 Running 2
▼.wslconfing setting
set .wslconfig file on C:\Users\ {username}
[wsl2]
memory=8GB
localhostForwarding=true
Problem
▼ at first after running docker in WSL
・
・
・
web_1 | => Booting Puma
web_1 | => Rails 6.0.3 application starting in development
web_1 | => Run `rails server --help` for more startup options
web_1 | [Simple Form] Simple Form is not configured in the application and will use the default values. Use `rails generate simple_form:install` to generate the Simple Form configuration.
web_1 | Puma starting in single mode...
web_1 | * Puma version: 5.1.1 (ruby 2.7.2-p137) ("At Your Service")
web_1 | * Min threads: 5
web_1 | * Max threads: 5
web_1 | * Environment: development
web_1 | * PID: 50
web_1 | * Listening on http://0.0.0.0:3000
web_1 | Use Ctrl-C to stop
・When I try to connect from browser "localhost:3000", timeout error
・Serch "hostname -I" in WSL, and connect from browser of this IP address, connected
▼ after executing server several times
・Can't connect "localhsot", and even IP address which is serched by "hostname -I" as well (timeout error)
Other
When I execute curl http://localhost:3000 in Powershell, I get error
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest]、WebExce
ption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

The question was some time ago but one workaround currently is to shutdown WSL via
wsl --shutdown
You can then open up your distro and starting your server as usual.
Voilá you should be able to connect now.
If you are using Docker make sure to close it, if it is configured to use the WSL 2 backend. After your distro is up and running again you can launch Docker as usual.
Some issues on GH you could also relate to:
https://github.com/microsoft/WSL/issues?q=is%3Aissue+is%3Aopen+connecting+localhost
EDIT:
make sure you have the latest WSL2 Kernel installed. Some issues are related to older Kernel versions. Current is 5.4.+
to get the Kernel updates automatically:
it is served by windows update if you check "include updates for other microsoft products"

Related

why lxc command gives me permission denied error?

I have some problem in executing command lxc. when i try without sudo i get the error:
$ lxc storage list
Error: Get http://unix.socket/1.0: dial unix /var/snap/lxd/common/lxd/unix.socket: connect: permission denied
when i try with sudo i get:
$ sudo lxc storage list
sudo: lxc: command not found
i don't understand the problem about permission and i cannot solve this type of issue. Any suggestion is appreciated
INFO: i'm runnign Debian 10 buster on a virtual machine, i installed lxd and lxc by:
$ sudo snap install lxd
$ sudo apt install lxc
modified PATH with:
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin:/snap/bin:/var/lib/snapd/snap/bin:/snap/bin/lxc:/snap/bin/lxd
i added my account to sudoers:
moro ALL=(ALL)ALL
if i run
$ su-
root#debian:~# lxc storage list
+---------+-------------+--------+--------------------------------------------+---------+
| NAME | DESCRIPTION | DRIVER | SOURCE | USED BY |
+---------+-------------+--------+--------------------------------------------+---------+
| default | | btrfs | /var/snap/lxd/common/lxd/disks/default.img | 14 |
+---------+-------------+--------+--------------------------------------------+---------+
As far as my understanding goes, lxc uses the lxc group, in which your $USER has to be. Thus everything should work as expected if you add your user to the lxc group, e.g. via
sudo adduser $USER lxd
This is mentioned without an example on the lxd page getting started under access control and with an example in this
nice tutorial for Ubuntu 16.04, which should be applicable to many other debian based OS.

minishift start using virtualbox on windows throws timeout error

I am trying to start minishift on my machine. It successfully creates minishift VM but throws time out error.
Configuration:
Minishift version: v1.34.0+f5db7cb
OS: Windows 10
Hypervisor: Virtual Box v6.0.10
PS C:\WINDOWS\system32> minishift start
-- Starting OpenShift cluster .......................................................................Error during 'cluster up' execution: Error starting the cluster. ssh command error:
command : /var/lib/minishift/bin/oc cluster up --image 'openshift/origin-${component}:v3.11.0' --public-hostname 192.168.99.100 --routing-suffix 192.168.99.100.nip.io --base-dir /var/lib/minishift/base
err : exit status 1
output : Getting a Docker client ...
Checking if image openshift/origin-control-plane:v3.11.0 is available ...
Pulling image openshift/origin-cli:v3.11.0
E0725 17:15:42.919928 5316 helper.go:173] Reading docker config from /home/docker/.docker/config.json failed: open /home/docker/.docker/config.json: no such file or directory, will attempt to pull image docker.io/openshift/origin-cli:v3.11.0 anonymously
Image pull complete
E0725 17:15:44.643860 5316 helper.go:173] Reading docker config from /home/docker/.docker/config.json failed: open /home/docker/.docker/config.json: no such file or directory, will attempt to pull image docker.io/openshift/origin-node:v3.11.0 anonymously
Pulling image openshift/origin-node:v3.11.0
Pulled 5/6 layers, 85% complete
Pulled 6/6 layers, 100% complete
Extracting
Image pull complete
Checking type of volume mount ...
Determining server IP ...
Using public hostname IP 192.168.99.100 as the host IP
Checking if OpenShift is already running ...
Checking for supported Docker version (=>1.22) ...
Checking if insecured registry is configured properly in Docker ...
Checking if required ports are available ...
Checking if OpenShift client is configured properly ...
Checking if image openshift/origin-control-plane:v3.11.0 is available ...
I0725 17:16:20.775520 5316 config.go:40] Running "create-master-config"
Starting OpenShift using openshift/origin-control-plane:v3.11.0 ...
I0725 17:16:31.108342 5316 config.go:46] Running "create-node-config"
I0725 17:16:35.237968 5316 flags.go:30] Running "create-kubelet-flags"
I0725 17:16:36.785234 5316 run_kubelet.go:49] Running "start-kubelet"
I0725 17:16:37.288388 5316 run_self_hosted.go:181] Waiting for the kube-apiserver to be ready ...
E0725 17:21:37.300062 5316 run_self_hosted.go:571] API server error: Get https://192.168.99.100:8443/healthz?timeout=32s: dial tcp 192.168.99.100:8443: connect: connection refused ()
Error: timed out waiting for the condition
Expected result: It should provide me without errors link to open web console
This happens to me sometimes too.
Solutions include:
minishift stop && minishift start (turn it off and on again)
restart Windows (perhaps VBox has corrupted itself again)
More info on my minishift setup is here:
http://divby0.blogspot.com/2019/07/configuring-minishift-for-use-with.html
For what it's worth I use a combination of linux shells in Windows 10 to interact with minishift / docker daemon:
Git Bash (usually the best)
Docker Toolbox (plan B when something won't run in Git Bash shell)
WSL (ubuntu based, plan C in desperation)

How check the httpd is enabled and running using InSpec with Kitchen-docker on CentOS?

Running my test with InSpec I am unable to test if the httpd is enabled and running.
InSpec test
describe package 'httpd' do
it { should be_installed }
end
describe service 'httpd' do
it { should be_enabled }
it { should be_running }
end
describe port 80 do
it { should be_listening }
end
The output for kitchen verify is:
System Package
✔ httpd should be installed
Service httpd
✖ should be enabled
expected that `Service httpd` is enabled
✖ should be running
expected that `Service httpd` is running
Port 80
✖ should be listening
expected `Port 80.listening?` to return true, got false
Test Summary: 1 successful, 3 failures, 0 skipped
Recipe for httpd installation:
if node['platform'] == 'centos'
# do centos installation
package 'httpd' do
action :install
end
execute "chkconfig httpd on" do
command "chkconfig httpd on"
end
execute 'apache start' do
command '/usr/sbin/httpd -DFOREGROUND &'
action :run
end
I do not know what I am doing wrong.
More info
CentOS version on docker instance
kitchen exec --command 'cat /etc/centos-release'
-----> Execute command on default-centos-72.
CentOS Linux release 7.2.1511 (Core)
Chef version installed in my host
Chef Development Kit Version: 1.0.3
chef-client version: 12.16.42
delivery version: master (83358fb62c0f711c70ad5a81030a6cae4017f103)
berks version: 5.2.0
kitchen version: 1.13.2
UPDATE 1: Kitchen yml with driver attributes
The platform has the configuration recommended by coderanger :
---
driver:
name: docker
use_sudo: false
provisioner:
name: chef_zero
verifier: inspec
platforms:
- name: centos-7.2
driver:
platform: rhel
run_command: /usr/lib/systemd/systemd
provision_command:
- /bin/yum install -y iniscripts net-tools wget
suites:
- name: default
run_list:
- recipe[apache::default]
verifier:
inspec_tests:
- test/integration
attributes:
And it is the output when run kitchen test:
... some docker steps...
Step 16 : RUN echo ssh-rsa\ AAAAB3NzaC1yc2EAAAADAQABAAABAQDIp1HE9Zbtl3zAH2KKL1mVzb7BU1WxK7mi5xpIxNRBar7EZAAzxi1pVb1JwUXFSCVoAmUyfn/lBsKlgXnUD49pKrqkeLQQW7NoG3uCFiXBUTof8nFVuLYtw4CTiAudplyMvu5J7HQIP1Hve1caY27tFs/kpkQaXHCEuIkqgrM2rreMKK0n8im9b36L2SwWyM/GwqcIS1z9mMttid7ux0\+HOWWHqZ\+7gumOauh6tLRbtjrm3YYoaIAMyv945MIX8BFPXSQixThBVOlXGA9iTwUZWjU6WvZThxVFkKPR9KZtUTuTCT7Y8\+wFtQ/9XCHpPR00YDQvS0Vgdb/LhZUDoNqV\ kitchen_docker_key >> /home/kitchen/.ssh/authorized_keys
---> Using cache
---> c0e6b9e98d6a
Successfully built c0e6b9e98d6a
d486d7ebfe000a3138db06b1424c943a0a1ee7b2a00e8a396cb8c09f9527fb4b
0.0.0.0:32841
Waiting for SSH service on localhost:32841, retrying in 3 seconds
Waiting for SSH service on localhost:32841, retrying in 3 seconds
Waiting for SSH service on localhost:32841, retrying in 3 seconds
Waiting for SSH service on localhost:32841, retrying in 3 seconds
.....
You cannot, at least not out of the box. This is one area where kitchen-docker shows its edges. We try to pretend that a container is like a tiny VM but in reality it isn't, and one notable place where the pretending breaks down is init systems. With CentOS 7, it uses systemd. It is possible to get systemd to run inside the container (see https://github.com/poise/yolover-example/blob/master/.kitchen.yml#L17-L33) but not all features are supported and it can generally be a bit odd :-/ That example should be enough to make your tests work though. For completeness, CentOS 6 uses Upstart which just flat out won't run inside Docker so no love there either.

ROR + A server is already running. Check .../tmp/pids/server.pid. Exiting

In my Rails Project, I am trying to run two different servers at different port. But it fails by giving this error at console.
C:\Rails>rails s
=> Booting Mongrel
=> Rails 3.1.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
A server is already running. Check C:/Rails/tmp/pids/server.pid.Exiting
Please check the updated answer.
After googling a lot, I just delete that file and restart the server. Then again system create that file, then again I delete that file. Now Server is running fine. And System generates another copy at the same place. But it is running well.
DELETE THAT FILE ....
If you want to run two servers then it may again create trouble. So
Both commands are checking the default PID file location (tmp/pids/server.pid), so you're seeing this error. Try running multiple servers like so:
Server 1: bundle exec rails s
Server 2: bundle exec rails s -p 3001 -P tmp/pids/server2.pid
Credit: https://stackoverflow.com/a/14446920/1376448
Thanks
UPDATE after Connor Leech comment about Forman Gem
Foreman can help manage multiple processes that your Rails app depends
upon when running in development. It also provides an export command
to move them into production.
You can use netstat to know which process is holding the rails webserver, then you can kill the pid and start it over again, assuming that for some weird reason the server is not responding or running in background and you don't find another way to restart it..
netstat -plntu | grep 3000
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 7656/ruby
The last column shows the PID and the process name, then you only need to do:
kill -9 7656
and rails s to get it working again...
Hope it's useful
I find myself coming back to this webpage a lot to find the lsof -wni tcp:3000 command so I've found this method to be easier.
If you get this message:
A server is already running. Check /Users/username/project/tmp/pids/server.pid.
Exiting
And if you're running on a unix system (mac or linux) you can run these commands:
$ cat /Users/username/project/tmp/pids/server.pid
# output
71030
# Kill the process
$ kill -9 71030
Then run your server again!
I deleted the file with cd'ing in to the tmp directory then removing the file
rm server.pid
Then I restarted the server and I got this error
Exiting/Users/josephmellin/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:206:in `bind': Address already in use - bind(2) for 0.0.0.0:3000 (Errno::EADDRINUSE)
Then I could use the following command to see which process is running.
sudo lsof -iTCP -sTCP:LISTEN -P | grep :3000
And after I entered my password, I got this resoponse
ruby 2786 josephmellin 12u IPv4 0xfeadd8ae849eaec9 0t0 TCP *:3000 (LISTEN)
And then killed the process with the following command
KILL -9 2786
And then restarted the server (you will have a different number than 2786 - I left it here for demo purposes)
Step 1: remove .pid
C:/Rails/tmp/pids/server.pid.Exiting
# IN linux/unix shell
$ rm -rf <path to file>
Sometime this doesn't solve the problem, then you have to kill the process running by localhost, for such cases, follow STEP 2
STEP 2: List the process for localhost and kill it
# For Linux/Unix shell
$ lsof -wni tcp:3000
# output
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ruby 5946 rails 11u IPv4 79073 0t0 TCP *:3000 (LISTEN)
ruby 5946 rails 12u IPv4 103786 0t0 TCP 127.0.0.1:3000->127.0.0.1:53612 (ESTABLISHED)
# Kill the running process
$ kill -9 5946
run your server again
rails server
ps aux | grep rails
or
bundle exec rails s -p 3001 -P tmp/pids/server2.pid
Every instance of a RoR server creates a PID file. By default it is
#{Rails.root}/tmp/pids/server.pid
and if that file already exists it will refuse to start a new server.
To run more than one server of the same project on the same machine you should manually specify the PID file name for each instance of the server (I recommend simply appending a hyphen and the port number) using the -P option:
rails s -p 1234 -P tmp/pids/server-1234.pid
I'm told in some cases you may need to supply a full (rather than relative) path, but I don't know what those cases are.
You can see the PID for each proccess(the first column) :
ps vax | grep rails
// OR: ps auxw | grep rails
5236 pts/1 Sl+ 1:46 2 0.2 /usr/bin/ruby1.9.1 script/rails s -p 3001
5298 pts/2 Sl+ 0:12 2 0.7 /usr/bin/ruby1.9.1 script/rails s -p 3003
7356 pts/5 Sl+ 0:09 2 0.9 /usr/bin/ruby1.9.1 script/rails s -p 3002
7846 pts/3 Sl+ 0:19 2 1.7 /usr/bin/ruby1.9.1 script/rails s
Then kill the server:
kill -9 <pid>
To kill all running apps with "rails" in the name:
killall -9 rails
Use rails default commands, for example:
rake tmp:clear
Works for me, and really simple. ;)
single line command, that will take care of it.
kill -9 $(more C:/Rails/tmp/pids/server.pid)
I just had this problem, just deleted server.pid file and server works fine!
Remove that file: C:/Rails/tmp/pids/server.pid
A simpler way in which I found lesser commands . Go to the path which says a server is running in your folder structure . Search for the file. On the file itself shows a number which is the process id that is currently running. Lets say if the number is 'x', then simply type this command into your terminal
kill -9 x
However, note that this works in Ubuntu. Not sure, if it works in other OS as well.
Try to change the number in the pid file to another and save it.

"node with name "rabbit" already running", but also "unable to connect to node 'rabbit'"

Rabbitmq server does not start, saying it's already running:
$: rabbitmq-server
Activating RabbitMQ plugins ...
0 plugins activated:
node with name "rabbit" already running on "android-d1af002161676bee"
diagnostics:
- nodes and their ports on android-d1af002161676bee: [{rabbit,52176},
{rabbitmqprelaunch2254,
59205}]
- current node: 'rabbitmqprelaunch2254#android-d1af002161676bee'
- current node home dir: /Users/Jordan
- current node cookie hash: ZSx3slRJURGK/nHXDTBRqQ==
But, rabbitmqctl seems to think otherwise:
rabbitmqctl -n rabbit status
Status of node 'rabbit#android-d1af002161676bee' ...
Error: unable to connect to node 'rabbit#android-d1af002161676bee': nodedown
diagnostics:
- nodes and their ports on android-d1af002161676bee: [{rabbit,52176},
{rabbitmqctl2462,59256}]
- current node: 'rabbitmqctl2462#android-d1af002161676bee'
- current node home dir: /Users/Jordan
- current node cookie hash: ZSx3slRJURGK/nHXDTBRqQ==
Any takers?
The rabbitmq server was running somewhere but it just couldn't be connected to.
One of the following will mention something about rabbits:
$: ps aux | grep epmd
$: ps aux | grep erl
Kill the process with kill -9 {pid of rabbitmq process}
i was having the same problem then I realized I was not issuing the right command.
./rabbitmqctl stop
this works everytime, although it does take down erlang runtime too. also mind where your config file.
I used rabbitmqctl stop and then restarted using rabbitmq-server as root.
This issue can be caused by two issues:
Rabbit is already running on the server. If that is the case, use the answer you found of killing the currently running process (ps aux | grep rabbit | grep -v grep)
You have changed the IP address of your machine but not changed the /etc/hosts file to reflect the new IP address of the machine.
The more common of the issues is the first, but the harder to find is the second (especially if you have rabbit running on the other machine. If rabbit is installed on the other machine it will look at the old IP address and would see another machine already running rabbitmq and give you the same error. This has caused me grief in the past.
I was having this same error # Win 7, but the solutions above did not worked for me, what did solved was to remove and reinstall the service. Using a console with admin rights:
rabbitmq-service remove
rabbitmq-service install
I hope this might help someone else too
$CD RabbitMQ Server\rabbitmq_server-3.7.8\sbin
rabbitmq-service remove
rabbitmq-service install
Go : windows Services
Find : RabbitMQ and Start it
after this Enable plugin :
rabbitmq-plugins enable rabbitmq_management
In my case under Ubuntu 11.10 it helped to
#rabbitmqctl cluster MASTER SLAVE
#rabbitmqctl start_app
before I always got this error message...
Using admin console, in Win 2012R2 ver 3.5.5 rabbit, got it to work using the remove and install then rabbitmq-server restart
then ctr-c to terminate the job, then I was able to use the windows service console and start the rabbitMq service.
In my case(windows),
1. I just ran the stop service.
2. The started the service.