Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1019 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Does pm2 auto restart application after reboot by default?

#1
I have an issue with my linux server and need to reboot, before that I run my node application with `pm2 start server.js` without any other config. Can it auto restart my app after reboot server?
Reply

#2
Not by default, but PM2 can do so using a [startup script](

[To see links please register here]

):

> PM2 can generate startup scripts and configure them in order to keep
> your process list intact across expected or unexpected machine
> restarts.

After generating your startup script (read also this [comment](

[To see links please register here]

)), take a look at `pm2 save`:

> Once you started all the applications you want to manage, you have to
> save the list you wanna respawn at machine reboot with:
>
> `pm2 save`

Reply

#3
You can use this script before run `pm2 save`:

pm2 startup
[PM2] You have to run this command as root. Execute the following command:
sudo su -c "env PATH=$PATH:/home/unitech/.nvm/versions/node/v14.3/bin pm2 startup <distribution> -u <user> --hp <home-path>


[To see links please register here]

Reply

#4
**First of all I run below command**

`pm2 save`

Then edit **crontab**

nano /etc/crontab

**Then Add**

* * * * * pm2 resurrect
Reply

#5
No, if you do not add a startup command then it will close after reboot so

you can use:
```bash
pm2 startup ubuntu
```

After this, it's always run after closing the server in the terminal.
Reply

#6
I used another alternative way on Ubuntu 20.04 and it worked!

Make sure you have saved the pm2 configuration (**pm2 save**)

**First edit the crontab file**

```
crontab -e
```
**Then paste the following command**
```
@reboot /usr/lib/node_modules/pm2/bin/pm2 resurrect && /usr/lib/node_modules/pm2/bin/pm2 start all
```
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through