如何将用户的 PATH 添加到 systemd 服务而不对其进行硬编码?

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

我有一个像这样的systemd服务:

[Unit]
Description=description here
After=database.service

[Service]
Type=simple
User=user
WorkingDirectory=/home/user/project
ExecStart=/home/user/.local/share/pnpm/pnpm start
LoadCredentialEncrypted=a:/home/user/project/.credstore/a.cred
LoadCredentialEncrypted=b:/home/user/project/.credstore/b.cred
LoadCredentialEncrypted=c:/home/user/project/.credstore/c.cred
LoadCredentialEncrypted=d:/home/user/project/.credstore/d.cred

[Install]
WantedBy=multi-user.target

当我尝试启动它时,出现此错误:

> [email protected] start /home/user/project
> node .
sh: 1: node: not found
ELIFECYCLE  Command failed.

这是有道理的,PATH 环境变量不完整。我可以

printenv
并将正确的 PATH 环境变量复制到我的服务中,如下所示:

Environment=PATH=paste here

但这意味着我现在需要在 PATH 环境变量发生变化时编辑我的服务,但我不希望这样。是否没有更好的方法从用户获取 PATH 环境变量并将其附加到服务?

node.js environment-variables systemd pnpm
1个回答
0
投票

服务开始时间

.bashrc
阅读:

ExecStart=/bin/bash -c ". ~/.bashrc ; exec /home/user/.local/share/pnpm/pnpm start"

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