Skip to content Skip to sidebar Skip to footer

AWS Deployment Goes Down Frequently

So, I've got a very basic deployment on an EC2 instance that largely works, except for a couple of large issues. Right now I'm just ssh'ing into the box and running python -m Simp

Solution 1:

Use screen! Here's a quick tutorial: http://www.nixtutor.com/linux/introduction-to-gnu-screen/

Essentially just ssh in, open a new window via screen, start the server via python -m SimpleHTTPServer 80, then detach from the window. Additionally, you should be able to close your terminal and it should stay up.


Solution 2:

I was able to solve this a little hackishly by putting together a cron job to run a bash script that spun up a server, but I'm not sure if this is the best way. It seems to have solved my problems in the short term though. For reference, this is the code I used:

import SimpleHTTPServer
import SocketServer

PORT = 80

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

httpd.serve_forever()

Which I wrapped in a simple bash script:

#!/bin/bash
cd relevant/directory
sudo -u ubuntu python simple_server.py

I sure there was a better permissioning to use, but after that I just ran

chmod -R 777 bash_script.sh

To make sure I wouldn't run into any issues on that front.

And then placed in a cronjob to run every minute (The more the merrier, right?)

crontab -e (Just to bring up the relevant file)

Added in this line:

*/1 * * * * path/to/bash_script.sh

And it seems to be working. I closed out my ssh'd terminal and everything still runs and nothing has gone down yet. I will update if something does, but I'm generally happy with this solution (not that I will be in 2 weeks once I learn more about the subject), but it seems very minimal and low level, which means I at least understand what I just did.


Solution 3:

SimpleHTTPServer just serves static pages on port 80, mainly for use during development.

For production usage (if you want to use EC2) I recommend you read up on Apache or nginx. Basically you want a web server that runs on Linux.

If you think your site will remain static files (HTML, CSS, JS) I recommend you host them on Amazon S3 instead. S3 is cheaper and way more reliable. Take a look at this answer for instructions: Static hosting on Amazon S3 - DNS Configuration

Enjoy!


Post a Comment for "AWS Deployment Goes Down Frequently"