-1

I have a Node.js application cloned on an AWS EC2 instance running Amazon Linux 2.

I can execute the project's server.js file just fine:

[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
...

I am trying to create a systemd service so that the app will run all the time, and am following along with this walkthrough

I have the following in /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

I have run all the following in various orders:

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

But I keep seeing the following:

$ 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
getty@tty1.service                                            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

Any ideas? Googled code=exited, status=203/EXEC as well but the results are all over the place.

Thanks :)

Aaron Parisi
  • 464
  • 7
  • 15
  • 1
    I’m voting to close this question because From the tag: systemd questions should be for *programming questions* using systemd or its libraries. Questions about *configuring the daemon* (including writing unit files) are better directed to Unix & Linux: https://unix.stackexchange.com. Please delete this. – Rob Mar 16 '23 at 12:47

1 Answers1

0

I think your directory is wrong /home/.nvm/versions/node/v16.19.1/bin/node

it should be ExecStart=/home/ec2-user/.nvm/versions/node/v16.19.1/bin/node