1 # http://www.bigbold.com/snippets/posts/show/2265
9 WorkingDirectory = File.expand_path(FileUtils.pwd)
12 File.join(WorkingDirectory, "matzbot.pid")
16 case config[:daemonize]
25 puts "Invalid command. Please specify start, stop or restart."
35 Dir.chdir WorkingDirectory
37 STDIN.reopen "/dev/null"
38 STDOUT.reopen "/dev/null", "a"
53 unless File.file? pid_fn
54 puts "Pid file not found. Is the daemon started?"
59 puts "Process killed."
60 Process.kill("TERM", pid) rescue nil
63 def store(pid=Process.pid)
65 puts "** Already started with PID #{File.read(pid_fn)}"
68 File.open(pid_fn, 'w') { |f| f << pid }
73 IO.read(pid_fn).to_i rescue nil