MCPcopy
hub / github.com/Unitech/pm2 / _startJson

Method _startJson

lib/API.js:898–1177  ·  view source on GitHub ↗

* Method to start/restart/reload processes from a JSON file * It will start app not started * Can receive only option to skip applications * * @private

(file, opts, action, pipe, cb)

Source from the content-addressed store, hash-verified

896 * @private
897 */
898 _startJson (file, opts, action, pipe, cb) {
899 var config = {};
900 var appConf = {};
901 var staticConf = [];
902 var deployConf = {};
903 var apps_info = [];
904 var that = this;
905
906 /**
907 * Get File configuration
908 */
909 if (typeof(cb) === 'undefined' && typeof(pipe) === 'function') {
910 cb = pipe;
911 }
912 if (typeof(file) === 'object') {
913 config = file;
914 } else if (pipe === 'pipe') {
915 config = Common.parseConfig(file, 'pipe');
916 } else {
917 var data = null;
918
919 var isAbsolute = path.isAbsolute(file)
920 var file_path = isAbsolute ? file : path.join(that.cwd, file);
921
922 debug('Resolved filepath %s', file_path);
923
924 try {
925 data = fs.readFileSync(file_path);
926 } catch(e) {
927 Common.printError(conf.PREFIX_MSG_ERR + 'File ' + file +' not found');
928 return cb ? cb(Common.retErr(e)) : that.exitCli(conf.ERROR_EXIT);
929 }
930
931 try {
932 config = Common.parseConfig(data, file);
933 } catch(e) {
934 Common.printError(conf.PREFIX_MSG_ERR + 'File ' + file + ' malformated');
935 console.error(e);
936 return cb ? cb(Common.retErr(e)) : that.exitCli(conf.ERROR_EXIT);
937 }
938 }
939
940 /**
941 * Alias some optional fields
942 */
943 if (config.deploy)
944 deployConf = config.deploy;
945 if (config.static)
946 staticConf = config.static;
947 if (config.apps)
948 appConf = config.apps;
949 else if (config.pm2)
950 appConf = config.pm2;
951 else
952 appConf = config;
953 if (!Array.isArray(appConf))
954 appConf = [appConf];
955

Callers 6

startMethod · 0.80
reloadMethod · 0.80
restartMethod · 0.80
CLI.jsFile · 0.80
programmatic.jsFile · 0.80
API.jsFile · 0.80

Calls 9

cbFunction · 0.85
startAppsFunction · 0.85
exitCliMethod · 0.80
resolveMethod · 0.80
indexOfMethod · 0.80
_operateMethod · 0.80
speedListMethod · 0.80
nextFunction · 0.70
isAbsoluteMethod · 0.45

Tested by

no test coverage detected