-
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 cluster mode fails to start because Error: ENOENT, no such file or directory
for process.cwd()
#1623
Comments
v0.9.1 v0.9.4 all have the same problem |
If I change to a complete new directory, "pm2 start" works just fine. Once I remove and recreate one of the old directory, "pm2 start" hangs and logging this error. 😞 |
I'm creating the directory with a new name every time to overcome this bug in PM2. I want to know why, so could someone familiar with PM2 tell me where the problem might be? |
@yinrong Are you using NODE4.0.0 I'm seeing these issues also. I need to kill pm2 daemon... |
which hosting solution are you using? |
Hi Guys, have 100% same problem with Capistrano deployment and PM2 Cluster mode. apps : [
// First application
{
name : "MyApp",
script : "app.js",
cwd : "/home/deployment/APP/MyApp/production/current",
log_date_format : "YYYY-MM-DD HH:mm Z",
error_file : "/home/deployment/APP/MyApp/production/shared/logs/app_error.log",
out_file : "/home/deployment/APP/MyApp/production/shared/logs/app_output.log",
instances : 3,
max_memory_restart : "1024M",
// cron_restart : "1 0 * * *",
watch : false,
ignore_watch : ["[\\/\\\\]\\./", "node_modules"],
merge_logs : false,
exec_interpreter : "node",
exec_mode : "cluster",
autorestart : false,
vizion : false,
max_restarts : 2,
min_uptime : "15s",
next_gen_js : false,
restart_delay : 4000,
env: {
COMMON_VARIABLE: "true",
NODE_ENV: "production",
APP_PORT: 8443,
APP_IP: "127.0.0.1"
},
env_production : {
NODE_ENV: "production"
}
}
] How looks pm2 show ID Describing process with id 7 - name MyApp
┌───────────────────┬──────────────────────────────────────────────────────────────────────┐
│ status │ stopped │
│ name │ MyApp │
│ id │ 7 │
│ path │ /home/deployment/APP/MyApp/production/current/app.js │
│ args │ │
│ exec cwd │ /home/deployment/APP/MyApp/production/current │
│ error log path │ /home/deployment/APP/MyApp/production/shared/logs/app_error-7.log │
│ out log path │ /home/deployment/APP/MyApp/production/shared/logs/app_output-7.log │
│ pid path │ /home/deployment/.pm2/pids/MyApp-7.pid │
│ mode │ cluster_mode │
│ node v8 arguments │ │
│ watch & reload │ ✘ │
│ interpreter │ node │
│ restarts │ 0 │
│ unstable restarts │ 1 │
│ uptime │ 0 │
│ created at │ 2015-09-19T19:45:03.739Z │
└───────────────────┴──────────────────────────────────────────────────────────────────────┘ Log in pm2.log:
This happens only in cluster mode, fork work pretty well. This mean PM2 itself caching some folders locations from 1st deployment and when 7 deployment triggered 1st folder (which was initial) removed, then i can see this problem with ENOENT, frankly stack trace totally not informative :) i was not able locate those lines in any files (guess this is normal behaviour for JS in general). As conclusion , i think this issue easy to duplicate if do next: Those steps above always lead to error with ENOENT |
Below folder structure for project which is under capistrano3 deployment tool .
└── production
├── current -> /home/deployment/APP/MyApp/production/releases/20150919193256
├── releases
│ ├── 20150919193205
│ ├── 20150919193215
│ ├── 20150919193232
│ ├── 20150919193239
│ ├── 20150919193249
│ └── 20150919193256
├── repo
│ ├── branches
│ ├── hooks
│ ├── info
│ ├── objects
│ └── refs
└── shared
├── app_configs
├── logs
└── node_modules
checked with lower history value and it is same, 2 releases + 1 current, 4th deployment hang with ENOENT error. This looks like problem exactly in PM2 and how it handling cluster mode :( |
@md2k Exact same set up, but it's weird because I'm having this issue with digitalocean, but not with my EC2 instances. What system are you running? |
@md2k I use https://github.com/shipitjs/shipit (like Capistrano, written in JS) and have same issue but It is unpredictable |
@iam4x it is dedicated servers, with Ubuntu 14.04 freshly installed, all 6 servers where i use PM2 have same issue. so it is 100% in PM2 side for cluster mode, it simply cached some path, and when folder removed simply unable to locate what it looking for, no other explanation. only for me really hard debug nodejs projects. @Jokero tried it before, but when i tried it, it was pretty buggy :) and as you said you also have issue, so we need to do something with PM2 and not jump over different deployment tools :) |
I'm using node v0.12.4. @iam4x |
Thanks for links @Unitech , i will check over weekends and post here my findings. |
my first finding that i unable duplicate problem when pm2 started with --no-daemon option :( |
@Unitech seems issue not from those 3 locations you mentioned above. |
unfortunately didn't found anything till now :( |
Seems i found something.
It is failing trying unlink pid file for application ID 1. only not clear why it trying to do so if application already stopped ? o_0 @Unitech can you point me to part of code where PM2 cleaning pid files and other similar staff? |
shoot me... when strace connected to pid i unable to duplicate issue. P.S. by strace i still can see No such file or directory with unlink command, but at least it not fail. |
Not very informative...
|
hm. one more finding:
@Unitech any idea how it possible to avoid (except pre start PM2 outside of App folder)? Long story short, it fail on getcwd(), duplicate issue possible even without nodejs. I assume this what happens with PM2 when it started from application folder which is symlink and PM2 formally started from real folder. But this only assumption at this moment, need do more tests. |
seems my assumption is correct: started pm from
after several deployments PM2 start throw error trying get list of apps while i in same directory:
As you can see, ENOENT occurred even for Then i do
but unable restart them, most probably because PM2 Home dir still points to not-exists folder which was removed due history limit of releases by capistrano (or whatever deployment tool which similar to capistrano's folder layout) Only it is not explain why with attached strace all was good, but frankly not remember from where i started PM2 yesterday during tracing process or no-damon option. But tested many times and if i pre-start PM2 outside symlink folder |
100% what i said in my last message is true for this kind of issue, question if we can some how programmatically lock PM2 during start to some specific folder without pre-start it manually outside of current release folder , PM2_HOME not affecting any how to this problem. i think issue in process.env.PWD for PM2 main process, question how to override it before start if it possible. @Unitech it is possible to add to PM2 one more command like 'pm2 up' which just starts PM2 manager process? currently do pm2 list to start manager :) |
@Unitech Hi, I think this is a major bug. Users have to kill PM2 to avoid this problem. In such way, most PM2 promising functionalities do not need to exist any more. |
@iam4x thanks for noticing. It's really a good workaround. |
Great finding @md2k we were just hit by the same issue. Using symlinks to current and after old build clean up pm2 starts to complain with:
Any progress on this issue? Seem pretty critical and dangerous, because you would think it works, roll to production boxes, start releasing and then suddenly whole thing breaks after 7th release and old builds cleanup.. |
We need a fix ASAP!!! Can we help? @soyuka? |
I won't say that it's a bug, it's just how cwd works. Proof:
I'm willing to fix this but I don't see any solution, I can wrap a try/catch around |
Anybody solved the issue? |
We ended up using upstart with chef to start intitial pm2 process on boot, before we run pm2 in the build folder. This approach seem to solve the problem, becaue pm2 is not tied to the build folder any more. But as more genearl solution (@soyuka) I was thinking maybe we should change current dir to / if it's anything else but / ? |
You (users) are the only ones who're able to change the pm2 cwd because it's the directory from where pm2 is launched. So, doing |
Just ran into this too. I am using shipit to deploy which symlinks the app dir to a release for rollback purposes. By default only the latest 2 releases stick around. So after 2 deploys the directory that pm2 was started in will be killed - causing the error. So @soyuka's solution is the way to go. I think the return value is a failure though because it requires the user to specify an app.json file to start. However, if you This should be fixed in PM2 though. |
Yes, but it's not really viable solution as most users will be unaware of this problem.. Still thinking for better and reliable approach/solution. At the moment we use upstart to start pm2 daemon on new box creation and then run pm2 within the apps, but it's all seems like walking on the thin ice.. |
So it appears to happen anytime the directory of the configured app is deleted :( I think I have to move to forever. EDIT Just realized PM2 follows symlinks when recording the app dir, so instead of |
@vjpr: In our case delete and start didn't work. After pm2 gets the error (the one in this thread) there is no way to make it work unless you kill the pm2 daemon. Also, delete and start doesn't take the advantage of a nice graceful reload. |
@gansbrest @vjpr I think our solution didn't work. It was okay for a few releases then back to the issue. |
Yes, once the folder is gone - some issue. When we kill pm2, remove .pm2 folder and then issue /etc/init.d/pm2 start, it displays start message and pm2 process launches (with no processes), but later when we go into the app and issue reload command, pm2 seem to memorize cwd at that very moment. Is there a way to use main process ( the one started with upstart with empty process list) pwd? Any thoughts @soyuka? |
Or maybe when we issue reload (and other commands) use fetch new cwd for started processes? Is it possible? |
I'm running a capistrano-like deployment too, and I'm not facing this issue. To avoid this cwd issue, as I said before, pm2 must not be started from the This is why it could break: 1 - First deployment:
2 - A bit later, fifth deployment, keeping only 4 releases, the first deployment release will be destroyed and so, the pm2 cwd will not exist anymore and it'll throw the The fix, or at least what I'm using: 1 - First deployment:
Where
FIY, I'm symlinking logs to the previous directory too, because I want to keep them accross different releases. @gansbrest Are you facing two different issues? One related to pm2 loosing it's |
|
@huangyingjie I had the same problem ( using a webpack env it was giving me a path is not a absolute path error ). Update solved it. It was a version issue? |
I had this same error pop up. I hadn't run the code for about a month (nor had I rebooted my laptop). I ran
Mac OS Sierra Hopefully that helps someone. |
@ThiagoMiranda Not update the pm2 version, but the pm2 instance in memory, because some app was deleted. node node_modules/.bin/pm2 delete someApp || true;
node node_modules/.bin/pm2 update || true;
node node_modules/.bin/pm2 start pm2.json |
same as #1244
This always happen when stop the old server, replace the source code, and start the new server.
One way to fix the problem is to kill PM2 and restart again. However, I can't do this, because I have to keep some processes running while stop/start the others.
The text was updated successfully, but these errors were encountered: