mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
removed capistrano & unicorn + cleaned lacasemate brading
This commit is contained in:
parent
208e33a890
commit
01ac73a1a1
7
Gemfile
7
Gemfile
@ -17,7 +17,7 @@ gem 'jquery-rails'
|
||||
gem 'jbuilder', '~> 2.5'
|
||||
gem 'jbuilder_cache_multi'
|
||||
# bundle exec rake doc:rails generates the API under doc/api.
|
||||
gem 'sdoc', '~> 0.4.0', group: :doc #TODO remove unused ?
|
||||
gem 'sdoc', '~> 0.4.0', group: :doc # TODO, remove unused ?
|
||||
|
||||
gem 'forgery'
|
||||
gem 'responders', '~> 2.0'
|
||||
@ -41,16 +41,12 @@ end
|
||||
group :development do
|
||||
gem 'active_record_query_trace'
|
||||
gem 'awesome_print'
|
||||
gem 'capistrano'
|
||||
gem 'capistrano-maintenance', '0.0.5', require: false
|
||||
gem 'capistrano-sidekiq', require: false
|
||||
gem 'coveralls', require: false
|
||||
gem 'foreman'
|
||||
# Preview mail in the browser
|
||||
gem 'mailcatcher'
|
||||
gem 'puma'
|
||||
gem 'rb-readline'
|
||||
gem 'rvm-capistrano', require: false
|
||||
end
|
||||
|
||||
group :test do
|
||||
@ -66,7 +62,6 @@ end
|
||||
|
||||
group :production do
|
||||
gem 'rails_12factor'
|
||||
gem 'unicorn'
|
||||
end
|
||||
|
||||
gem 'seed_dump'
|
||||
|
@ -9,14 +9,9 @@
|
||||
|
||||
<title><%=Setting.find_by(name: 'fablab_name').value%></title>
|
||||
|
||||
<% if ENV['DEFAULT_HOST'] == 'fablab.lacasemate.fr' %>
|
||||
<script type="text/javascript" src="//use.typekit.net/rih5zfr.js"></script>
|
||||
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
|
||||
<% else %>
|
||||
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,600,600italic,700,800,700italic' rel='stylesheet' type='text/css'>
|
||||
<link href='https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700,300italic' rel='stylesheet' type='text/css'>
|
||||
<link href='https://fonts.googleapis.com/css?family=Loved+by+the+King' rel='stylesheet' type='text/css'>
|
||||
<% end %>
|
||||
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,600,600italic,700,800,700italic' rel='stylesheet' type='text/css'>
|
||||
<link href='https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700,300italic' rel='stylesheet' type='text/css'>
|
||||
<link href='https://fonts.googleapis.com/css?family=Loved+by+the+King' rel='stylesheet' type='text/css'>
|
||||
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
|
||||
<script type="text/javascript">
|
||||
Stripe.setPublishableKey('<%= Rails.application.secrets.stripe_publishable_key %>');
|
||||
|
121
config/deploy.rb
121
config/deploy.rb
@ -1,121 +0,0 @@
|
||||
require "bundler/capistrano"
|
||||
require "rvm/capistrano"
|
||||
require 'capistrano/ext/multistage'
|
||||
require 'capistrano/maintenance'
|
||||
|
||||
set :stages, %w(production staging)
|
||||
set :default_stage, "staging"
|
||||
|
||||
|
||||
default_run_options[:pty] = true
|
||||
ssh_options[:forward_agent] = true
|
||||
|
||||
after "deploy", "deploy:cleanup" # keep only the last 5 releases
|
||||
|
||||
# after "deploy:finalize_update", "deploy:assets:precompile"
|
||||
|
||||
namespace :deploy do
|
||||
%w[start stop restart].each do |command|
|
||||
desc "#{command} unicorn server"
|
||||
task command, roles: :app, except: {no_release: true} do
|
||||
run "/etc/init.d/unicorn_#{application} #{command}"
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Symlink bootstrap glyphicons'
|
||||
task :symlink, :roles => :web, :except => { :no_release => true } do
|
||||
#run "rm -R #{shared_path}/assets/bootstrap/glyphicons-halflings-regular-*"
|
||||
run "ln -nfs #{shared_path}/assets/bootstrap/glyphicons-halflings-regular-*.ttf #{shared_path}/assets/bootstrap/glyphicons-halflings-regular.ttf"
|
||||
run "ln -nfs #{shared_path}/assets/bootstrap/glyphicons-halflings-regular-*.svg #{shared_path}/assets/bootstrap/glyphicons-halflings-regular.svg"
|
||||
run "ln -nfs #{shared_path}/assets/bootstrap/glyphicons-halflings-regular-*.woff #{shared_path}/assets/bootstrap/glyphicons-halflings-regular.woff"
|
||||
run "ln -nfs #{shared_path}/assets/bootstrap/glyphicons-halflings-regular-*.woff2 #{shared_path}/assets/bootstrap/glyphicons-halflings-regular.woff2"
|
||||
run "ln -nfs #{shared_path}/assets/bootstrap/glyphicons-halflings-regular-*.eot #{shared_path}/assets/bootstrap/glyphicons-halflings-regular.eot"
|
||||
#run "rm -R #{shared_path}/assets/select2/select2*"
|
||||
run "ln -nfs #{shared_path}/assets/select2/select2-*.png #{shared_path}/assets/select2.png"
|
||||
run "ln -nfs #{shared_path}/assets/select2/select2x2-*.png #{shared_path}/assets/select2x2.png"
|
||||
run "ln -nfs #{shared_path}/assets/select2/select2-spinner-*.gif #{shared_path}/assets/select2-spinner.gif"
|
||||
end
|
||||
|
||||
task :setup_config, roles: :app do
|
||||
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
|
||||
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
|
||||
run "mkdir -p #{shared_path}/config"
|
||||
run "mkdir -p #{shared_path}/uploads"
|
||||
run "mkdir -p #{shared_path}/invoices"
|
||||
run "mkdir -p #{shared_path}/exports"
|
||||
run "mkdir -p #{shared_path}/plugins"
|
||||
put File.read("config/database.yml"), "#{shared_path}/config/database.yml"
|
||||
puts "Now edit #{shared_path}/config/database.yml and add your username and password"
|
||||
put File.read("config/application.yml"), "#{shared_path}/config/application.yml"
|
||||
puts "Now edit #{shared_path}/config/application.yml and add your ENV vars"
|
||||
|
||||
end
|
||||
after "deploy:setup", "deploy:setup_config"
|
||||
|
||||
task :symlink_config, roles: :app do
|
||||
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
|
||||
run "rm -rf #{release_path}/config/application.yml"
|
||||
run "ln -nfs #{shared_path}/config/application.yml #{release_path}/config/application.yml"
|
||||
end
|
||||
after "deploy:finalize_update", "deploy:symlink_config"
|
||||
|
||||
desc "Make sure local git is in sync with remote."
|
||||
task :check_revision, roles: :web do
|
||||
unless `git rev-parse HEAD` == `git rev-parse origin/master`
|
||||
puts "WARNING: HEAD is not the same as origin/master"
|
||||
puts "Run `git push` to sync changes."
|
||||
exit
|
||||
end
|
||||
end
|
||||
#before "deploy", "deploy:check_revision"
|
||||
|
||||
desc "load seed to bd"
|
||||
task :load_seed, :roles => :app do
|
||||
run "cd #{current_path} && bundle exec rake db:seed RAILS_ENV=production"
|
||||
end
|
||||
|
||||
desc "Rake db:migrate"
|
||||
task :db_migrate, :roles => :app do
|
||||
run "cd #{current_path} && bundle exec rake db:migrate RAILS_ENV=production"
|
||||
end
|
||||
after "deploy:create_symlink", "deploy:db_migrate"
|
||||
|
||||
desc "Symlinks the uploads dir"
|
||||
task :symlink_uploads_dir, :roles => :app do
|
||||
run "rm -rf #{release_path}/public/uploads"
|
||||
run "ln -nfs #{shared_path}/uploads/ #{release_path}/public/"
|
||||
end
|
||||
after "deploy:finalize_update", 'deploy:symlink_uploads_dir'
|
||||
|
||||
desc "Symlinks the invoices dir"
|
||||
task :symlink_invoices_dir, :roles => :app do
|
||||
run "rm -rf #{release_path}/invoices"
|
||||
run "ln -nfs #{shared_path}/invoices/ #{release_path}/"
|
||||
end
|
||||
after "deploy:finalize_update", 'deploy:symlink_invoices_dir'
|
||||
|
||||
desc "Symlinks the exports dir"
|
||||
task :symlink_exports_dir, :roles => :app do
|
||||
run "rm -rf #{release_path}/exports"
|
||||
run "ln -nfs #{shared_path}/exports/ #{release_path}/"
|
||||
end
|
||||
after "deploy:finalize_update", 'deploy:symlink_exports_dir'
|
||||
|
||||
desc "Symlinks the plugins dir"
|
||||
task :symlink_plugins_dir, :roles => :app do
|
||||
run "rm -rf #{release_path}/plugins"
|
||||
run "ln -nfs #{shared_path}/plugins/ #{release_path}/"
|
||||
end
|
||||
after "deploy:finalize_update", 'deploy:symlink_plugins_dir'
|
||||
|
||||
namespace :assets do
|
||||
desc 'Run the precompile task locally and rsync with shared'
|
||||
task :precompile, :roles => :web, :except => { :no_release => true } do
|
||||
%x{bundle exec rake assets:precompile RAILS_ENV=production}
|
||||
%x{rsync --recursive --times --rsh='ssh -p#{port}' --compress --human-readable --progress public/assets #{user}@#{domain}:#{shared_path}}
|
||||
%x{bundle exec rake assets:clean}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -1,16 +0,0 @@
|
||||
server "fablab.lacasemate.fr", :web, :app, :db, primary: true
|
||||
|
||||
set :domain, "fablab.lacasemate.fr"
|
||||
set :application, "fablab"
|
||||
set :user, "sleede"
|
||||
set :port, 22
|
||||
set :deploy_to, "/home/#{user}/apps/#{application}"
|
||||
set :deploy_via, :remote_cache
|
||||
set :use_sudo, false
|
||||
|
||||
set :scm, "git"
|
||||
set :repository, "git@git.sleede.com:clients/fablab.git"
|
||||
set :scm_user, "jarod022"
|
||||
set :branch, "master"
|
||||
|
||||
set :rails_env, 'production'
|
@ -1,66 +0,0 @@
|
||||
server "test.fab-manager.com", :web, :app, :db, primary: true
|
||||
|
||||
set :application, "fablab_staging"
|
||||
set :user, "admin"
|
||||
set :port, 22
|
||||
set :deploy_to, "/home/#{user}/apps/#{application}"
|
||||
set :deploy_via, :remote_cache
|
||||
set :use_sudo, false
|
||||
|
||||
set :scm, "git"
|
||||
set :repository, "git@git.sleede.com:clients/fablab.git"
|
||||
set :scm_user, "jarod022"
|
||||
set :branch, "dev"
|
||||
|
||||
set :rails_env, 'staging'
|
||||
|
||||
|
||||
namespace :deploy do
|
||||
%w[start stop restart].each do |command|
|
||||
desc "#{command} unicorn server"
|
||||
task command, roles: :app, except: {no_release: true} do
|
||||
run "/etc/init.d/unicorn_#{application} #{command}"
|
||||
end
|
||||
end
|
||||
|
||||
task :setup_config, roles: :app do
|
||||
sudo "ln -nfs #{current_path}/config/nginx_staging.conf /etc/nginx/sites-enabled/#{application}"
|
||||
sudo "ln -nfs #{current_path}/config/unicorn_init_staging.sh /etc/init.d/unicorn_#{application}"
|
||||
run "mkdir -p #{shared_path}/config"
|
||||
run "mkdir -p #{shared_path}/uploads"
|
||||
put File.read("config/database.yml"), "#{shared_path}/config/database.yml"
|
||||
puts "Now edit #{shared_path}/config/database.yml and add your username and password"
|
||||
put File.read("config/application.yml"), "#{shared_path}/config/application.yml"
|
||||
puts "Now edit #{shared_path}/config/application.yml and add your ENV vars"
|
||||
|
||||
end
|
||||
after "deploy:setup", "deploy:setup_config"
|
||||
|
||||
task :symlink_robots, roles: :app do
|
||||
run "rm -rf #{release_path}/public/robots.txt"
|
||||
run "ln -nfs #{shared_path}/robots.txt #{release_path}/public/robots.txt"
|
||||
end
|
||||
after "deploy:finalize_update", "deploy:symlink_robots"
|
||||
|
||||
desc "Rake db:migrate"
|
||||
task :db_migrate, :roles => :app do
|
||||
run "cd #{current_path} && bundle exec rake db:migrate RAILS_ENV=staging"
|
||||
end
|
||||
after "deploy:create_symlink", "deploy:db_migrate"
|
||||
|
||||
namespace :assets do
|
||||
desc 'Run the precompile task locally and rsync with shared'
|
||||
task :precompile, :only => { :primary => true } do
|
||||
|
||||
%x{bundle exec rake assets:precompile RAILS_ENV=staging}
|
||||
|
||||
servers = find_servers :roles => [:app], :except => { :no_release => true }
|
||||
servers.each do |server|
|
||||
%x{rsync --recursive --times --rsh='ssh -p#{port}' --compress --human-readable --progress public/assets #{user}@#{server}:#{shared_path}}
|
||||
end
|
||||
|
||||
%x{bundle exec rake assets:clean}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -1,64 +0,0 @@
|
||||
upstream unicorn {
|
||||
server unix:/tmp/unicorn.fablab.sock fail_timeout=0;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name fablab.lacasemate.fr fablab.ccsti-grenoble.org;
|
||||
rewrite ^ https://fablab.lacasemate.fr$request_uri? permanent;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name fablab.lacasemate.fr;
|
||||
root /home/sleede/apps/fablab/current/public;
|
||||
|
||||
ssl on;
|
||||
ssl_certificate /etc/nginx/ssl/certificate.fablab.lacasemate.fr.crt;
|
||||
ssl_certificate_key /etc/nginx/ssl/fablab.lacasemate.fr.deprotected.key;
|
||||
|
||||
#location / {
|
||||
# auth_basic "Restricted";
|
||||
# auth_basic_user_file /home/sleede/apps/fablab/.htpasswd;
|
||||
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
# proxy_set_header Host $http_host;
|
||||
# proxy_redirect off;
|
||||
# proxy_pass http://unicorn;
|
||||
#}
|
||||
|
||||
location ^~ /assets/ {
|
||||
gzip_static on;
|
||||
expires max;
|
||||
add_header Cache-Control public;
|
||||
}
|
||||
|
||||
try_files $uri/index.html $uri @unicorn;
|
||||
location @unicorn {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_redirect off;
|
||||
proxy_pass http://unicorn;
|
||||
}
|
||||
|
||||
client_max_body_size 4G;
|
||||
keepalive_timeout 10;
|
||||
|
||||
error_page 500 502 504 /500.html;
|
||||
error_page 503 @503;
|
||||
|
||||
# Return a 503 error if the maintenance page exists.
|
||||
if (-f /home/sleede/apps/fablab/shared/system/maintenance.html) {
|
||||
return 503;
|
||||
}
|
||||
|
||||
location @503 {
|
||||
# Serve static assets if found.
|
||||
if (-f $request_filename) {
|
||||
break;
|
||||
}
|
||||
|
||||
# Set root to the shared directory.
|
||||
root /home/sleede/apps/fablab/shared;
|
||||
rewrite ^(.*)$ /system/maintenance.html break;
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
upstream puma {
|
||||
server unix:/usr/src/app/tmp/sockets/fablab.sock fail_timeout=0;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name capsciences.fab-manager.com;
|
||||
root /usr/src/app/public;
|
||||
location ^~ /assets/ {
|
||||
gzip_static on;
|
||||
expires max;
|
||||
add_header Cache-Control public;
|
||||
}
|
||||
|
||||
try_files $uri/index.html $uri @puma;
|
||||
location @puma {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_redirect off;
|
||||
proxy_pass http://puma;
|
||||
}
|
||||
|
||||
client_max_body_size 4G;
|
||||
keepalive_timeout 10;
|
||||
|
||||
error_page 500 502 503 504 /500.html;
|
||||
error_page 503 @503;
|
||||
|
||||
# Return a 503 error if the maintenance page exists.
|
||||
if (-f /usr/src/app/public/maintenance.html) {
|
||||
return 503;
|
||||
}
|
||||
|
||||
location @503 {
|
||||
# Serve static assets if found.
|
||||
if (-f $request_filename) {
|
||||
break;
|
||||
}
|
||||
|
||||
# Set root to the shared directory.
|
||||
root /usr/src/app/public;
|
||||
rewrite ^(.*)$ /maintenance.html break;
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
upstream fablab_unicorn_staging {
|
||||
server unix:/tmp/unicorn.fablab_staging.sock fail_timeout=0;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name fablab.sleede.com capsciences.sleede.com relais-sciences.sleede.com demo-premium.fab-manager.com;
|
||||
root /home/admin/apps/fablab_staging/current/public;
|
||||
|
||||
#location / {
|
||||
# auth_basic "Restricted";
|
||||
# auth_basic_user_file /home/admin/apps/fablab/.htpasswd;
|
||||
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
# proxy_set_header Host $http_host;
|
||||
# proxy_redirect off;
|
||||
# proxy_pass http://unicorn;
|
||||
#}
|
||||
|
||||
location ^~ /assets/ {
|
||||
gzip_static on;
|
||||
expires max;
|
||||
add_header Cache-Control public;
|
||||
}
|
||||
|
||||
try_files $uri/index.html $uri @fablab_unicorn_staging;
|
||||
location @fablab_unicorn_staging {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_redirect off;
|
||||
proxy_pass http://fablab_unicorn_staging;
|
||||
}
|
||||
|
||||
client_max_body_size 4G;
|
||||
keepalive_timeout 10;
|
||||
|
||||
error_page 500 502 504 /500.html;
|
||||
error_page 503 @503;
|
||||
|
||||
# Return a 503 error if the maintenance page exists.
|
||||
if (-f /home/admin/apps/fablab_staging/shared/system/maintenance.html) {
|
||||
return 503;
|
||||
}
|
||||
|
||||
location @503 {
|
||||
# Serve static assets if found.
|
||||
if (-f $request_filename) {
|
||||
break;
|
||||
}
|
||||
|
||||
# Set root to the shared directory.
|
||||
root /home/admin/apps/fablab_staging/shared;
|
||||
rewrite ^(.*)$ /system/maintenance.html break;
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
# config/unicorn.rb
|
||||
|
||||
root = "/home/sleede/apps/fablab/current"
|
||||
working_directory root
|
||||
pid "#{root}/tmp/pids/unicorn.pid"
|
||||
stderr_path "#{root}/log/unicorn.log"
|
||||
stdout_path "#{root}/log/unicorn.log"
|
||||
|
||||
listen "/tmp/unicorn.fablab.sock"
|
||||
worker_processes 1
|
||||
timeout 60
|
||||
preload_app true
|
||||
|
||||
# Force the bundler gemfile environment variable to
|
||||
# reference the capistrano "current" symlink
|
||||
before_exec do |_|
|
||||
ENV["BUNDLE_GEMFILE"] = File.join(root, 'Gemfile')
|
||||
end
|
@ -1,84 +0,0 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: unicorn
|
||||
# Required-Start: $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Manage unicorn server
|
||||
# Description: Start, stop, restart unicorn server for a specific application.
|
||||
### END INIT INFO
|
||||
set -e
|
||||
|
||||
# Feel free to change any of the following variables for your app:
|
||||
TIMEOUT=${TIMEOUT-60}
|
||||
APP_ROOT=/home/sleede/apps/fablab/current
|
||||
PID=$APP_ROOT/tmp/pids/unicorn.pid
|
||||
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
|
||||
AS_USER=sleede
|
||||
set -u
|
||||
|
||||
OLD_PIN="$PID.oldbin"
|
||||
|
||||
sig () {
|
||||
test -s "$PID" && kill -$1 `cat $PID`
|
||||
}
|
||||
|
||||
oldsig () {
|
||||
test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
|
||||
}
|
||||
|
||||
run () {
|
||||
if [ "$(id -un)" = "$AS_USER" ]; then
|
||||
eval $1
|
||||
else
|
||||
su -c "$1" - $AS_USER
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
sig 0 && echo >&2 "Already running" && exit 0
|
||||
run "$CMD"
|
||||
;;
|
||||
stop)
|
||||
sig QUIT && exit 0
|
||||
echo >&2 "Not running"
|
||||
;;
|
||||
force-stop)
|
||||
sig TERM && exit 0
|
||||
echo >&2 "Not running"
|
||||
;;
|
||||
restart|reload)
|
||||
sig HUP && echo reloaded OK && exit 0
|
||||
echo >&2 "Couldn't reload, starting '$CMD' instead"
|
||||
run "$CMD"
|
||||
;;
|
||||
upgrade)
|
||||
if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
|
||||
then
|
||||
n=$TIMEOUT
|
||||
while test -s $OLD_PIN && test $n -ge 0
|
||||
do
|
||||
printf '.' && sleep 1 && n=$(( $n - 1 ))
|
||||
done
|
||||
echo
|
||||
|
||||
if test $n -lt 0 && test -s $OLD_PIN
|
||||
then
|
||||
echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
|
||||
run "$CMD"
|
||||
;;
|
||||
reopen-logs)
|
||||
sig USR1
|
||||
;;
|
||||
*)
|
||||
echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@ -1,84 +0,0 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: unicorn
|
||||
# Required-Start: $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Manage unicorn server
|
||||
# Description: Start, stop, restart unicorn server for a specific application.
|
||||
### END INIT INFO
|
||||
set -e
|
||||
|
||||
# Feel free to change any of the following variables for your app:
|
||||
TIMEOUT=${TIMEOUT-60}
|
||||
APP_ROOT=/home/admin/apps/fablab_staging/current
|
||||
PID=$APP_ROOT/tmp/pids/unicorn.pid
|
||||
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn_staging.rb -E staging"
|
||||
AS_USER=admin
|
||||
set -u
|
||||
|
||||
OLD_PIN="$PID.oldbin"
|
||||
|
||||
sig () {
|
||||
test -s "$PID" && kill -$1 `cat $PID`
|
||||
}
|
||||
|
||||
oldsig () {
|
||||
test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
|
||||
}
|
||||
|
||||
run () {
|
||||
if [ "$(id -un)" = "$AS_USER" ]; then
|
||||
eval $1
|
||||
else
|
||||
su -c "$1" - $AS_USER
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
sig 0 && echo >&2 "Already running" && exit 0
|
||||
run "$CMD"
|
||||
;;
|
||||
stop)
|
||||
sig QUIT && exit 0
|
||||
echo >&2 "Not running"
|
||||
;;
|
||||
force-stop)
|
||||
sig TERM && exit 0
|
||||
echo >&2 "Not running"
|
||||
;;
|
||||
restart|reload)
|
||||
sig HUP && echo reloaded OK && exit 0
|
||||
echo >&2 "Couldn't reload, starting '$CMD' instead"
|
||||
run "$CMD"
|
||||
;;
|
||||
upgrade)
|
||||
if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
|
||||
then
|
||||
n=$TIMEOUT
|
||||
while test -s $OLD_PIN && test $n -ge 0
|
||||
do
|
||||
printf '.' && sleep 1 && n=$(( $n - 1 ))
|
||||
done
|
||||
echo
|
||||
|
||||
if test $n -lt 0 && test -s $OLD_PIN
|
||||
then
|
||||
echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
|
||||
run "$CMD"
|
||||
;;
|
||||
reopen-logs)
|
||||
sig USR1
|
||||
;;
|
||||
*)
|
||||
echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
@ -1,18 +0,0 @@
|
||||
# config/unicorn_staging.rb
|
||||
|
||||
root = "/home/admin/apps/fablab_staging/current"
|
||||
working_directory root
|
||||
pid "#{root}/tmp/pids/unicorn.pid"
|
||||
stderr_path "#{root}/log/unicorn.log"
|
||||
stdout_path "#{root}/log/unicorn.log"
|
||||
|
||||
listen "/tmp/unicorn.fablab_staging.sock"
|
||||
worker_processes 1
|
||||
timeout 60
|
||||
preload_app true
|
||||
|
||||
# Force the bundler gemfile environment variable to
|
||||
# reference the capistrano "current" symlink
|
||||
before_exec do |_|
|
||||
ENV["BUNDLE_GEMFILE"] = File.join(root, 'Gemfile')
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user