Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@elife/pm2
Advanced tools
PM2 is a project that is stable, robust, and well designed. However, when running for Electron, it has two issues:
Hence I created this new "Process Manager". It can be used without Electron of course but will also work perfectly with Electron without any of the existing PM2 issues.
const pm2 = require('@tpp/pm2')
pm2.start({
script: 'path/to/script.py',
})
pm2
functions take an optional callback that is invoked when there are
errors.
pm2.start({
script: 'path/to/script.py',
}, (err, pid) => {
...
})
The start
callback can be invoked multiple times - for each error in
the process and when the process restarts. The callback also contains
the PID of the process when it starts. A callback without pid
or err
means it has terminated cleanly.
pm2.start({
script: 'path/to/script.py',
args: ['say','hello'],
})
pm2.start({
script: 'script.py',
cwd: '/path/to/folder',
})
Because pm2
understands Node modules we can simply point to the module
folder and it will pick up the correct starting point.
pm2.start({
cwd: '/path/to/npm/module/',
})
pm2.start({
cwd: '/path/to/npm/module/',
log: 'mylog.log',
})
In order to stop a process it needs to be given a name:
pm2.start({
name: 'my-process',
cwd: '/path/to/npm/module/',
})
pm2.stop('my-process')
stop
also takes an optional callback that will be called when
stopped/error.
pm2.stop('my-process', (err) => {
...
})
You can stop all running processes (named or un-named).
pm2.stopAll()
You can also restart a named process.
pm2.restart('my-process')
Note that restart
does not take a callback. It uses the same callback
you provided to start
.
You can set the environment of the running process:
pm2.start({
script: 'path/to/script.py',
env: ENVIRONMENT_OBJECT,
})
If you want to clean up your sub-processes or simply stop cleanly in a
sub-process you can use the onstopping
event handler:
const pm2 = require('@tpp/pm2')
pm2.onstopping(() => {
...
})
Of course this only works if you're sub-process is a NodeJS module.
By default pm2
will restart any crashed processes. To prevent
'spinning' it will restart each time with a delay:
If it has been running successfully for 30 minutes assume started ok.
This is all configurable using the restartAt
and restartOk
parameters. The default parameters for the behaviour given above is:
pm2.start({
cwd: '/path/to/npm/module/',
restartAt: [100, 500, 1*1000, 10*1000, 30*1000, 60*1000, 5*60*1000],
restartOk: 30 * 60 * 1000,
})
You can design any restart strategy you want using the above parameters.
You can turn the restarting behaviour off completely by setting
restartAt
to []
or [0]
.
In some cases the output of programs designed for the terminal can
contain ANSI Escape Codes.
To remove them specify stripANSI:true
as an option.
pm2.start({
cwd: '/path/to/npm/module/',
log: 'mylog.log',
stripANSI: true,
})
This is usually because you want a clean log file.
[ ] Add Support for more process types (besides just python and node)
FAQs
A PM2 Replacement that works with Electron
We found that @elife/pm2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.