@kyletryon I was thinking of using AWS too, sounds like a very appealing idea. I ended up going with a company called "Digital Ocean" And just recently got it all working on their Droplet service. Look into them too.
Systemctl Dynamic Path: AWS EC2 + AWS Linux2
The recommended setup for nvm/npm/nodejs is per user.
Lets assume you created a user nodebb, installed nodejs under it, and revised .bashrc to set environment variables to point to the latest version (standard procedure):
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" #
Systemctl expects full path to executable. Unfortunately, that path may change when nodejs gets updated.
So how do we hack systemctl to use a dynamic path?
- Generate the env variables and dump them into a file
- Load the file into systemctl environment
See config below:
After=system.slice multi-user.target mongod.service syslog.target
ExecStartPre=/bin/bash -c -l '/usr/bin/env > /tmp/tmp_env ; /bin/echo NODE_ENV=production >> /tmp/tmp_env'
ExecStart=/usr/bin/env node loader.js --no-silent --no-daemon
Pay attention: Type=idle replaces Type=simple.