【问题标题】:Centos7 SystemD - Systemctl startup issueCentos7 SystemD - Systemctl 启动问题
【发布时间】:2019-03-17 17:27:37
【问题描述】:

我有我的 bash 脚本,我将我的服务设置为在其上运行 ExecStart - 现在我的 bash 脚本直接通过用户 'staytus' 运行,按预期启动和停止事情,但由于某种原因,当我不理解时通过 systemctl 运行它会抛出错误!

现在,由于它可以作为同一用户正常运行,因此我设置了要使用的服务,这有点告诉我问题出在启动文件上。

[Unit]
Description=Starts up procodile which runs staytus

[Service]
User=staytus
Type=simple
ExecStart=/usr/bin/startup/start.sh
Restart=on-abort

[Install]
WantedBy=multi-user.target

我尝试添加一个工作目录、更改用户等,但都没有成功 - 关于尝试什么的任何其他建议?

Oct 12 15:36:52 system-name start.sh: /usr/local/bin/procodile: line 10: require: command not found
Oct 12 15:36:52 system-name start.sh: /usr/local/bin/procodile: line 12: version: command not found
Oct 12 15:36:52 system-name start.sh: /usr/local/bin/procodile: line 16: syntax error near unexpected token `('
Oct 12 15:36:52 system-name start.sh: /usr/local/bin/procodile: line 16: `  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding'
Oct 12 15:36:52 system-name systemd: status.service: main process exited, code=exited, status=2/INVALIDARGUMENT

【问题讨论】:

  • 它会抛出什么错误?
  • 在组织帖子中添加了详细信息
  • /usr/local/bin/procodile 缺少包含所有环境的 ruby​​ 环境。还是 start.sh 脚本试图获取 procodile ruby​​ 脚本而不是执行它?

标签: centos centos7 startup systemd systemctl


【解决方案1】:

在 Systemd 上,ExecStart 运行的进程的环境变量与用户终端上的不同。

https://www.freedesktop.org/software/systemd/man/systemd.exec.html#Environment%20variables%20in%20spawned%20processes

您必须检查运行正常的环境变量(可能在终端上使用set 命令)并使用Environment="VAR1=VALUE1" "VAR2=VALUE2" 在systemd 服务定义中添加所需的变量。见https://www.freedesktop.org/software/systemd/man/systemd.exec.html#Environment

【讨论】:

    猜你喜欢
    • 2016-11-06
    • 1970-01-01
    • 1970-01-01
    • 2015-06-13
    • 2014-05-25
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    • 2022-08-03
    相关资源
    最近更新 更多