-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PM2 reload vs start vs resurrect in systemd #2914
Comments
We should definitely do something about this.
Usually this is how I do, and I'd say it's how pm2 is supposed to work:
I don't had any, and nope
Indeed this is odd. You shouldn't need to launch
Because you have a single
In your case I may even go further by not using |
Hi Dylan, We use a similar set up to deploy our nodejs microservices (1 microservice per instance). We use a Centos AMI and we provision the instance with puppet. Our instances are in an autoscaling group so they're able to be scaled up/down where we need to with no issues. We manage the node service with pm2, and we manage pm2 via a systemd service. We have a templated systemd service file, which we place in We don't use the startup/resurrect behaviour as it doesn't fit in with our use case. Once you have the service running, to update we just do a Its important to treat pm2 and the node service as its own app. When you normally start pm2 for example, it will create its HOME (and its various log/dump files) inside the user who ran it. This doesn't lend itself well to automation, however its easy to overcome. For example, we set the Here's a copy of our pm2.service file
and our
This is all pretty simple to do via puppet. Install nodejs, npm, pm2 and the application package. Create the pm2.service file (with the template), the directories we use, and then the Let me know if you have any more questions. We weren't exactly sure of how to do this either, but we've been running and deploying nodejs services this way for a couple of months now and it seems to be doing well. |
@cam-itv this is really nice job there! Would you mind if I add some of your examples to the official documentation to help further users? Thanks for taking the time to share ❤️. |
@soyuka Thanks! Yeah sure, go for it! I'm not a systemd expert, so there might be better ways to do it. A couple of caveats, for the |
It's definitely better to make a custom unit file that better fit your needs. The |
Still @vmarchaud any reason we also dump |
Because generally you expect that your process state is the same after a reboot than when you started the process. |
Thank you for the thoughtful replies everyone (especially @cam-itv). We will use an approach that is very similar to that of @cam-itv. Here are our files for reference. The main difference is that our pm2 manifest (ecosystem.json) is always in the same location, so there is nothing dynamic about the systemd unit file. Regarding puppet/modules/common/service/templates/pm2-systemd.service.erb
puppet/modules/common/service/templates/pm2_config.service.erb (pm2 manifest)
An example service_cfg array would look like this:
|
Closing this issue since I've gotten enough useful feedback. Thanks again to everyone! @soyuka: feel free to use our configs as examples as well. I'd also be happy to contribute a puppet + pm2 tutorial if you want. Ping me on slack if you're interested. |
Just adding that |
Ah ok, thanks for that - good to know 😄 |
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
It seems my difficulty with start / stop was not misplaced. PM2 wants to save the state and this is problematic when managing the starting and stopping via systemd. Running without the PM2 daemon seems to work better. Also, I am removing Type=forking, which will cause this to use the simple type. Not sure about that, but it seems to be what people are using with PM2 and systemd. See: Unitech/pm2#2914
What's going wrong?
There is no bug, this is a question about best practices. Please see the background and questions below. I sincerely appreciate any time spent on helping me to understand PM2 better!
Supporting information
Background
(My understanding)
PM2 offers a
startup
command, which will install a systemd unit file.The unit file configures systemd to start PM2 on boot using the
pm2 resurrect
command.The
resurrect
command reads a dump file inPM2_HOME
, which records the state of PM2 managed processes: PM2 settings, environment vars, etc...The dump file is created when
pm2 startup
is run, and whenpm2 save
is run.Our servers use a single PM2 manifest to manage all node.js processes (usually just one process).
We are interested in directly starting PM2 using
pm2 reload /path/to/pm2/manifest.json --no-daemon
from within the systemd unit file, rather than relying on the resurect/dump-file system.Here is an example systemd unit file that we might use:
Reasons for avoiding the dump file and resurrect are:
Questions
resurrect
has some additional protections that make it play well with systemd.pm2 save
can capture a heterogeneous environment well, but having to callpm2 save
as part of our deployment procedure doesn't sit well.pm2 save
? The only way that we can think of to get this to work with our provisioning and deployment system is to make our deployment bounce command bepm2 reload && pm2 save
. This feels odd, so we would like to know what others are doing.More background than you probably wanted
This model for integration with systemd is tricky to integrate with our server provisioning system. During provisioning, we use Puppet to install Nodejs, npm and PM2. We also place a standardized pm2 manifest on disk that will be used to start the node services once the source code is deployed. This is the time when we would ideally run
pm2 startup
to setup the systemd files, however, our services have not been started with PM2 yet.That's not a problem really, as we can just run
pm2 save
after runningpm2 reload
as part of our deployment. Thus, the command to bounce our services becomespm2 reload {{/path/to/pm2/manifest}} && pm2 save
.Still, the team and I have decided that it would be simpler to hard-code
pm reload /path/to/pm2/manifest.json
into the systemd unit file, than to addpm2 save
to our deployment process.The text was updated successfully, but these errors were encountered: