Skip to content

Instantly share code, notes, and snippets.

@diego-aslz
Last active April 17, 2017 18:17
Show Gist options
  • Save diego-aslz/0de991bf6f1550a94ab3ccb8f9c31615 to your computer and use it in GitHub Desktop.
Save diego-aslz/0de991bf6f1550a94ab3ccb8f9c31615 to your computer and use it in GitHub Desktop.
CEP
/home/web/uems/current
# /etc/init/puma-manager.conf - manage a set of Pumas
# This example config should work with Ubuntu 12.04+. It
# allows you to manage multiple Puma instances with
# Upstart, Ubuntu's native service management tool.
#
# See puma.conf for how to manage a single Puma instance.
#
# Use "stop puma-manager" to stop all Puma instances.
# Use "start puma-manager" to start all instances.
# Use "restart puma-manager" to restart all instances.
# Crazy, right?
#
description "Manages the set of puma processes"
# This starts upon bootup and stops on shutdown
start on runlevel [2345]
stop on runlevel [06]
# Set this to the number of Puma processes you want
# to run on this machine
env PUMA_CONF="/etc/puma.conf"
pre-start script
for i in `cat $PUMA_CONF`; do
app=`echo $i | cut -d , -f 1`
logger -t "puma-manager" "Starting $app"
start puma app=$app
done
end script
# /etc/init/puma.conf - Puma config
# This example config should work with Ubuntu 12.04+. It
# allows you to manage multiple Puma instances with
# Upstart, Ubuntu's native service management tool.
#
# See workers.conf for how to manage all Puma instances at once.
#
# Save this config as /etc/init/puma.conf then manage puma with:
# sudo start puma app=PATH_TO_APP
# sudo stop puma app=PATH_TO_APP
# sudo status puma app=PATH_TO_APP
#
# or use the service command:
# sudo service puma {start,stop,restart,status}
#
description "Puma Background Worker"
# no "start on", we don't want to automatically start
stop on (stopping puma-manager or runlevel [06])
# change apps to match your deployment user if you want to use this as a less privileged user (recommended!)
setuid web
setgid web
respawn
respawn limit 3 30
instance ${app}
script
# this script runs in /bin/sh by default
# respawn as bash so we can source in rbenv/rvm
# quoted heredoc to tell /bin/sh not to interpret
# variables
# source ENV variables manually as Upstart doesn't, eg:
#. /etc/environment
exec /bin/bash <<'EOT'
# set HOME to the setuid user's home, there doesn't seem to be a better, portable way
export HOME="$(eval echo ~$(id -un))"
if [ -d "/usr/local/rbenv/bin" ]; then
export PATH="/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH"
elif [ -d "$HOME/.rbenv/bin" ]; then
export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"
elif [ -f /etc/profile.d/rvm.sh ]; then
source /etc/profile.d/rvm.sh
elif [ -f /usr/local/rvm/scripts/rvm ]; then
source /etc/profile.d/rvm.sh
elif [ -f "$HOME/.rvm/scripts/rvm" ]; then
source "$HOME/.rvm/scripts/rvm"
elif [ -f /usr/local/share/chruby/chruby.sh ]; then
source /usr/local/share/chruby/chruby.sh
if [ -f /usr/local/share/chruby/auto.sh ]; then
source /usr/local/share/chruby/auto.sh
fi
# if you aren't using auto, set your version here
# chruby 2.0.0
fi
cd $app
logger -t puma "Starting server: $app"
exec bundle exec puma -C config/puma.rb
EOT
end script
# Change to match your CPU core count
workers 2
# Min and Max threads per worker
threads 1, 6
# Default to production
rails_env = ENV['RAILS_ENV'] || 'production'
environment rails_env
preload_app!
# Set up socket location
bind 'unix:///home/web/uems/shared/tmp/sockets/uems.socket'
# Logging
stdout_redirect "/home/web/uems/shared/log/puma.log", "/home/web/uems/shared/log/puma.log", true
# Set master PID and state locations
pidfile "/home/web/uems/shared/tmp/pids/puma.pid"
state_path "/home/web/uems/shared/tmp/pids/puma.state"
activate_control_app
on_worker_boot do
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
ActiveRecord::Base.establish_connection
end
resources :zips, only: :show
@onReady ->
# Não sei que ID vc usa nesse campo:
$('#user_zip').on 'change', ->
zip = $(this).val()
return unless zip.length
$.get "/zips/#{zip}", (address) ->
# Aqui vc preenche os campos, vou fazer uns chutes:
$('#user_city_name').val(address.city)
$('#user_complement').val(address.complement)
$('#user_state').val(address.state)
def show
@address = Correios::CEP::AddressFinder.get(params[:id])
render json: @address
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment