![可执行路径不是绝对的](https://linux22.com/image/1613231/%E5%8F%AF%E6%89%A7%E8%A1%8C%E8%B7%AF%E5%BE%84%E4%B8%8D%E6%98%AF%E7%BB%9D%E5%AF%B9%E7%9A%84.png)
我正在尝试通过使用以下环境变量来应用 DRY:
Environment='SHARED=/var/www/backend/shared/'
Environment='QUEUE=critical'
Environment='BUNDLE_PATH=/home/ubuntu/.rvm/gems/ruby-2.3.0/bin/bundle'
ExecStart=${BUNDLE_PATH} exec sidekiq -q {$QUEUE} --index 0 --pidfile ${SHARED}tmp/pids/sidekiq_reserved_${QUEUE}.pid -e production --logfile ${SHARED}log/sidekiq_reserved_${QUEUE}.log --config ${SHARED}config/sidekiq_${QUEUE}.yml --daemon
但是,我收到错误:
[/lib/systemd/system/sidekiq.service:30] Executable path is not absolute, ignoring: ${BUNDLE_PATH} exec sidekiq -q {$QUEUE} --index 0 --pidfile ${SHARED}tmp/pids/sidekiq_reserved_${QUEUE}.pid -e production --logfile ${SHARED}log/sidekiq_reserved_${QUEUE}.log --config ${SHARED}config/sidekiq_${QUEUE}.yml --daemon
sidekiq.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
sidekiq.service: Failed to create sidekiq.service/start: Unit sidekiq.service is not loaded properly: Invalid argument.
那么,这是我替换环境变量的方式的问题吗?有什么想法吗?
答案1
您不能使用变量作为命令。您可以通过先启动 shell 或直接对可执行文件的路径进行硬编码来解决此问题。
ExecStart=/bin/bash -c '${BUNDLE_PATH} sidekiq -q {$QUEUE} ...'
我很好奇,看起来他们正在考虑添加这个:
https://github.com/systemd/systemd/issues/1274
所以去看看这个问题,对我来说似乎很有用!