Centos systemctl启动脚本-Ruby错误的解释器

时间:2018-10-06 17:03:39

标签: bash shell path centos7

systemctl尝试运行启动脚本时出现以下错误

/usr/bin/startup/status_start.sh: /usr/local/bin/procodile: /usr/bin/ruby: bad interpreter: No such file or directory

这是我的开始脚本

#!/usr/bin/bash
cd /opt/staytus/staytus/
procodile start

现在,我认为这与bash shell和PATH等有关,但是我不太了解这个世界:)

我已经用#!/ usr / bin / bash和#!/ bin / bash尝试了我的启动脚本

还有其他建议吗?


更新1:

在脚本中添加一行以打印出“哪个红宝石”,从而导致以下错误

Oct 06 17:31:02 status.sh[11014]: which: no ruby in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)

这使我添加了更多

echo "current path:" $PATH
PATH=/opt/staytus/.rbenv/shims/ruby:$PATH
echo "new path:" $PATH

尽管进行了尝试,但在systemctl运行启动时仍然出现错误...

Oct 06 17:45:37 start.sh[2878]: current path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Oct 06 17:45:37 start.sh[2878]: new path: /opt/staytus/.rbenv/shims/ruby:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Oct 06 17:45:37 start.sh[2878]: /usr/bin/startup/start.sh: /usr/local/bin/procodile: /usr/bin/ruby: bad interpreter: No such file or directory

更新2

这是systemctl脚本

[Unit]
Description=Starts up procodile which runs staytus

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

[Install]
WantedBy=multi-user.target

以root身份运行版本时,请保持住状态

bash: /usr/bin/ruby: No such file or directory

Ruby似乎已安装在

which ruby
~/.rbenv/shims/ruby

更新3:

好,所以我决定通过另一个脚本将似乎缺少的路径流添加到我的脚本中,该脚本通过eval命令打印命令以设置环境

path.sh

#!/bin/sh
echo export PATH=/opt/staytus/bin/procodile:/opt/staytus/.rbenv/shims/ruby:/usr/lib64/ruby:/usr/share/ruby:/usr/bin/bash:$PATH

start.sh

#!/usr/bin/env bash
set -xv
whoami
echo "current path:" $PATH
cd /opt/staytus/staytus/
pwd
eval `/usr/bin/startup/path.sh`
echo "New path:" $PATH
procodile start

1 个答案:

答案 0 :(得分:0)

您的一个脚本-可能是/usr/local/bin/procodile,但可能会调用的某些脚本-以#!/usr/bin/ruby开头。

但是,您的Ruby解释器未安装为/usr/bin/ruby ,因此会中断。

找到负责的脚本,并将其第一行更改为#!/usr/bin/env ruby,这将遵循PATH来查找运行解释器。