- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个Python脚本,可以作为CentOS 7中的systemd守护进程。该守护进程由我在virtualenv中创建的python版本执行。我正在尝试调整脚本,以便能够在环境变量中设置 virtualenv 路径,以便我可以通过一个变量更改路径并重新启动服务来轻松切换到不同的 virtualenv。我创建了 systemd 脚本,以便能够初始化守护进程的多个实例,这非常有效。当我尝试使用环境变量指向我的 python 解析器时,事情就会崩溃。这是我到目前为止所拥有的。
/etc/systemd/system/[email protected] :
[Unit]
Description=pipeline remove tickets worker instances as a service, instance %i
Requires=pipeline-remove.service
Before=pipeline-remove.service
BindsTo=pipeline-remove.service
[Service]
PermissionsStartOnly=true
Type=idle
User=root
ExecStart=/path/to/venv/bin/python /pipeline/python/daemons/remove_tickets.py
Restart=always
TimeoutStartSec=10
RestartSec=10
[Install]
WantedBy=pipeline-remove.service
/etc/systemd/system/pipeline-remove.service(启动所有实例):
[Unit]
Description=manages pipeline remove tickets worker instances as a service, instance
[Service]
Type=oneshot
ExecStart=/usr/bin/sh /usr/bin/pipeline-remove-start.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
管道删除启动.sh:
#!/bin/bash
systemctl start pipeline-remove@{1..2}
这对我来说非常有用,但是当我尝试按以下方式设置 python 目录时,事情就会崩溃:
/etc/profile.d/pipeline_envvars.sh:
PIPELINE_VIRTUALENV=/path/to/venv
/etc/systemd/system/[email protected] :
[Unit]
Description=pipeline remove tickets worker instances as a service, instance %i
Requires=pipeline-remove.service
Before=pipeline-remove.service
BindsTo=pipeline-remove.service
[Service]
PermissionsStartOnly=true
Type=idle
User=root
EnvironmentFile=/etc/profile.d/pipeline_envvars.sh
ExecStart=/${PIPELINE_VIRTUALENV}/bin/python /pipeline/python/daemons/remove_tickets.py
Restart=always
TimeoutStartSec=10
RestartSec=10
[Install]
WantedBy=pipeline-remove.service
然后我尝试启动它:
sudo systemctl daemon-reload
sudo systemctl restart pipeline-remove@{1..1}
sudo systemctl status pipeline-remove@{1..1}
状态显示以下退出代码 203,这意味着未找到可执行文件:
● <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6a6bfa6b3babfb8b3fba4b3bbb9a0b396e7f8a5b3a4a0bfb5b3" rel="noreferrer noopener nofollow">[email protected]</a> - pipeline remove tickets worker instances as a service, instance 1
Loaded: loaded (/etc/systemd/system/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b5b425b4e4742454e06594e46445d4e6b05584e595d42484e" rel="noreferrer noopener nofollow">[email protected]</a>; disabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: exit-code) since Fri 2018-01-26 15:04:50 UTC; 6s ago
Process: 11716 ExecStart=/${PIPELINE_VIRTUALENV}/bin/python /pipeline/python/daemons/remove_tickets.py (code=exited, status=203/EXEC)
Main PID: 11716 (code=exited, status=203/EXEC)
Jan 26 15:04:50 dev systemd[1]: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2a2bba2b7bebbbcb7ffa0b7bfbda4b792e3fca1b7a0a4bbb1b7" rel="noreferrer noopener nofollow">[email protected]</a>: main process exited, code=exited, status=203/EXEC
Jan 26 15:04:50 dev systemd[1]: Unit <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f3839a83969f9a9d96de81969e9c8596b3c2dd809681859a9096" rel="noreferrer noopener nofollow">[email protected]</a> entered failed state.
Jan 26 15:04:50 dev systemd[1]: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="37475e47525b5e59521a45525a584152770619445245415e5452" rel="noreferrer noopener nofollow">[email protected]</a> failed.
找到执行代码here 。还在系统日志/var/log/messages 中发现了这一点:
Jan 26 15:07:13 dev systemd: Starting pipeline remove tickets worker instances as a service, instance 1...
Jan 26 15:07:13 dev systemd: Failed at step EXEC spawning /${PIPELINE_VIRTUALENV}/bin/python: No such file or directory
Jan 26 15:07:13 dev systemd: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="55253c2530393c3b30782730383a233015647b263027233c3630" rel="noreferrer noopener nofollow">[email protected]</a>: main process exited, code=exited, status=203/EXEC
Jan 26 15:07:13 dev systemd: Unit <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="56263f26333a3f38337b24333b392033166778253324203f3533" rel="noreferrer noopener nofollow">[email protected]</a> entered failed state.
Jan 26 15:07:13 dev systemd: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dbabb2abbeb7b2b5bef6a9beb6b4adbe9beaf5a8bea9adb2b8be" rel="noreferrer noopener nofollow">[email protected]</a> failed.
Jan 26 15:07:23 dev systemd: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="72021b02171e1b1c175f00171f1d041732435c011700041b1117" rel="noreferrer noopener nofollow">[email protected]</a> holdoff time over, scheduling restart.
Jan 26 15:07:23 dev systemd: Started pipeline remove tickets worker instances as a service, instance 1.
当我尝试删除 ExecStart
中的前导 /
时,即使我的环境变量确实包含绝对路径,我也会收到相对路径错误:
Failed to start <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee9e879e8b8287808bc39c8b8381988baedfc09d8b9c98878d8b" rel="noreferrer noopener nofollow">[email protected]</a>: Unit is not loaded properly:
Invalid argument.
See system logs and 'systemctl status <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bacad3cadfd6d3d4df97c8dfd7d5ccdffa8b94c9dfc8ccd3d9df" rel="noreferrer noopener nofollow">[email protected]</a>' for
details.
状态显示如下:
vagrant@dev:~$ sudo systemctl status pipeline-remove@{1..1}
● <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="03736a73666f6a6d662e71666e6c756643322d706671756a6066" rel="noreferrer noopener nofollow">[email protected]</a> - pipeline remove tickets worker instances as a service, instance 1
Loaded: error (Reason: Invalid argument)
Active: inactive (dead)
Jan 26 15:11:39 dev systemd[1]: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b4b524b5e5752555e16495e56544d5e7b0a15485e494d52585e" rel="noreferrer noopener nofollow">[email protected]</a> failed.
Jan 26 15:11:42 dev systemd[1]: Stopped pipeline remove tickets worker instances as a service, instance 1.
Jan 26 15:11:42 dev systemd[1]: [/etc/systemd/system/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="64140d1401080d0a01491601090b1201244a170116120d0701" rel="noreferrer noopener nofollow">[email protected]</a>:12] Executable path is not absolute, ignoring: ${PIPELINE_VIRTUALENV}/bin/python /pipel...e_tickets.py
Jan 26 15:11:42 dev systemd[1]: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dfafb6afbab3b6b1baf2adbab2b0a9ba9feef1acbaada9b6bcba" rel="noreferrer noopener nofollow">[email protected]</a> lacks both ExecStart= and ExecStop= setting. Refusing.
我用了this指南帮助我开始,但现在我陷入困境。在从环境变量设置 python 可执行路径时,如何启动 python 守护进程?
最佳答案
经过更多阅读,我偶然发现了答案 here 。问题是 ExecStart
的第一个参数必须是文字:
ExecStart= Commands with their arguments that are executed when this service is started. For each of the specified commands, the first argument must be an absolute and literal path to an executable.
继续阅读 ExecStart 上的内容:
Variables whose value is not known at expansion time are treated as empty strings. Note that the first argument (i.e. the program to execute) may not be a variable.
我最终也偶然发现了这个answer这看起来是同样的问题。最后这就是有效的:用 shell 包装整个东西来运行:
[Unit]
Description=pipeline remove tickets worker instances as a service, instance %i
Requires=pipeline-remove.service
Before=pipeline-remove.service
BindsTo=pipeline-remove.service
[Service]
PermissionsStartOnly=true
Type=idle
User=root
EnvironmentFile=/etc/profile.d/pipeline_envvars.sh
ExecStart=/bin/sh -c '${PIPELINE_VIRTUALENV}/bin/python /pipeline/python/daemons/remove_tickets.py'
Restart=always
TimeoutStartSec=10
RestartSec=10
[Install]
WantedBy=pipeline-remove.service
所以ExecStart=/bin/sh -c '<your command>'
节省了时间,我现在可以为我的环境变量指定 python 解释器路径。将留下答案,希望能为其他人节省一些时间。
关于python - systemd execstart python 守护进程动态使用环境变量中的 virtualenv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48464270/
一 点睛 线程可以设置为守护线程,ThreadGroup 也可以设置为守护 ThreadGroup,但是若将一个 ThreadGroup 设置为 deamon,也并不会影响线程的 daemon 属性,
我有一个 python 脚本需要在启动时作为守护进程运行。进程从 tty(和 pdb)分离,但代码不运行。 我已经将它缩小到一个最小的例子 import daemon from time import
reactjs isMounted API 的文档提到: You can use this method to guard asynchronous calls to setState() or fo
我正在开发一个需要嵌入 HTTP 服务器的守护进程。我正在尝试使用 BaseHTTPServer 来完成它,当我在前台运行它时,它工作正常,但是当我尝试将守护进程 fork 到后台时,它停止工作。我的
我正在尝试使用 Apache Commons Daemon 使用 Daemon 接口(interface)来守护我的应用程序。 Java 应用程序本身不执行任何操作,只是写入 stout。 我编译了j
我正在使用 Bootle Python Web Framework 在 Ubuntu 上开发网络应用程序。是否有任何有效的方法来守护启动默认 bottlepy 网络服务器的脚本? 谢谢。 UPD:现在
我一直使用 bluepill成功地守护简单的 Ruby 脚本。然而这一次,我有一个脚本,它也在加载 Rails 环境,因此我可以访问 Rails 应用程序及其各自模型的数据库连接。我使用的 bluep
我试图守护一些代码,但我遇到了一些麻烦。 如果我用 tklogger() 调用代码,它运行得很好。但是,如果我在守护程序上下文中调用它,我会得到以下跟踪信息: Traceback (most rece
我打算使用 systemd 将 celery 4.3.0 作为守护进程运行,但它给了我这个错误: 它会启动 worker 但会很快停止它们。但是,我可以通过键入以下命令手动运行工作人员: celery
我是一名优秀的程序员,十分优秀!