Skip to content

Instantly share code, notes, and snippets.

@drscream
Last active December 23, 2015 04:19
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save drscream/6579478 to your computer and use it in GitHub Desktop.
Gentoo Redmine Unicorn: The `unicorn.redmine` file should be created as `unicorn` file in `/etc/init.d/`. After that you should symlink the file to the correct app name, for example to `unicorn.redmine`. Create a configuration file in `/etc/conf.d/` that should be named as the app name.
## /etc/conf.d/unicorn
## Project directory where the ruby files are located
PROJECT_DIR="/local/sites/com/<something>/redmine"
## User which unicorn will run (Default: unicorn)
PROJECT_USER="redmine"
## Project name only be used for identification (Default: service name)
#PROJECT_NAME=""
## Path to the rvm binary (Default: ~${PROJECT_USER}/.rvm/bin/rvm)
#RVM=${PROJECT_USER}/.rvm/bin/rvm
## Ruby version used in the RVM to exec unicorn (Default: all)
#RVM_RUBY_VERSION="all"
## RVM arguments that using some variables above (Default: ${RVM_RUBY_VERSION} exec)
#RVM_ARGS=${RVM_RUBY_VERSION} exec
## PID file location (Default: /var/run/unicorn_${PROJECT_NAME}.pid)
UNICORN_PID="/local/sites/com/<something>/redmine/unicorn/unicorn.pid"
## Additional parameters for the unicorn binary (Default: -D)
#UNICORN_PARAM="-D"
## Configuration file for the unicorn service
UNICORN_CONFIG="/local/sites/com/<something>/redmine/unicorn/config.rb"
#!/sbin/runscript
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
depend() {
need net
use nginx
after sshd
}
configtest() {
ebegin "Checking ${SVCNAME} configuration"
checkconfd
eend $?
}
checkconfd() {
if [ ${SVCNAME} == 'unicorn' ]; then
eerror "Symlink the file to the correct service name and"
eerror "create a new configuration file in /etc/conf.d"
return 1
fi
PROJECT_USER=${PROJECT_USER:-"unicorn"}
PROJECT_NAME=${PROJECT_NAME:-${SVCNAME#*-}}
UNICORN_PID=${UNICORN_PID:-"/var/run/unicorn_${PROJECT_NAME}.pid"}
UNICORN_PARAM=${UNICORN_PARAM:-"-D"}
RVM=${RVM:-"~${PROJECT_USER}/.rvm/bin/rvm"}
if [ ! -r ${RVM} ]; then
eerror "RVM does not exists: ${RVM}"
return 1
fi
RVM_RUBY_VERSION=${RVM_RUBY_VERSION:-"all"}
RVM_ARGS=${RVM_ARGS:-"${RVM_RUBY_VERSION} exec"}
PROJECT_DIR=${PROJECT_DIR}
if [ ! -d ${PROJECT_DIR} ]; then
eerror "PROJECT_DIR does not exist: ${PROJECT_DIR}"
return 1
fi
UNICORN_CONFIG=${UNICORN_CONFIG}
if [ ! -r ${UNICORN_CONFIG} ]; then
eerror "UNICORN_CONFIG does not exist: ${UNICORN_CONFIG}"
return 1
fi
DAEMON=${DAEMON:-"unicorn_rails -c ${UNICORN_CONFIG} ${UNICORN_PARAM}"}
}
start() {
configtest || return 1
ebegin "Starting app ${PROJECT_NAME}"
start-stop-daemon --start \
-u ${PROJECT_USER} \
-d ${PROJECT_DIR} \
-p ${UNICORN_PID} \
"${RVM}" -- ${RVM_ARGS} ${DAEMON}
eend $?
}
stop() {
configtest || return 1
ebegin "Stopping app ${PROJECT_NAME}"
start-stop-daemon --stop -u "${PROJECT_USER}" \
-p "${UNICORN_PID}" "${RVM}"
eend $?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment