Linux systemctl 提示 报错 Failed to locate executable cd No such file or directory
目录
.service: Failed to locate executable cd: No such file or directory
.service: Failed at step EXEC spawning cd: No such file or directory
出现错误的原因是在 ExecStart 中使用了 cd 命令,但是 cd 命令不是可执行程序,而是 shell 内置命令,因此 systemd 无法直接执行 cd 命令。
使用 bash -c 命令来创建一个新的 shell 进程,在其中执行需要的命令序列。
[Unit]
Description=hugo
After=network.target
After=nginx.service
[Service]
User=root
Group=root
Type=simple
WorkingDirectory=/var/www/hugo-blog
ExecStart=/bin/bash -c '/usr/bin/hugo --gc --minify --cleanDestinationDir'
Restart=always
RestartSec=60s
[Install]
WantedBy=multi-user.target