Maintenance mode in AWS EC2 - amazon-ec2

In heroku we could use the command heroku maintenance on or off... How can I do it in my AWS EC2 web services? I tried just to stop the server using sudo service nginx stop but I don't like the error page that was displayed. It says error in url. In heroku if i use the maintenance command, the error page will display "Under contruction" "Maintenance" or something like that.
How can I do it in Amazon web services? thanks

You have to do it yourself. AWS does not provide that.

Yeah, so heroku has routing magick, think of the default WebBrick server your rails app is running as running outside of rails. Idk, assuming you use passenger you would'nt really notice this but at a high level, nginx is proxying your apps' port 3000 to port 80 for certain requests. I appologize if you don't know what I mean by that.
So (YOUR APP) ---> (NGINX) -----> (Client)
the advantage here, is that nginx keeps running but during maintience mode they most likely start shooting you pages to static content. If you too run you rails app via a proxy rather than via passenger, than you solution is easy. Stop your WebBrick, mongrel, unicorn, thin (what ever app server here) and setup an error message page for bad gateway errors aka 502 route.
If you use passenger. You could write a location block, that would over ride all your routes to a maintence page and switch Passenger to off in that server block, now rather than serving your app you can serve a static maintence page.
Heroku wraps alot of technology and exposes nice tools, so you'll need to do a bit more ground work to automate your stack. But this is a place to start.

Related

Problem deploying nginx on heroku in front of server on Go

I want to deploy to heroku nginx as a reverse proxy in front of my Go application.
I made a config file for nginx, but its samples presented here https://github.com/heroku/heroku-buildpack-nginx do not give an understanding of which port to specify in the proxy_pass directive to redirect to my application. These examples use unix socket listening instead of http.
upstream app_server {
server unix: /tmp/nginx.socket fail_timeout = 0;
}
But my application is running over http.
In addition, heroku uses random ports, which the application must retrieve from the PORT environment variable. However, now I have set this variable in the config for nginx. What port should my application run on now? If you specify your own port, this will not work, since heroku will say that the port is already busy.
I am completely discouraged by the difficulty of deploying a simple environment for my heroku application. None of the heroku instructions give a comprehensive understanding of how this can be done.
Please guide me on the right path.
P.S. For a couple of days of searching for an answer, I found only a lot of questions similar to mine and not a single answer.
Update.
I did as in this post Springboot application with nginx as proxy deploy on Heroku
But the author did not explain what she set in the APP_PORT variable. I set it to 3001 and got the same thing as here:
Nginx and Heroku. Serving Static Files

How to deploy sinatra application on myown private server?

i am new to sinatra application. i developed my first application with sinatra. Now, i want to deploy this application on my own private server. My own private server is Linux server and all required config (i.e., ruby, sinatra, passenger ) installed.
So, i would like to know how to deploy it?
Here's our company's basic setup for Ruby microservices APIs:
1) Put your Ruby apps in a special folder
We like /srv/applications/
2) Choose a port for your application
Don't use the default port. I prefer ones in the 2000 series (E.g., 2000, 2010, 2020, ...) for Ruby apps.
3) Setup a reverse proxy to access your application on that port
Depending on your server, there are lots of Tutorials for Apache or Nginx.
That way /user-api will redirect to your port. Ex. myserver.com/user-api goes to myserver.com:2020
4) Run your application
If you're not using bundler, use bundle to run the app. To run on a specific port, use "bundle exec rackup -p "
You should then be able to access the application. If you run into trouble, some common problems include 1) the port is being blocked to the outside world, 2) you tried to access it before the app was running and now you still get 503s even though the app is running (restart your webserver to fix it).
Bonus - running your app as a Unix service
This has enormous benefits. If you can run the Ruby app with another supervisor level app, then you can automatically start it on reboot, automatically restart the app on failures (which can lead to flapping when you have catastrophic problems).
Originally we used Monit which is typically used for service monitoring but can actually start/stop/restart (start on boot) for a service.
Now we use foreman and upstart. I highly recommend this pairing, as app supervision is the textbook use case for Upstart. You can skip using Foreman if you have a vanilla configuration, but it is incredibly useful if you need to start other services, set environment variables, etc.

How do I go about setting up my Sinatra REST API on a server?

I'm an iOS developer primarily. In building my current app, I needed a server that would have a REST API with a couple of GET requests. I spent a little time learning Ruby, and landed on using Sinatra, a simple web framework. I can run my server script, and access it from a browser at localhost:4567, with a request then being localhost:4567/hello, as an example.
Here's where I feel out of my depth. I setup an Ubuntu droplet at DigitalOcean, and felt my way around to setting up all necessary tools via command line, until I could again run my server, now on this droplet.
The problem then is that I couldn't then access my server via droplet.ip.address:4567, and a bit of research lead me to discovering I need Passenger and an Apache HTTP Server to be setup, and not with simple instructions.
I'm way in over my head here, and I don't feel comfortable. There must be a better way for me to take my small group of ruby files and run this on a server, than me doing this. But I have no idea what I'm doing.
Any help or advice would be greatly appreciated.
bit of research lead me to discovering I need Passenger and an Apache HTTP Server to be setup, and not with simple instructions.
Ignore that for now. Take baby steps first. You should be able to run your Sinatra app from the command line on the DigitalOcean droplet, and then access it via droplet.ip.address:4567. If that doesn't work something very fundamental is wrong.
When you start your app, you will see what address and port the app is listening on. Make sure it's 0.0.0.0 and 4567. If it's 127.0.0.1 or localhost that means it will only service requests originating from the same machine
After you get this working, next step is to make your Sinatra app into a service. Essentially this means the app runs in the background, and auto-starts when the system reboots. Look into Supervisor which is very simple configuration to get this running.
Later you can install Apache or Nginx to put in front of your Sinatra app. These are proxies which simply forward requests from port 80 (default HTTP port) to your sinatra app, but can do additional things such as add SSL support, load balancing, custom error pages etc. - all of which you do not need right now.

allow others to see your Sinatra local server through amazon instance

It's really difficult to explain. But basically, I have an amazon instance, and I want to ssh into it and run a local server on it with sinatra. so I would ssh into the amazon instance, git clone my repo, and run ruby config.ru. Then I want someone else to be able to see that exact local server that is being ran. One of the things I've done is added a security group, port 4567 HTTP so that I can access it via public dns. It works on a rack app but it doesn't work on the sinatra, I've even tried a 'hello world' sample app to try to get it working.
I'm not sure if there is a specific reason that you want to do this from an Amazon server or not, but if you just want someone else to see your sinatra app, you could simply use localtunnel.
Using this, you can simply run localhost on your OWN computer, then run localtunnel PORTNUMBER and it will give you a URL that your app will now be visible from. You can then give that URL to anyone you want.
Example of use:
$ ruby myapp.rb
$ localtunnel 4567
A URL will then be displayed for you to copy-paste to a friend. Easy as that.
I use this a lot when developing web apps to be mobile friendly and want to quickly look at the app on my phone without having to deploy to a server.

Heroku Cedar and nginx (gzip)

According to the comments in the accepted answer here Rails how to Gzip Javascript? (Heroku) and the official cedar documentation (http://devcenter.heroku.com/articles/http-routing#the_herokuappcom_http_stack):
Since requests to Cedar apps are made directly to the application server – not proxied through an HTTP server like nginx – any compression of responses must be done within your application. For Rack apps, this can be accomplished with the Rack::Deflater middleware. For gzipped static assets, make sure that Rack::Deflater is loaded before ActionDispatch::Static in your middleware stack.
However, as far as I can tell, my app is running on herokuapp.com (cedar) and, according to the heroku logs, is using nginx to serve data (which is great). I've also confirmed via the Content-Encoding HTTP header that it is gzipping data to the browser. According to the documentation, that is NOT supposed to happen on cedar. Am I missing something here?
You must be accessing these apps through a domain pointing to these IPs:
75.101.163.44
75.101.145.87
174.129.212.2
These are the apex faces and they are in front of both bamboo and cedar apps. Varnish is there for bamboo, but any request that goes through them ends up going through varnish too.
These faces are only for apex domains. If your app is under a subdomain such as www, it should be setup as a CNAME pointing to appname.herokuapp.com. When setup like that, requests will not go through varnish.
For more on Apex's and Heroku, see here: http://neilmiddleton.com/the-dangers-of-a-records-and-heroku/

Resources