【发布时间】:2023-08-20 09:30:01
【问题描述】:
您好 Stack Overflow 团队,
我有一个使用 daemon runner 用 python 编写的守护进程。即
from daemon import runner
import random
import time
class App():
def __init__(self):
self.stdin_path = '/dev/null'
self.stdout_path = '/dev/null'
self.stderr_path = '/dev/null'
self.pidfile_path = '/var/run/my_daemon.pid'
self.pidfile_timeout = 5
def run(self):
seed = random.seed()
rtime = random.randrange(21600,42300)
count = 0
while True:
count += 1
main()
time.sleep(rtime)
app = App()
daemon_runner = runner.DaemonRunner(app)
在同一个守护程序中,当守护程序发现需要写入我们的远程数据库时,我使用:from cryptography.fernet import Fernet 来解密我们的数据库密码。
即
from cryptography.fernet import Fernet
def getTheIngredients(recipe):
cipher_suite = Fernet(recipe['lock_smith'].encode())
og_kush = cipher_suite.decrypt(recipe['og_kush_repro'].encode())
raw_bacon = recipe['bacon'].encode()
the_son_of_anton = Fernet(og_kush)
bacon = the_son_of_anton.decrypt(raw_bacon)
return bacon
我使用pyinstaller --onefile my_daemon.py 部署这个守护进程
并使用以下命令构建 rpm:rpmbuild -ba my_custom_daemon.spec
spec 文件的样子:
Name: my_daemon
Version: 1.1.1
Release: 0%{?dist}
Summary: my little daemon
Group: Miscellaneous
License: GPL
#URL:
Source0: my_daemon-1.1.1.tar.gz
BuildArch: x86_64
#BuildRequires: systemd
#Requires:
%description
my little daemon that does stuff :-)
%prep
%setup -q
%build
%install
rm -rf $RPM_BUILD_ROOT
install -d -m 0755 $RPM_BUILD_ROOT/usr/local/bin/
install -m 0755 my_daemon $RPM_BUILD_ROOT/usr/local/bin
mkdir -p %{buildroot}%{_unitdir}/
install -m 0644 %{name}.service %{buildroot}%{_unitdir}/
%post
%systemd_post %{name}.service
%clean
rm -rf $RPM_BUILD_ROOT
%files
%doc
/usr/local/bin/my_daemon
%{_unitdir}/my_daemon.service
%changelog
* Tue Jun 08 2021 M E <me@me.com> - 1.1.1-0
- stuff
- more stuff
当我的守护进程运行时,以下异常被捕获:
'No module named '_hmacopenssl'
而且我非常确定该异常与我添加用于为我解密的cryptography.fernet 有关。因为在我进行这些更改之前,我的守护进程运行良好。
所以在构建的 rpm 之外运行我的守护进程可以正常工作。 但是一旦我打包它并尝试通过安装的 rpm 运行它,它就会抛出该异常。
非常感谢您在这方面的任何帮助/指导。
【问题讨论】:
标签: python cryptography pyinstaller rpm rpmbuild