我正在运行一个脚本(在 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')