我正在尝试创建一个服务来运行打字稿文件。
到目前为止,这是我的服务文件中的内容:
[Unit]
Description=Service that runs the Parenti Bot
After=network.target
[Service]
Type=simple
User=abias
ExecStart=/home/abias/.local/share/pnpm/ts-node /home/abias/projects/lemmygrad-parenti-bot/bot.ts
Restart=on-failure
[Install]
WantedBy=multi-user.target
#!/usr/bin/env ts-node
我在文件顶部添加了 shebang bot.ts
。我也确定要跑sudo chmod +x bot.ts
。尽管做了所有这些,当我sudo systemctl status
在我的服务上运行时,我得到以下输出:
× parentibot.service - Service that runs the Parenti Bot
Loaded: loaded (/usr/lib/systemd/system/parentibot.service; disabled; preset: disabled)
Active: failed (Result: exit-code) since Thu 2022-12-08 17:50:32 EST; 11s ago
Duration: 6ms
Process: 283671 ExecStart=/home/abias/.local/share/pnpm/ts-node /home/abias/projects/lemmygrad-parenti-bot/bot.ts (code=e>
Main PID: 283671 (code=exited, status=203/EXEC)
CPU: 3ms
Dec 08 17:50:32 fedora systemd[1]: parentibot.service: Scheduled restart job, restart counter is at 5.
Dec 08 17:50:32 fedora systemd[1]: Stopped parentibot.service - Service that runs the Parenti Bot.
Dec 08 17:50:32 fedora systemd[1]: parentibot.service: Start request repeated too quickly.
Dec 08 17:50:32 fedora systemd[1]: parentibot.service: Failed with result 'exit-code'.
Dec 08 17:50:32 fedora systemd[1]: Failed to start parentibot.service - Service that runs the Parenti Bot.
我可能做错了什么?
编辑:运行输出sudo journalctl -xeu yourService.service
Dec 08 17:50:32 fedora systemd[1]: Stopped parentibot.service - Service that runs the Parenti Bot.
░░ Subject: A stop job for unit parentibot.service has finished
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A stop job for unit parentibot.service has finished.
░░
░░ The job identifier is 22216 and the job result is done.
Dec 08 17:50:32 fedora systemd[1]: parentibot.service: Start request repeated too quickly.
Dec 08 17:50:32 fedora systemd[1]: parentibot.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ The unit parentibot.service has entered the 'failed' state with result 'exit-code'.
Dec 08 17:50:32 fedora systemd[1]: Failed to start parentibot.service - Service that runs the Parenti Bot.
░░ Subject: A start job for unit parentibot.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit parentibot.service has finished with a failure.
░░
░░ The job identifier is 22216 and the job result is failed.
编辑2: 的内容bot.ts
:可以看到这里。
编辑3:我刚刚运行journalctl
并看到这个错误:parentibot.service: Failed to locate executable /home/abias/.local/share/pnpm/ts-node
。这看起来可能是问题所在,但它提出了一个问题:为什么找不到可执行文件(我检查以确保存在)?
答案1
我明白问题出在哪里了。事实证明这只是我自己的用户/home/abias/.local/share/pnpm/ts-node
的位置。ts-node
要使用的 ts-node 的正确位置是/usr/bin/local/ts-node
。