Created
April 12, 2014 20:11
-
-
Save sfgeorge/10554372 to your computer and use it in GitHub Desktop.
Start Adhearsion in JRuby
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
# Start Adhearsion in JRuby, while building a pidfile as soon as possible. | |
def ahnctl_start | |
shell_command = "#{exec_ahn_async} && #{wait} && #{save_pid}" | |
%x{shell_command} | |
end | |
private | |
# Run start in the background, since it is not daemonized. | |
# This also makes it easier for us to nab the PID. | |
def exec_ahn_async | |
"( #{exec_ahn} & )" | |
end | |
# Start Adhearsion | |
def exec_ahn | |
exec_ahn = 'rvm $(cat .ruby-version) exec bundle exec ahn start .' | |
# Add action-specific options to the invoked command | |
exec_ahn << ' --no-console' | |
end | |
# Wait a moment to ensure that Java has spawned. | |
def wait | |
'sleep 1' | |
end | |
# Save the process id / PID | |
def save_pid | |
pid_file = '/path/to/adhearsion.pid' | |
"ps -fp $(/sbin/pidof java) | grep 'ahn start' | awk '{print $2}' > #{pid_file}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment