ProcessContainerFork.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * Copyright 2013-2022 the PM2 project authors. All rights reserved.
  3. * Use of this source code is governed by a license that
  4. * can be found in the LICENSE file.
  5. */
  6. var url = require('url');
  7. // Inject custom modules
  8. var ProcessUtils = require('./ProcessUtils')
  9. ProcessUtils.injectModules()
  10. if (typeof(process.env.source_map_support) != "undefined" &&
  11. process.env.source_map_support !== "false") {
  12. require('source-map-support').install();
  13. }
  14. // Rename the process
  15. process.title = process.env.PROCESS_TITLE || 'node ' + process.env.pm_exec_path;
  16. if (process.connected &&
  17. process.send &&
  18. process.versions &&
  19. process.versions.node)
  20. process.send({
  21. 'node_version': process.versions.node
  22. });
  23. // Require the real application
  24. if (process.env.pm_exec_path) {
  25. if (ProcessUtils.isESModule(process.env.pm_exec_path) === true) {
  26. import(url.pathToFileURL(process.env.pm_exec_path));
  27. }
  28. else
  29. require('module')._load(process.env.pm_exec_path, null, true);
  30. }
  31. else
  32. throw new Error('Could not _load() the script');
  33. // Change some values to make node think that the user's application
  34. // was started directly such as `node app.js`
  35. process.mainModule = process.mainModule || {};
  36. process.mainModule.loaded = false;
  37. require.main = process.mainModule;