Open navinspm opened 6 years ago
As a better way, I use daemons.py. After installing it using gem install daemons, you can use a special file to launch it
ebook.rb
#!/usr/bin/ruby2.3
#
# This file was generated by RubyGems.
#
# The application 'twitter_ebooks' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0.a"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
version = $1
ARGV.shift
end
end
system("pwd")
Dir.chdir "/usr/local/lib/mybot_ebooks"
system("pwd")
load Gem.bin_path('twitter_ebooks', 'ebooks', version)
ebooks_daemon.rb
# this is ebooks_daemon.rb
require 'daemons'
Daemons.run('ebook.rb')
To invoke that daemon then
ruby ebooks_daemon.rb run -- start mybot_ebooks
To stop it
ruby ebooks_daemon.rb stop
to get a status
ruby ebooks_daemon.rb status
The double dash after the command run is a way to pass parameters to the program ebook.rb
I am running ebooks in production server, using
ebooks start &
But If I am killing the pid, ebooks starts new process automatically. I cant able to kill the process completely.