我正在运行一个脚本(在AWS EC2实例上运行),该脚本不断从API提取状态立法数据,并将其持久化到SQLite3 .db文件。当我尝试在后台将脚本作为守护程序运行时,该过程立即停止,并且出现以下错误。
stateleg.rb: process with pid 4666 started.
Traceback (most recent call last):
11: from stateleg_daemon.rb:4:in `<main>'
10: from /usr/local/rvm/gems/ruby-2.5.1/gems/daemons-1.3.1/lib/daemons.rb:149:in `run'
9: from /usr/local/rvm/gems/ruby-2.5.1/gems/daemons-1.3.1/lib/daemons/cmdline.rb:121:in `catch_exceptions'
8: from /usr/local/rvm/gems/ruby-2.5.1/gems/daemons-1.3.1/lib/daemons.rb:150:in `block in run'
7: from /usr/local/rvm/gems/ruby-2.5.1/gems/daemons-1.3.1/lib/daemons/controller.rb:59:in `run'
6: from /usr/local/rvm/gems/ruby-2.5.1/gems/daemons-1.3.1/lib/daemons/application.rb:307:in `start'
5: from /usr/local/rvm/gems/ruby-2.5.1/gems/daemons-1.3.1/lib/daemons/application.rb:228:in `start_load'
4: from /usr/local/rvm/gems/ruby-2.5.1/gems/daemons-1.3.1/lib/daemons/application.rb:228:in `load'
3: from /home/ubuntu/stateleg.rb:8:in `<top (required)>'
2: from /home/ubuntu/stateleg.rb:8:in `new'
1: from /usr/local/rvm/gems/ruby-2.5.1/gems/sqlite3-1.4.1/lib/sqlite3/database.rb:89:in `initialize'
/usr/local/rvm/gems/ruby-2.5.1/gems/sqlite3-1.4.1/lib/sqlite3/database.rb:89:in `open_v2': unable to open database file (SQLite3::CantOpenException)
当我尝试在前台运行脚本时,脚本会完美运行,并将必要的信息写入.db文件。
如何使此守护程序打开数据库文件? SQLite3和Ruby守护程序在某种程度上不兼容吗?任何信息都将非常有帮助。
这是整个守护程序脚本。
require 'daemons'
Daemons.run('stateleg.rb')
答案 0 :(得分:0)