express-admin
express-admin copied to clipboard
settings.json is deleted when running with forever process
This is not necessarily a bug but a pretty big gotcha and I think a better solution could be implemented.
Executing the following command:
forever start -w -a -l ~/log/admin.log node_modules/express-admin/app.js ./config
Will delete your config/settings.json file.
In app.js the following code will cause the settings file to temporarily be empty and trigger a reload by forever. Ultimately this causes forever to fail and deletes the settings.json file.
var fpath = path.join(args.dpath, 'settings.json'),
updated = settings.refresh(args.settings, data);
fs.writeFileSync(fpath, JSON.stringify(updated, null, 4), 'utf8');
A workaround is to run forever with a --spinSleepTime
so the file has time to write.
forever start --spinSleepTime=3000 -w -a -l ~/log/admin.log node_modules/express-admin/app.js ./config
Perhaps a better solution would be to maintain a schema.json file that is different from use generated settings.json and then merge them together at runtime using a loadash utility.
Something like:
var fpath = path.join(args.dpath, 'settings.json'),
_.defaults(mergedSettings, userSettings, defaultSettings);
fs.writeFileSync(fpath, JSON.stringify(mergedSettings, null, 4), 'utf8');
Thanks for the workaround, let's keep this open for future reference :+1:
Just wanted to add one more comment to this.
I've currently been exploring https://github.com/Unitech/pm2 and http://pm2.keymetrics.io/docs/usage/application-declaration/ rather than forever and the same issue occurs.
I've tried playing with all the following options and nothign seems to work. https://github.com/paulmillr/chokidar#path-filtering
"watch_options": {
"usePolling" : true,
"interval" : 5000,
"alwaysStat": true,
"awaitWriteFinish": {
"stabilityThreshold": 5000,
"pollInterval": 5000
},
"atomic": 5000
},
I guess for now I'll just have to restart on deploy.
If I haven't mentioned it, thanks for this tool, it's great for quick starting projects.