Padrino development host - sinatra

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.

Related

Receiving ERR_CONNECTION_REFUSED after Sinatra deployment on Digital Ocean

Having a problem with deployment of a small Sinatra app that works fine locally, and seems like its running on digital ocean, but can't be hit via the domain name. The following is the message I receive:
This webpage is not available
Error code: ERR_CONNECTION_REFUSED
The following is what's displayed on my droplet using rackup -p 80, which to me indicates it should be able to be hit:
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on localhost:80, CTRL+C to stop
If it makes any difference, I also cannot hit the ip address directly. Anyone encounter similar problems or possibly a solution? The app is on ubuntu uses psql as a database. It would be greatly appreciated. Thanks!
Bind your app on 0.0.0.0 instead of localhost:
ruby your_app.rb -o 0.0.0.0
or
rackup --host 0.0.0.0
In production, you should setup a reverse proxy (eg. using nginx or apache) to bind a domain to your app internal port insteal of opening everything on 0.0.0.0

How to get MONGO_URL from command line Meteor Up deployment?

I am currently deploying to Digital Ocean using Meteor Up. If I don't specify a MONGO_URL in the mup.json, can I get the value from the command line while the website is running, i.e. I don't want to shutdown the site?
If I go to the app directory and run meteor mongo --url, I get the following error:
mongo: Meteor isn't running a local MongoDB server.
This command only works while Meteor is running your application
locally. Start your application first. (This error will also occur if
you asked Meteor to use a different MongoDB server with $MONGO_URL when
you ran your application.)
If you're trying to connect to the database of an app you deployed
with 'meteor deploy', specify your site's name with this command.
Even if I run the app from the app directory, it will only give the localhost MONGO_URL. I need the MONGO_URL for the deployed app.
I have also taken a look at a similar question as suggested by some of the answers. I disagree that it is "impossible" to get the MONGO_URL without some other program running on the server. It's not as if we are defying the laws of physics here, folks. Fundamentally, there should be a way to access it. Just because no one has yet figured it out doesn't mean it is impossible.
meteor mongo --url should return the URL.
Try opening another shell in the app directory and running that command.
Meteor Up packages your app in production mode with meteor build so that it runs via node rather than the meteor command line interface. Among other things, this means meteor foo won't work on the remote server (at least not by default). So what you're really looking for is a way to access mongo itself remotely.
I recently set up mongo on an AWS EC2 instance and listed some lessons learned here: https://stackoverflow.com/a/28846703/2669596. Some details of how you do it are going to be different on Digital Ocean, but these are the main things you have to take care of once mongo itself is installed:
Public IP/DNS Address: This is probably fine already since you can deploy to the server.
Port Security Rules: You need to make sure port 27017 is open for TCP access, at least from your IP address. MongoDB also has an http interface you can set up; if you want to use that you'll need to open 28017 as well.
/etc/mongod.conf (file location may differ depending on Linux flavor):
Uncomment port=27017 to make sure you have the default port (I don't think this is actually necessary, but it made me feel better and it's good to know where to change the default port...).
Comment out bind_ip=127.0.0.1 in order to listen to external interfaces (e.g. remote connections).
Uncomment httpinterface=true if you want to use the http interface.
You may have to restart the mongod host via sudo service mongod restart. That's a problem if you can't have downtime, but I don't know of a way around that if you change the config file.
Create User: You need to create an admin and/or user to access the database remotely.
Once you've done all of that, you should be able to access the database from your local machine (assuming you have the mongo client installed locally) by running
mongo server.url.com:27017/mup-app-name -u username -p
where server.url.com is the URL or IP address of your remote server, mup-app-name is the appName parameter from your mup.json file, username is the user you created to access the database, and you'll be prompted for that user's password after you run the command (or you could put it after -p on the same line, depending on the password).
There may also be a way to do this by setting up nginx to reverse-proxy 127.0.0.1:27017 on your remote server, but I've never done it and that's just me speculating.

Google App Engine Java on Eclipse can not connect to localhost

Usage: [options]
Options:
--help, -h Show this help message and exit.
--server=SERVER The server to use to determine the latest
-s SERVER SDK version.
--address=ADDRESS The address of the interface on the local machine
-a ADDRESS to bind to (or 0.0.0.0 for all interfaces).
--port=PORT The port number to bind to on the local machine.
-p PORT
--sdk_root=DIR Overrides where the SDK is located.
--disable_update_check Disable the check for newer SDK versions.
--generated_dir=DIR Set the directory where generated files are created.
--jvm_flag=FLAG Pass FLAG as a JVM argument. May be repeated to
supply multiple flags.
I had come across similar problem while working with Google App Engine for Python-loalhost was not getting its connection established.
$fuser -k 8080/tcp
Try this in terminal/command prompt and restart localhost.
It worked for me. Hope it works for you also. Good luck!

Postgres.app configuration (port and other options)

I just installed Postgres.app on my Mac, and I need to make some specific configuration to server. For example I want to use different port, not 5432.
I found that it have postgresql.conf at ~/Library/Application\ Support/Postgres/var/postgresql.conf, but even if I change value of port = to something other, it listen on 5432 after server restart.
Seems that this postgresql.conf isn't used by Postgress.app. Where it stores server configuration files?
The postgresql.conf-file at ~/Library/Application\ Support/Postgres/var/ is used by Postgres.app. The only problem: if you change the port in that file, that change will not be reflected in the menu-bar. So the elephant over there will still say "Running on Port 5432", although postgres might be running on, for example, port 5433. (Mac OS X 10.8.2, Server.app 2.2, Postgres.app 9.2.2.0)
I can see the output from ps aux |grep post
/Applications/Postgres.app/Contents/MacOS/bin/postgres -D /Users/chenc26/Library/Application Support/Postgres/var -p5432
So I think there must be some config in this app to specify the CLI parameter which ignore the value from config file.
I'm running a Mavericks 10.9.3 and opening Postgres app v9.3 config via nano ~/Library/Application\ Support/Postgres/var-9.3/postgresql.conf and uncommenting the port = 5432 line, then changing it to, say, 5433 did the trick for me. (Restarting the app was required, as the config file mentions). Afterwards the app correctly displays that it is running on port 5433.
If correctly changing the content of postgresql.conf, then restarting the PostgreSQL server doesn't change the port it's listening on, you're almost certainly editing the wrong postgresql.conf.
On other platforms, PostgreSQL puts a copy of its default version of postgresql.conf in the data directory. So you're liable to find at least two copies of all the configuration files somewhere on your computer--usually one in the directory where the distribution or source was downloaded or uncompressed, and one in the data directory. On your Mac, if you're using version 9.1, the data directory might be
/Library/PostgreSQL/9.1/data/
Check for a postgresql.conf there. If you find one, consider making a copy of it to replace the one you edited. (So the one you edited will again be an unedited version.)
In 2022, I can't just edit the server.conf file. It looks like instead, I've had to do this from the GUI to change the port which the command line parameters refer to:
... bin/postgres -D /Users/MyUser/Library/Application Support/Postgres/var-11 -p 6543
The way I was able to make the change was to:
Open the Postgres elephant icon in the top bar.
Select "Open Postgres"
Stop the server.
Click on server settings.
Then, change the port in the simple input.
After this, start the server and find that the port has changed.
This works for the Postgres.app (version 11 on my desktop).

Using "http://localhost" instead of "http://xx.xx.xx.xx" on iPod on WAMP

I am running Windows 7 and use my iPod Touch to access my localhost sites for testing purposes on WAMP.
I can browse my localhost sites by navigating to my machine IP in Safari on my iPod like so: http://10.0.0.100
I would like to know if it is at all possible to use http://localhost instead, and how I can accomplish that.
Thank you very much!!
Basically, localhost refers to 127.0.0.1 refers to the loop back ip which is the ipod itself so it's not possible unless you change [localhost to resolve to machine IP which is in this case 10.0.0.100] in the (DNS / hosts file) your ipod is using to resolve domain names in your connection settings and I don't recommend that.
Following are the steps needed to change the hosts file in your ipod (I warned you already this is not a good thing unless you know what are you doing)
source: https://discussions.apple.com/thread/2801892?start=0&tstart=0
Simple solution:
the hostfile is located at: /etc/hosts
To edit this file you need to SSH into your device, If you know how to do this directly just use vi, or nano to edit the file. From windows use WinSCP to access the file system via FTP(SSH). Then simply navigate to /etc/hosts download the file to your desktop, right click and open it with note pad, add your resolver to the last line "192.168.0.100 testserver", save, and replace the original file with the new one.
/etc/host -- example config
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
192.168.0.100 testserver
*To SSH into an ipod it must have OpenSSH installed, usually this requires a jailbreak.