Simple process manager; alternative to pm2
yarn add magicbin
- Create a
magicbin.config.js
file. Take example on the demo one. - After each change, run
yarn mb sync
to apply the new configuration. - If you wish to access the logs, run
yarn mb open
. - To stop the local namespace, run
yarn mb stop
. - To fully stop the daemon itself, run
yarn mb daemon stop
.
For magicbin development or debug purposes, you can spawn its daemon as a regular process by running the following in a tab:
DEBUG='mb:*' CLIPANION_DAEMON=1 yarn mb
You'll then be able to run any command as usual from other terminals, which will execute inside the daemon you've spawned.
You can force a process to only start once another has started (and has been confirmed, if relevant, cf next section). To do that, just add a dependsOn
field to your task definition.
Magicbin supports a non-standard protocol that lets processes notify the daemon that they have properly been setup. This is a good match for many kind of servers, which need to asynchronously go through various steps before being truly initialized.
To leverage that, the easiest way is to use the Magicbin Node API:
import {confirmProcess} from 'magicbin';
const server = http.createServer((req, res) => {
res.end();
});
setTimeout(() => {
server.listen(4500, () => {
console.log(`Started to listen`);
confirmProcess();
});
}, 5000);
Copyright © 2021 Mael Nison
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.