![]() ![]() To view logs for your application: pm2 logs pm2 logs index │ 0 │ index │ default │ N/A │ fork │ 4528 │ 0s │ 15 │ online │ 0% │ 15.4mb │ ubuntu │ disabled │ Use -update-env to update environment variables To restart your application: pm2 restart pm2 restart index │ 0 │ index │ default │ N/A │ fork │ 0 │ 0 │ 15 │ stopped │ 0% │ 0b │ ubuntu │ disabled │ Applying action stopProcessId on app (ids: ) To stop your application: pm2 stop pm2 stop index Verify that your application is running: pm2 list pm2 list ![]() │ 0 │ index │ default │ N/A │ fork │ 4559 │ 0s │ 16 │ online │ 0% │ 7.2mb │ ubuntu │ disabled │ │ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │ Applying action restartProcessId on app (ids: ) Start your Node.js application with PM2: pm2 start pm2 start index.js You can start your Node.js application with PM2 and it will continue running even after you disconnect from the EC2 instance. PM2 is a process manager for Node.js applications that provides built-in support for keeping applications running in the background and automatically restarting them if they crash. You can use pm2 to keep your Node.js application running on an EC2 instance after disconnecting from SSH. Another option is by using the command: tmux kill-session -t session_name One option is to enter the exit command while connected to the session you want to kill. To kill/stop a session, you have two options. List all active sessions: tmux list-sessionsĬonnect to a named session: tmux attach-session -t session_name Start (and connect to) a new named session: tmux new-session -s session_nameĭetach from any session as described above: Ctrl+ B, D. To do this effectively, each session will be given a name. This can be useful if you need to run several processes in the background simultaneously. This tmux tutorial will teach you a bit more, and there is plenty more out there. This shows how to use tmux for your specific use case, but tmux can do much more than this. When I disconnect from tmux, the ssh connection is also killed. So now I can run maileo on a local command line and connect to the server, and the tmux session. This does ssh to the server and runs the command at the end - tmux attach -d The -t option ensures that a terminal is started - if a command is supplied then it is not run in a terminal by default. I run a mail client >inside tmux on a server, and I have a local alias: alias maileo='ssh -t tmux attach -d' You can go one step further >if you want and integrate the command into an alias for ssh. So when I login I can just type tt and reattach. In fact, you can use the -d option all the time. You can tell tmux to detach from the last connection and attach to your new connection by running tmux attach -d Note that if you accidentally lose the ssh connection (say your network goes down), tmux will still be running, though it may think it is still attached to a connection. When you login again, you can run tmux attachĪnd you will reconnect to tmux and see all the output that happened. Then, when you want to disconnect, you do Ctrl+ B, D (ie press Ctrl+B, then release both keys, and then press d) To start it the first time, just type tmux ![]() ![]() Then when you login in again later you can reconnect, and see all the output you missed. If you run it on a remote server, you can disconnect from it without the terminal dying. I use tmux, and would recommend you do to.īasically tmux will run a terminal (or set of terminals) on a computer. I would use a terminal multiplexer - screen being the best known, and tmux being a more recent implementation of the idea. Here is a great answer by Hamish Downer given to a similar question over at : tmux is widely used for this purpose, and is preinstalled on new Ubuntu EC2 instances. For those landing here from a google search, I would like to add tmux as another option. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |