Skip to content

Instantly share code, notes, and snippets.

@sfgeorge
Created April 12, 2014 20:11
Show Gist options
  • Save sfgeorge/10554372 to your computer and use it in GitHub Desktop.
Save sfgeorge/10554372 to your computer and use it in GitHub Desktop.
Start Adhearsion in JRuby
# 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