Last active
December 17, 2015 01:19
-
-
Save carlzulauf/5527048 to your computer and use it in GitHub Desktop.
Thin initd script. Spawns thin daemons from a config directory using a specific non-privileged user (`carl`).
This file contains 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
#!/usr/bin/env ruby | |
# thin init script | |
# install to /etc/init.d/thin | |
# crazy debian LSB header stuff | |
### BEGIN INIT INFO | |
# Provides: thin | |
# Required-Start: $local_fs $remote_fs | |
# Required-Stop: $local_fs $remote_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: S 0 1 6 | |
# Short-Description: thin initscript | |
# Description: thin | |
### END INIT INFO | |
CONFIG = "/home/carl/www/thin" | |
BUNDLE = "/home/carl/.rvm/gems/ruby-2.0.0-p0@global/bin/bundle" | |
USER = "carl" | |
def call_thin(action = "start") | |
Dir[File.join(CONFIG, "*.yml")].each do |config| | |
dir=`awk '/^chdir:/ { print $2; }' #{config}`.chomp | |
cmd = "cd #{dir} && #{BUNDLE} exec thin #{action} -C #{config}" | |
wrapper = "su -l #{USER} -c '#{cmd}'" | |
puts "Executing:\n#{wrapper}" | |
system wrapper | |
end | |
end | |
case ARGV.first | |
when 'start' | |
call_thin "start" | |
when 'stop' | |
call_thin "stop" | |
when 'restart' | |
call_thin "restart" | |
else | |
puts "usage: $0 start|stop|restart" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can't believe I never thought of this.