Skip to content

Instantly share code, notes, and snippets.

@cdarne
Created May 24, 2012 11:17
Show Gist options
  • Save cdarne/2780874 to your computer and use it in GitHub Desktop.
Save cdarne/2780874 to your computer and use it in GitHub Desktop.
Upstart/init.d config example for rails/passenger
sudo a2enmod proxy_http
sudo service apache2 restart
<VirtualHost *:80>
ServerName redmine.trololo.con
ProxyPass / http://127.0.0.1:1984/
ProxyPassReverse / http://127.0.0.1:1984/
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
#! /bin/bash
### BEGIN INIT INFO
# Provides: gitlab
# Required-Start: $local_fs $remote_fs $network $syslog mysql redis-server
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: GitLab git repository management
# Description: GitLab git repository management
### END INIT INFO
APP_ADDR="127.0.0.1"
APP_PORT="4000"
DAEMON_OPTS="-e production -a $APP_ADDR -p $APP_PORT -d"
NAME=passenger
DESC="Gitlab service"
PID=/home/ruby_passenger/gitlab/tmp/pids/passenger.$APP_PORT.pid
RESQUE_PID=/home/ruby_passenger/gitlab/tmp/pids/resque_worker.pid
case "$1" in
start)
LOAD_RVM_ENV=". /home/ruby_passenger/.rvm/environments/ruby-1.9.3-p194@gitlab"
CD_TO_APP_DIR="cd /home/ruby_passenger/gitlab"
START_DAEMON_PROCESS="bundle exec passenger start $DAEMON_OPTS"
START_RESQUE_PROCESS="./resque.sh"
echo -n "Starting $DESC: "
if [ `whoami` = root ]; then
sudo -u ruby_passenger bash -l -c "$LOAD_RVM_ENV > /dev/null 2>&1 && $CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS"
else
$CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS
fi
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
kill -QUIT `cat $PID`
kill -QUIT `cat $RESQUE_PID`
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
kill -USR2 `cat $PID`
kill -USR2 `cat $RESQUE_PID`
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
kill -HUP `cat $PID`
kill -HUP `cat $RESQUE_PID`
echo "$NAME."
;;
*)
echo "Usage: $NAME {start|stop|restart|reload}" >&2
exit 1
;;
esac
exit 0
# redmine
# Passenger standalone for Redmine
description "Passenger standalone for Redmine"
author "Cédric Darné"
console output
env HOME="/home/cdarne" # Passenger needs HOME to be set
env app_name="redmine" # Unique app name/id
env app_dir="$HOME/Code/ruby/redmine" # RoR Application root dir
env rvm_env="$HOME/.rvm/environments/ruby-1.9.3-p194@redmine" # RoR Application root dir
env log_file="/var/log/redmine.log" # RoR Application root dir
env ps_user="cdarne" # User to run passenger as
env ps_addr="127.0.0.1" # Bind to this IP
env ps_port="1984" # Port for incoming connections
start on started-postgresql
stop on stopped-postgresql
# this makes the script hanging forever until reboot :(
#expect fork
script
exec su -s /bin/bash -c ". $rvm_env; cd $app_dir; passenger start -e production -a $ps_addr -p $ps_port" $ps_user >> $log_file 2>&1
end script
# Restart if passenger dies
respawn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment