# 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