Skip to content

Commit

Permalink
Add Thin as Webserver
Browse files Browse the repository at this point in the history
  • Loading branch information
kevicency committed Oct 7, 2011
1 parent ada414e commit 8ef5aed
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1 +1,3 @@
cfg/aws_keys.json
log
tmp
3 changes: 2 additions & 1 deletion Gemfile
@@ -1,10 +1,11 @@
source :rubygems

gem "sinatra", "1.2.6"
gem "rack", "1.3.2"
gem "thin"
gem "right_aws"
gem "uuidtools"
gem "haml"
gem "init"

group :test do
gem "rack-test", "0.5.7"
Expand Down
12 changes: 10 additions & 2 deletions Gemfile.lock
@@ -1,8 +1,11 @@
GEM
remote: http://rubygems.org/
specs:
daemons (1.1.4)
eventmachine (0.12.10)
haml (3.1.3)
rack (1.3.2)
init (1.2.1)
rack (1.3.3)
rack-test (0.5.7)
rack (>= 1.0)
right_aws (2.1.0)
Expand All @@ -11,6 +14,10 @@ GEM
sinatra (1.2.6)
rack (~> 1.1)
tilt (>= 1.2.2, < 2.0)
thin (1.2.11)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
tilt (1.3.3)
uuidtools (2.1.2)

Expand All @@ -19,8 +26,9 @@ PLATFORMS

DEPENDENCIES
haml
rack (= 1.3.2)
init
rack-test (= 0.5.7)
right_aws
sinatra (= 1.2.6)
thin
uuidtools
14 changes: 13 additions & 1 deletion Rakefile
Expand Up @@ -11,7 +11,7 @@ task :console do
end

task :run => :setup do
exec "rvmsudo rackup -p 80"
exec "rvmsudo thin -R config.ru -p 80 -d"
end

task :setup => [:check_picassound, :copy_configs, :load_ec2_metadata] do
Expand Down Expand Up @@ -50,4 +50,16 @@ task :check_picassound do
end
end

task :startup => :nostartup do
startup_file = "./lib/picloud/startup.rb"
system "sudo cp #{startup_file} /etc/init.d/picloud -f"
system "sudo chmod 777 /etc/init.d/picloud"
system "sudo update-rc.d -f picloud defaults"
end

task :nostartup do
system "sudo rm /etc/init.d/picloud"
system "sudo update-rc.d picloud remove"
end

task :default => :run
9 changes: 9 additions & 0 deletions config.ru
@@ -1,5 +1,14 @@
$:.unshift "lib"
require "picloud"
require 'sinatra'

set :environment, :production
#disable :run

#FileUtils.mkdir_p 'log' unless File.exists?('log')
#log = File.new("log/sinatra.log", "a")
#$stdout.reopen(log)
#$stderr.reopen(log)

map "/" do
run Picloud::Server
Expand Down
3 changes: 2 additions & 1 deletion lib/picloud/server.rb
Expand Up @@ -6,7 +6,8 @@ module Picloud

class Server < Sinatra::Base

set :root, File.expand_path("../../..", __FILE__)
root_dir = File.expand_path("../../..", __FILE__)
set :root, root_dir

get "/" do
haml :index
Expand Down
42 changes: 42 additions & 0 deletions lib/picloud/startup.rb
@@ -0,0 +1,42 @@
#!/usr/bin/env ruby
#
# picloud Startup script for Picloud
#
# chkconfig: - 85 15
#

require 'aef/init'

class Picloud < Aef::Init
BASE_DIR = '/local'
APPS = {
"picloud_server" => 80,
}

stop_start_delay 3

# An implementation of the start method
def start
APPS.each do |app_name, port|
app_dir = File.join(BASE_DIR, app_name)
puts "starting #{app_name} on #{port}..."
`rvmsudo thin start -d -p #{port} -e production -c #{app_dir} -R config.ru`
end
end

# An implementation of the stop method
def stop
APPS.each do |app_name, port|
app_dir = File.join(BASE_DIR, app_name)
puts "Stopping #{app_name}..."
`rvmsudo thin stop -c #{app_dir}`
end
end
end

# The parser is only executed if the script is executed as a program, never
# when the script is required in a ruby program
if __FILE__ == $PROGRAM_NAME
Picloud.parse
end

4 changes: 4 additions & 0 deletions public/css/master.css
Expand Up @@ -9,6 +9,10 @@
#preview {
max-width: 100%;
max-height: 100%;
visibility: collapse;
}

#preview_alt {
font-weight: bold;
font-size: 18px;
color: gray;
Expand Down
2 changes: 2 additions & 0 deletions public/js/app.js
Expand Up @@ -3,6 +3,8 @@ $(document).ready(function() {
function imageLoaded(e) {
var img = $("#preview");
img.attr("src", e.target.result);
img.css("visibility", "visible");
$("#preview_alt").remove();
}

function handleImage(file) {
Expand Down
3 changes: 2 additions & 1 deletion views/index.haml
Expand Up @@ -9,6 +9,7 @@
%link{:rel => "stylesheet", :href => "/css/master.css", :type => "text/css", :media => "screen"}
%body
#dropbox
%img#preview{alt: "Drop Image here"}
#preview_alt Drop Image here
%img#preview
#errors
#playlist

0 comments on commit 8ef5aed

Please sign in to comment.