/ usr / bin / env ruby 在systemd中找不到

问题描述 投票:-1回答:1

我正在尝试将Rails应用设置为在Ubuntu机器上作为systemd服务运行。我已经用工头导出了服务文件,并且看起来一切都很好,除了可执行文件全部失败,因为env找不到ruby。我正在使用rbenv进行红宝石管理。

每个脚本的开头是:#!/usr/bin/env ruby

在journalctl中出现的错误:/usr/bin/env: ‘ruby’: No such file or directory

我的所有服务文件都指定将所有内容设置为的用户。

my-app-web.1.service

[Unit]
PartOf=my-app.target
StopWhenUnneeded=yes

[Service]
User=my-user
WorkingDirectory=/home/my-user/my-app
Environment=PORT=5100
Environment=PS=web.1
ExecStart=/bin/bash -lc 'exec -a "my-app-web.1" bin/rails s'
Restart=always
RestartSec=14s
StandardInput=null
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=%n
KillMode=mixed
TimeoutStopSec=5

当我以用户身份登录时,我看到红宝石如预期般出现。

my-user@box:~/my-app$ which ruby
/home/my-user/.rbenv/shims/ruby

以我的用户身份运行ExecStart命令也可以:

my-user@box:~/my-app$ /bin/bash -lc 'exec -a "my-app-web.1" bin/rails s'
=> Booting Puma
=> Rails 5.2.3 application starting in development 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.2 (ruby 2.5.7-p206), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000

我是否缺少有关如何以指定用户身份运行这些服务的信息?

ruby-on-rails ruby ubuntu-18.04 systemd rbenv
1个回答
0
投票

在整个系统范围内安装ruby(/home),或者将完整路径保存到主目录中安装的ruby的$ PATH中。第一种方法更好。

© www.soinside.com 2019 - 2024. All rights reserved.