用ssh在linux服务器上启动nodejs应用程序(如果我关闭ssh连接,应用程序停止了吗?)1-创建nodejs应用程序-它的功能2-在Linux服务器上运行-它的功能(我停止了Apache服务器)但是如果我关闭了SSH连接(与我的Windows PC),应用程序停止。我该如何解决此问题?
Use the nohup command to start the application. Like:
nohup THE_COMMAND_YOU_DONT_WANT_TO_STOP_WHEN_YOU_LOGOUT &
With nodemon it might be helpful to put the command to start the server in a file called myserver.sh containing:
nodemon server.js
Make sure the file is executable:
chmod +x myserver.js
And then run
nohup myserver.sh &
The most correct thing to do is to write a service file for it so whatever init system you have (likely systemd) will keep it running and manage the start/stop/restart stuff for you.
Failing that (and I don't blame you...) you can run it within the screen
utility. Launch it with screen -d -m /path/to/start/script
and then you can come back later and reconnect to it with screen -r
or screen -r <pid of the screen session>
.
Note that launching it that way won't restart it, etc. To do that, you could do something like
#!/bin/sh
while true
do
sleep 3s
/path/to/start/script
done
And call that with the screen 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.