MCPcopy
hub / github.com/foreversd/forever / getAllProcesses

Function getAllProcesses

lib/forever.js:113–160  ·  view source on GitHub ↗
(callback)

Source from the content-addressed store, hash-verified

111// Returns all data for processes managed by forever.
112//
113function getAllProcesses(callback) {
114 const sockPath = forever.config.get("sockPath");
115
116 function getProcess(name, next) {
117 let fullPath = path.join(sockPath, name);
118 const socket = new nssocket.NsSocket();
119
120 if (process.platform === 'win32') {
121 // it needs the prefix
122 fullPath = '\\\\.\\pipe\\' + fullPath;
123 }
124
125 socket.connect(fullPath, function (err) {
126 if (err) {
127 next(err);
128 }
129
130 socket.dataOnce(['data'], function (data) {
131 data.socket = fullPath;
132 next(null, data);
133 socket.end();
134 });
135
136 socket.send(['data']);
137 });
138
139 socket.on('error', function (err) {
140 if (err.code === 'ECONNREFUSED') {
141 fs.unlink(fullPath, function () {
142 next();
143 });
144 }
145 else {
146 next();
147 }
148 });
149 }
150
151 getSockets(sockPath, function (err, sockets) {
152 if (err || (sockets && sockets.length === 0)) {
153 return callback(err);
154 }
155
156 async.map(sockets, getProcess, function (err, processes) {
157 callback(err, processes.filter(Boolean));
158 });
159 });
160}
161
162//
163// ### function getAllPids ()

Callers 2

stopOrRestartFunction · 0.85
forever.jsFile · 0.85

Calls 1

getSocketsFunction · 0.85

Tested by

no test coverage detected