Last active
December 22, 2015 01:49
-
-
Save florentmorin/6399246 to your computer and use it in GitHub Desktop.
Autostart Adhearsion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: adhearsion | |
# Required-Start: $all | |
# Required-Stop: $network $local_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start the adhearsions at boot | |
# Description: Enable at boot time. | |
### END INIT INFO | |
# This is /etc/init.d/adhearsion (without .sh) | |
# init.d script for single or multiple adhearsion installations. Expects at least one .conf | |
# file in /etc/adhearsion | |
# | |
# Modified by http://github.com/killercup | |
# based on modified version by [email protected] http://github.com/jaygooby | |
# which is based on http://gist.github.com/308216 by http://github.com/mguterl | |
# | |
## A sample /etc/adhearsion/my_app.conf | |
## | |
## AHN_ENV=production | |
## AHN_ROOT=/var/apps/www/my_app/current | |
## AHN_RUBY="/usr/local/rvm/bin/<WRAPPED_NAME>" #see rvm wrapper above | |
# | |
# This configures a unicorn master for your app at /var/apps/www/my_app/current running in | |
# production mode. | |
# | |
# If you call this script without any config parameters, it will attempt to run the | |
# init command for all your unicorn configurations listed in /etc/adhearsion/*.conf | |
# | |
# /etc/init.d/adhearsion start # starts all adhearsions | |
# | |
# If you specify a particular config, it will only operate on that one | |
# | |
# /etc/init.d/adhearsion start my_app | |
set -e | |
set -u | |
cmd () { | |
case $1 in | |
start) | |
${AHN_RUBY} ahn daemon "${AHN_ROOT}" | |
;; | |
stop) | |
${AHN_RUBY} ahn stop "${AHN_ROOT}" | |
;; | |
restart) | |
${AHN_RUBY} ahn stop "${AHN_ROOT}" | |
${AHN_RUBY} ahn daemon "${AHN_ROOT}" | |
;; | |
*) | |
echo >&2 "Usage: $0 <start|stop|restart>" | |
exit 1 | |
;; | |
esac | |
} | |
setup () { | |
cd "${AHN_ROOT}/script" || exit 1 | |
export AHN_ENV=${AHN_ENV} | |
} | |
start_stop () { | |
# either run the start/stop/reload/etc command for every config under /etc/adhearsion | |
# or just do it for a specific one | |
# $1 contains the start/stop/etc command | |
# $2 if it exists, should be the specific config we want to act on | |
if [ "$#" -eq 2 ]; then | |
. /etc/adhearsion/$2.conf | |
setup | |
cmd $1 | |
else | |
for CONFIG in /etc/adhearsion/*.conf; do | |
# import the variables | |
. $CONFIG | |
setup | |
# run the start/stop/etc command | |
cmd $1 | |
done | |
fi | |
} | |
if [ "$#" -eq 2 ]; then | |
ARGS="$1 $2" | |
else | |
ARGS="$1" | |
fi | |
start_stop $ARGS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adhearsion init.d script | |
Working with Ubuntu 12.04 and RVM on EC2 | |
1. Copy-paste adhearsion content to "/etc/init.d/" directory | |
2. Run "sudo chmod +x /etc/init.d/adhearsion" | |
3. Run "sudo /usr/sbin/update-rc.d -f adhearsion" | |
4. Create /etc/adhearsion directory (one configuration file per app) | |
5. Configure your applications in /etc/adhearsion/{app_name}.conf (sample code in "my_app.conf") | |
6. Run your service with "sudo service adhearsion start" | |
For app configuration: | |
- AHN_ROOT: your application directory | |
- AHN_ENV: your application environment | |
- AHN_RUBY: your ruby binary | |
Have fun :-) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AHN_ROOT=/home/ubuntu/adhearsion/my_app | |
AHN_ENV=production | |
AHN_RUBY=/home/ubuntu/.rvm/bin/my_app_ruby |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment