Sinatra not binding to right port - sinatra

I'm using Openshift and Sinatra to host my website. But it's not binding to the right port.
set :port, ENV["OPENSHIFT_RUBY_PORT"]
set :port, ENV["OPENSHIFT_RUBY_IP"]
...
puts ENV["OPENSHIFT_RUBY_PORT"]
puts settings.port
puts ENV["OPENSHIFT_RUBY_IP"]
puts settings.bind
This returns the correct output. But when the server actually starts...
Listening on localhost:9292, CTRL+C to stop
The error:
no acceptor (port is in use or requires root privileges) (RuntimeError)
How do I get it to bind to the right port?

set :port, ... sets the port for Sinatra’s builtin server, but you are using rackup, so this setting is not used (9292 is the default port for Rack).
You can use the -p or --port options to rackup to set the port. From the command line you can do:
$ bundle exec rackup -p $OPENSHIFT_RUBY_PORT
You can also specify command line options in the first line of the config.ru, but I don’t think you can specify environment variables there.
If you want to avoid specifying the port on the command line, you may need to create a wrapper script that reads the environment variables and calls rackup.

Related

logging into a specific hpc node from jupyter notebook in VS code

I work on an HPC where we have a login node to login and then we can ask for a specific amount of computing resources which will then be allocated on compute node. We cannot run our programs in login node since it is shared. Currently, if we want to run jupyter on the compute node, we have to ssh into the compute node and forward the port.
Is there any way to ssh into compute node so that we can run the jupyter notebook from vs code itself? If I run it directly it will run in login node which is a problem.
You can ssh into a compute node that is accessible through a login node by setting up your VSCode ssh config file such that your login node is a ProxyJump and your compute node the host you want to ssh to.
If you would log in to your login node as ssh username#ip.of.login.node, and from the login node, you can ssh to the compute node as ssh ip.of.compute.node, then you can set up your config file as such:
Host loginnode
HostName ip.of.login.node
User meulemeester
Host computenode
HostName ip.of.compute.node
User meulemeester
ProxyCommand ssh -vv -W %h:%p <ip.of.login.node>
# -W flag is necessary to redirect stdin and stdout
# %h:%p is hostname and portname. Host refers to ProxyJump (i.e. loginnode), port is 22 by default
ProxyJump loginnode
Make sure that this config file is the file used when running ssh. Check the VSCode setting Remote.SSH: config file to see if it points to this config file. Instead of using the IPs fo the login node or compute node, you can also use the host names directly (i.e. anything you would put after the # when ssh'ing).
Depending on the authorisation methods, you may want to add additional parameters to the config file. The given setup works if the host has the public key of the local machine stored under ~/.ssh/authorized_keys.
The compute node should now be available as an option when you want to connect to a host in VSCode.

Docker dotnet run port not mapping, windows 10 host, linux container

I'm following a https://app.pluralsight.com/library/courses/docker-web-development/table-of-contents which uses the older microsoft/aspnetcore-build image but I'm running core 2.1 so I'm using microsoft/dotnet:2.1-sdk instead.
The command I'm running is:
docker run -it -p 8080:5001 -v ${pwd}:/app -w "/app"
microsoft/dotnet:2.1-sdk
and then once inside the TTY I do a dotnet run which gives me the following output:
Using launch settings from /app/Properties/launchSettings.json...
info:
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using '/root/.aspnet/DataProtection-Keys'
as key repository; keys will not be encrypted at rest.
info:
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[58]
Creating key {5445e854-c1d9-4261-82f4-0fc3a7543e0a} with creation date
2018-12-14 10:41:13Z, activation date 2018-12-14 10:41:13Z, and
expiration date 2019-03-14 10:41:13Z.
warn:
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key
{5445e854-c1d9-4261-82f4-0fc3a7543e0a} may be persisted to storage in
unencrypted form.
info:
Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[39]
Writing data to file
'/root/.aspnet/DataProtection-Keys/key-5445e854-c1d9-4261-82f4-0fc3a7543e0a.xml'.
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to bind to https://localhost:5001 on the IPv6 loopback
interface: 'Cannot assign requested address'.
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to bind to http://localhost:5000 on the IPv6 loopback
interface: 'Cannot assign requested address'.
Hosting environment: Development
Content root path: /app
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
Then, when I open browser on my host and navigate to http://localhost:8080 I get a "This page isn't working" "localhost didn't send any data" " ERR_EMPTY_RESPONSE"
I've tried a couple different port combinations too with the same result.
Can anyone spot where I went wrong? Or have any ideas / suggestions?
Not sure if this question still relevant for you, but I also encountered this issue and left my solution here for others. I used PowerShell with the next docker command (almost the same as your command, just used internal port 90 instead of 5000 and used --rm switch which will automatically remove the container when it exits):
docker run --rm -it -p 8080:90 -v ${pwd}:/app -w "/app" microsoft/dotnet /bin/bash
And after that, I got the interactive bash shell, and when typing dotnet run I got the same output as you and cannot reach my site in the container via localhost:8080.
I resolved it by using UseUrls method or --urls command-line argument. They (UseUrls method or --urls command-line argument) indicates the IP addresses or host addresses with ports and protocols that the server should listen on for requests. Below descriptions of solutions which worked for me:
Edit CreateWebHostBuildermethod in Program.cs like below:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("http://+:90") //for your case you should use 5000 instead of 90
.UseStartup<Startup>();
You can specify several ports if needed using the next syntax .UseUrls("http://+:90;http://+:5000")
With this approach, you just typed dotnet run in bash shell and then your container will be reachable with localhost:8080.
But with the previous approach you alter the default behavior of your source code, which you can forget and then maybe should debug and fix in the future. So I prefer 2nd approach without changing the source code. After typing docker command and getting an interactive bash shell instead of just dotnet run type it with --urls argument like below (in your case use port 5000 instead of 90):
dotnet run --urls="http://+:90"
In the documentation there is also a 3rd approach where you can use ASPNETCORE_URLS environment variable, but this approach didn't work for me. I used the next command (with -e switch):
docker run --rm -it -p 8080:90 -v ${pwd}:/app -w "/app" -e "ASPNETCORE_URLS=http://+:90" microsoft/dotnet /bin/bash
If you type printenv in bash you will see that ASPNETCORE_URLS environment variable was passed to the container, but for some reason dotnet run is ignoring it.

MongoDB cannot remote access

I'm new to linux server. I install mongodb on centos 6.3. And I run the mongodb server in this command:
mongod -config /etc/mongodb.conf &
And i'm sure that I have make bind_ip to listen all ip:
# mongodb.conf
# Where to store the data.
dbpath=/var/lib/mongodb
#where to log
logpath=/var/log/mongodb/mongodb.log
logappend=true
rest = true
bind_ip = 0.0.0.0
port = 27017
But, I cannot make mongodb remote access either. my server ip is 192.168.2.24,and I run mongo in my local pc to access this mongodb, it show me this error:
Error: couldn't connect to server 192.168.2.24:2701
7 (192.168.2.24), connection attempt failed at src/mongo/shell/mongo.js:148
exception: connect failed
But, I can access this mongodb in server where mongodb install using this command:
mongo --host 192.168.2.24
So, I think it may success to make mongo remote access, but maybe something wrong with linux server,maybe firewall? So,I try to use the command to check the port whether open for remote access:
iptables -L -n | grep 27017
nothing is returned, then I add port to iptalbes using this command:
iptables -A INPUT -p tcp --dport 27017 -j ACCEPT
iptables -A OUTPUT -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT
and save the iptables & restart it:
iptables-save | sudo tee /etc/sysconfig/iptables
service iptables restart
I can see port of 27017 is added to iptables list, but it still not work at all. I think it may not success in opening the port of 27017. How should I do for it? I'm new to linux server,by the way my linux server pc is offline. So it can't use the command about "yum". please give me solution in detail. Thanks so much.
It seems like the firewall is not configured correctly.
Disclaimer: Fiddling with firewall settings has security implications. DO NOT USE THE FOLLOWING PROCEDURE ON PRODUCTION SYSTEMS UNLESS YOU KNOW WHAT YOU ARE DOING!!! If in the slightest doubt, get back to a sysadmin or DBA.
The problem
Put simply, a firewall limits the access to services like MongoDB running on the protected machine by unauthorized parties.
CentOS only allows access to ssh by default. We need to configure the firewall so that you can access the MongoDB service.
The solution
We will install a small tool provided by CentOS < 7 (version 7 provides different means), which simplifies the use of iptables, which in turn configures netfilter, the framework of the Linux kernel allowing manipulation of network packets – thus providing firewall functionality (amongst other cool things).
Then, we will use said tool to configure the firewall functionality so that MongoDB is accessible from everywhere. I can't give you a more secure configuration, since I do not know your network setup. Again, use this procedure on production systems at your own risk. You have been warned!
Installation of system-config-firewall-tui
First, you have to log into your CentOS box as root, which allows installation and deinstallation of packages and change system-wide configurations.
Then, you need to issue (the dollar sign denotes the shell prompt)
$ yum -y install system-config-firewall-tui
The result should look something like this
Configuration of the firewall
Next, you need to start the tool we just installed
$ system-config-firewall-tui
which will create a small command line GUI:
Do not simply disable the firewall!.
Press Tab or →| respectively, until the "Customize" button is highlighted. Now press ↵. In the next screen, highlight "Forward" and press ↵. You now should be in a screen called "Other Ports",
in which you highlight "Add" and press↵. This brings you to a screen "Port and Protocol" which you fill like shown below
The configuration explained: MongoDB uses TCP for communicating with the clients and it listens on port 27017 by default for a standalone instance. Note that you might need to change the port according to the referenced list in case you do not run a standalone instance or replica set.
The next step is to highlight "OK" and press ↵, which will seemingly clear the inputs. However, the configuration we just made is saved. So we will press "Cancel" and return to the "Other Ports" screen, which should now look like this:
Now, we press "Close" and return to the main screen of "system-config-firewall-tui". Here, we press "Ok" and the tool asks you if you really want to apply those the changes you just made. Take the time to really think about that. ;)
Pressing "Yes" will now modify the firewall rules executed by the Linux kernel.
We can verify that by issuing
$ iptables -L -n | grep 27017
which should result in the output below:
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:27017
Now you should be able to connect to your MongoDB server.

can port of a cq instance be set in terminal

their is an option for setting run mode of a CQ Instance directly in terminal
viz -Dsling.run.modes=${CQ_RUNMODE}
is their a similar option for changing the port as well.
I'm basically looking for a solution to keep changing name of CQ jar for a new instance.
Thanks
-p option can be used to set the port number from command line.
Ex: java -jar cq5-4502.jar -p 4503 will start the instance on 4503 even though the jar name contains 4502 as the port number.

Padrino development host

How can I specify a default host and port for Padrino?
Normally I could start my process like this:
padrino start -h myhost
I want to change the default parameters of start. I expected that to be done by editing the config/apps.rb to:
Padrino.mount('MyApp::App', :app_file => Padrino.root('app/app.rb')).to('/').host('myhost')
However with the above line, Rackup still starts listening only on 'localhost'. So I assume that the host() option does not have an effect on Rack at all.
Ideally I would like to set the port/host just for "development" mode, but I cannot find the place where that setting is handed down to the rackup/webrick server.
These options are now defaulted to 127.0.0.1 for security and paranoid reasons.
To rackup here: https://github.com/rack/rack/blob/28b014484a8ac0bbb388e7eaeeef159598ec64fc/lib/rack/server.rb#L187
To padrino s here https://github.com/padrino/padrino-framework/blob/5fe35ccbd2ffbf78d78233e9a47759eff1c6cc92/padrino-core/lib/padrino-core/cli/base.rb#L16
Considering your desire to host development mode app on local Ethernet, you have a dedicated server and you should have no problem setting up something like Passenger to host your app.
BTW, version 1.5.2 of rack still hosts the config.ru on 0.0.0.0, if you are locked on this version you can use rackup to host your development app for local network.