This is a part of the startup script for my compute engine instance
# Configure supervisor to run the node app.
cat >/etc/supervisor/conf.d/node-app.conf << EOF
[program:nodeapp]
directory=/opt/app
command=sudo node app.js
autostart=true
autorestart=true
user=nodeapp
environment=HOME="/home/nodeapp",USER="nodeapp",NODE_ENV="production"
stdout_logfile=syslog
stderr_logfile=syslog
EOF
If you notice this line
command=sudo node app.js
originally it was just
command=node app.js
but since my app is listening on port 80, I modified it so I could have root access. When my virtual machine starts up, it executes the script but I can't access my website, when I SSH into the instance and type
sudo node app.js
however, everything works. You can't have sudo commands in the startup script?
如果您无论如何都以root
身份运行 Node(这是使用sudo
的效果),您不妨设置user=root
(或完全删除该设置)并保留原始command
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.