Skip to content

Instantly share code, notes, and snippets.

@seyyah
Forked from ecylmz/README.md
Last active December 22, 2015 23:49
Show Gist options
  • Save seyyah/6549326 to your computer and use it in GitHub Desktop.
Save seyyah/6549326 to your computer and use it in GitHub Desktop.
  • Yapılandırmalar eski yerinde /etc/unicorn

    Örnek:

    RAILS_ROOT=/opt/medical
    RAILS_ENV=development

  • Ayrıca Rails app config,

    app_path = "/opt/medical"
    listen 3010 # by default Unicorn listens on port 8080
    listen 3011
    worker_processes 2 # this should be >= nr_cpus
    pid "#{app_path}/tmp/pids/unicorn.pid"
    stderr_path "#{app_path}/log/unicorn.log"
    stdout_path "#{app_path}/log/unicorn.log"

  • Nginx,

    upstream medical {
    server 0.0.0.0:3010;
    server 0.0.0.0:3011;
    }

    server {
    listen 80;
    server_name medical.a.ondokuz.biz;
    access_log /opt/medical/log/access.log;
    error_log /opt/medical/log/error.log;
    root /opt/medical/public;
    index index.html index.php;

        location / {                                                                                                                                                                          
                proxy_set_header  X-Real-IP  $remote_addr;                                                                                                                                    
                proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;                                                                                                                 
                proxy_set_header Host $http_host;                                                                                                                                             
                proxy_redirect off;                                                                                                                                                           
                                                                                                                                                                                              
                if (-f $request_filename/index.html) {                                                                                                                                        
                        rewrite (.*) $1/index.html break;                                                                                                                                     
                }                                                                                                                                                                             
                                                                                                                                                                                              
                if (-f $request_filename.html) {                                                                                                                                              
                        rewrite (.*) $1.html break;                                                                                                                                           
                }                                                                                                                                                                             
                                                                                                                                                                                              
                if (!-f $request_filename) {                                                                                                                                                  
                        proxy_pass http://medical;                                                                                                                                            
                        break;                                                                                                                                                                
                }                                                                                                                                                                             
        }                                                                                                                                                                                     
    

    }

Aşağısından emin değilim,

  • unicorn-multi.sh (şimdilik) /etc/unicorn altında (executable olması gerekmiyor
  • unicorn-multi betiği /etc/init.d altında
  • Bu sistemin çalışması için mevcut unicorn betiğini kaldırmak gerekmiyor ama kaldırılırsa daha güvenli olabilir.
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: unicorn initscript
# Description: unicorn
### END INIT INFO
set -e
NAME=unicorn-multi
DESC="Unicorn web server for multiple applications"
. /lib/lsb/init-functions
if [ -f /etc/default/unicorn-multi ]; then
. /etc/default/unicorn-multi
fi
RUNNER=/etc/unicorn/unicorn-multi.sh
CONFDIR=${CONFDIR-/etc/unicorn/conf.d}
[ -f $RUNNER ] || exit_with_message "Unicorn initializer $RUNNER is not exist."
[ -d $CONFDIR ] || exit_with_message "Configuration directory $CONFDIR is not exist."
list() {
local f
for f in ${CONFDIR}/${1}; do
[ -f "$f" ] || continue
echo $f
done
}
run() {
sh $RUNNER "$1" "$2" || {
log_warning_msg "Action $1 failed for configuration $2" || true
ERR=1
}
}
ERR=
if [ $# -ge 1 ]; then
conffiles=$(list ${2-'*'})
if [ -n "$conffiles" ]; then
for conf in $conffiles; do
run "$1" "$conf"
done
else
log_warning_msg "No configuration file found." || true
ERR=1
fi
else
log_action_msg "Usage: $0 <start|stop|restart|force-reload|reload|force-stop|reopen-logs|status> [<conffile>]" || true
ERR=1
fi
exit $ERR
#!/bin/sh
set -e
. /lib/lsb/init-functions
usage() {
log_action_msg "Usage: $0 <start|stop|restart|force-reload|reload|force-stop|reopen-logs|status> <conffile>" || true
exit 1
}
[ $# -eq 2 ] || usage
[ -f "$2" ] || exit_with_message "Configuration file '$2' not found."
ACTION=$1
CONFFILE=$2
APP_NAME=${CONFFILE##*/}
NAME=unicorn
DESC="Unicorn web server for $APP_NAME"
. $CONFFILE
DAEMON=/usr/bin/unicorn_rails
DAEMON_OPTS="-c ${APP_ROOT}/config/unicorn.rb -E ${APP_ENV} -D"
PID=${PID-${APP_ROOT}/tmp/pids/unicorn.pid}
run_by_init() {
([ "${previous-}" ] && [ "${runlevel-}" ]) || [ "${runlevel-}" = S ]
}
exit_with_message() {
if ! run_by_init; then
log_action_msg "$1 Not starting."
fi
exit 0
}
check_app_root() {
if ! [ -d $APP_ROOT ]; then
exit_with_message "Application directory $APP_ROOT is not exist."
fi
}
set -u
case "$ACTION" in
start)
check_app_root
log_daemon_msg "Starting $DESC" $NAME || true
if start-stop-daemon --start --quiet --oknodo --chdir $APP_ROOT --pidfile $PID --exec $DAEMON -- $DAEMON_OPTS; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
stop)
log_daemon_msg "Stopping $DESC" $NAME || true
if start-stop-daemon --stop --signal QUIT --quiet --oknodo --pidfile $PID; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
force-stop)
log_daemon_msg "Forcing stop of $DESC" $NAME || true
if start-stop-daemon --stop --quiet --oknodo --pidfile $PID; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" $NAME || true
start-stop-daemon --stop --quiet --oknodo --pidfile $PID
sleep 1
if start-stop-daemon --start --quiet --oknodo --chdir $APP_ROOT --pidfile $PID --exec $DAEMON -- $DAEMON_OPTS; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
reload)
log_daemon_msg "Reloading $DESC" $NAME || true
if start-stop-daemon --stop --signal HUP --quiet --oknodo --pidfile $PID; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
reopen-logs)
log_daemon_msg "Relopening log files of $DESC" $NAME || true
if start-stop-daemon --stop --signal USR1 --quiet --oknodo --pidfile $PID; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
status)
status_of_proc -p $PID $DAEMON $NAME && exit 0 || exit $?
;;
*)
usage
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment