我在运行 Amazon Linux 2 的 AWS EC2 实例上克隆了一个 Node.js 应用程序。
server.js
我可以很好地执行项目的文件:
[ec2-user@ip-*********** portfolio_v3]$ nvm use 16
Now using node v16.19.1
[ec2-user@ip-*********** portfolio_v3]$ MAIL_JET_API_KEY_PRIVATE="..." NYT_API_KEY="..." node server.js
...
我正在尝试创建一个 systemd 服务,以便该应用程序始终运行,并且正在跟随本演练
我有以下内容/etc/systemd/system/portfolio-v3.service
[Unit]
Description=portfolio-v3
After=multi-user.target
[Service]
Environment=MJ_API_KEY_PRIVATE=1234567890
Environment=NYT_API_KEY=1234567890
ExecStart=/home/.nvm/versions/node/v16.19.1/bin/node /home/ec2-user/portfolio-v3/server.js
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=portfolio-v3
User=ec2-user
[Install]
WantedBy=multi-user.target
我已经以不同的顺序运行了以下所有命令:
sudo chmod 644 /etc/systemd/system/portfolio-v3.service
sudo systemctl daemon-reload
sudo systemctl enable portfolio-v3.service
sudo systemctl start portfolio-v3.service
但我不断看到以下内容:
$ sudo systemctl status portfolio-v3.service
● portfolio-v3.service - portfolio-v3
Loaded: loaded (/etc/systemd/system/portfolio-v3.service; enabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: exit-code) since Thu 2023-03-16 04:55:42 UTC; 8s ago
Process: 7067 ExecStart=/home/.nvm/versions/node/v16.19.1/bin/node /home/ec2-user/portfolio-v3/server.js (code=exited, status=203/EXEC)
Main PID: 7067 (code=exited, status=203/EXEC)
Mar 16 04:55:42 ip-172-31-18-127.us-west-2.compute.internal systemd[1]: portfolio-v3.service: main process exited, code=exited, status=203/EXEC
Mar 16 04:55:42 ip-172-31-18-127.us-west-2.compute.internal systemd[1]: Unit portfolio-v3.service entered failed state.
Mar 16 04:55:42 ip-172-31-18-127.us-west-2.compute.internal systemd[1]: portfolio-v3.service failed.
$ systemctl
UNIT LOAD ACTIVE SUB DESCRIPTION
proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitrary Executable File Formats File System Automount Point
sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS1
sys-devices-platform-serial8250-tty-ttyS2.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS2
sys-devices-platform-serial8250-tty-ttyS3.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS3
sys-devices-pnp0-00:06-tty-ttyS0.device loaded active plugged /sys/devices/pnp0/00:06/tty/ttyS0
sys-devices-vbd\x2d51712-block-xvda-xvda1.device loaded active plugged /sys/devices/vbd-51712/block/xvda/xvda1
sys-devices-vbd\x2d51712-block-xvda.device loaded active plugged /sys/devices/vbd-51712/block/xvda
sys-devices-vif\x2d0-net-eth0.device loaded active plugged /sys/devices/vif-0/net/eth0
sys-subsystem-net-devices-eth0.device loaded active plugged /sys/subsystem/net/devices/eth0
-.mount loaded active mounted /
dev-hugepages.mount loaded active mounted Huge Pages File System
dev-mqueue.mount loaded active mounted POSIX Message Queue File System
run-user-1000.mount loaded active mounted /run/user/1000
sys-kernel-debug.mount loaded active mounted Debug File System
var-lib-nfs-rpc_pipefs.mount loaded active mounted RPC Pipe File System
brandbot.path loaded active waiting Flexible branding
systemd-ask-password-plymouth.path loaded active waiting Forward Password Requests to Plymouth Directory Watch
systemd-ask-password-wall.path loaded active waiting Forward Password Requests to Wall Directory Watch
session-897.scope loaded active running Session 897 of user ec2-user
acpid.service loaded active running ACPI Event Daemon
amazon-ssm-agent.service loaded active running amazon-ssm-agent
atd.service loaded active running Job spooling tools
auditd.service loaded active running Security Auditing Service
chronyd.service loaded active running NTP client/server
cloud-config.service loaded active exited Apply the settings specified in cloud-config
cloud-final.service loaded active exited Execute cloud user/final scripts
cloud-init-local.service loaded active exited Initial cloud-init job (pre-networking)
cloud-init.service loaded active exited Initial cloud-init job (metadata service crawler)
crond.service loaded active running Command Scheduler
dbus.service loaded active running D-Bus System Message Bus
[email protected] loaded active running Getty on tty1
gssproxy.service loaded active running GSSAPI Proxy Daemon
kmod-static-nodes.service loaded active exited Create list of required static device nodes for the current kernel
libstoragemgmt.service loaded active running libstoragemgmt plug-in server daemon
lvm2-lvmetad.service loaded active running LVM2 metadata daemon
lvm2-monitor.service loaded active exited Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress polling
network.service loaded active running LSB: Bring up/down networking
portfolio-v3.service loaded activating auto-restart portfolio-v3
有任何想法吗?也用谷歌搜索过code=exited, status=203/EXEC
,但结果到处都是。
谢谢 :)
编辑
尝试server.js
直接使用我想要的节点版本的绝对路径运行也失败:
[ec2-user@ip-172-31-18-127 portfolio_v3]$ /home/.nvm/versions/node/v16.19.1/bin/node server.js
-bash: /home/.nvm/versions/node/v16.19.1/bin/node: No such file or directory
[ec2-user@ip-172-31-18-127 portfolio_v3]$ cd
[ec2-user@ip-172-31-18-127 ~]$ ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc .gitconfig .lesshst .npm .nvm portfolio_v3 .ssh .vim .viminfo .vimrc
[ec2-user@ip-172-31-18-127 ~]$ cd .nvm
[ec2-user@ip-172-31-18-127 .nvm]$ ls
alias bash_completion nvm-exec nvm.sh versions
[ec2-user@ip-172-31-18-127 .nvm]$ cd versions
[ec2-user@ip-172-31-18-127 versions]$ ls
node
[ec2-user@ip-172-31-18-127 versions]$ cd node
[ec2-user@ip-172-31-18-127 node]$ ls
v16.19.1 v18.15.0
[ec2-user@ip-172-31-18-127 node]$ cd v16.19.1/
[ec2-user@ip-172-31-18-127 v16.19.1]$ ls
bin CHANGELOG.md include lib LICENSE README.md share
[ec2-user@ip-172-31-18-127 v16.19.1]$ cd bin
[ec2-user@ip-172-31-18-127 bin]$ ls
corepack node npm npx
[ec2-user@ip-172-31-18-127 bin]$ which node
~/.nvm/versions/node/v18.15.0/bin/node
[ec2-user@ip-172-31-18-127 bin]$