Code Monkey home page Code Monkey logo

pup's Introduction

Pup - Universal Process Manager

PUP

Pup is a powerful universal process manager developed with Deno, designed to keep your applications and services alive.

For detailed documentation, visit pup.56k.guru.

Key Features

  • Cross-platform and wide OS compatibility: Manage processes across different platforms and languages, including Deno, Node.js, Python, and Ruby, on Windows, macOS, and Linux.
  • Process management: Define, control, and manage your processes with simple commands and configuration options.
  • Multiple start/restart policies: Set up processes to start automatically, on a schedule (using cron expressions), or when files change.
  • Service management: Built-in installer for Linux (sysvinit, systemd, upstart), macOS, and Windows services.
  • Clustering and load balancing: Seamlessly scale your applications with built-in clustering and load balancing capabilities.
  • Plugins: Extend Pup's functionality with custom plugins, such as the Splunk HEC plugin for seamless integration with Splunk and the Web Interface plugin for an intuitive graphical user interface. Create your own plugins to add additional features and integrations tailored to your needs.
  • Process Telemetry and IPC: Gain deeper insights into managed processes by gathering telemetry data, such as memory usage and current working directory, from Deno client processes. Supports inter-process communication for connected processes to interact with each other.
  • Secure Rest API: Control and monitor Pup from third party solutions using the build in Rest API.

Note: Programmatic usage, process telemetry, and IPC are currently available only when running Deno client processes.

Quick Start

Installation

To install Pup, open your terminal and execute the following command:

deno run -Ar jsr:@pup/[email protected] setup --channel prerelease

This command downloads the latest version of Pup and installs it on your system. The --channel prerelease option is included as there is no stable version of Pup yet. Read more abour release channels here.

Configuration

Pup revolves around instance (ecosystem) configuration files, each process belongs to an instance defined by a pup.json. This file can either be created manually, or by the command line helpers.

  1. To create a simple instances running a single process:

    pup init --id "my-server" --autostart --cmd "deno run -A server.ts"

    If you intend to create multiple pup instances on the same server, you can pass an instance name through --name my-instance-name

  2. (Optional) In case you have an additional task to execute, such as a cleanup script, you can make use of pup append. The following example shows how to add an extra task that use the cron start policy:

    pup append --id "my-task" --cmd "deno run -A task.ts" --cron "0 0 * * * *"

  3. (Optional) Test your instance (exit by pressing CTRL+C):

    pup run

  4. To make your instance run at boot, enable it using pup enable-service.

    pup enable-service

    Will by default use the instance name for service name, which defaults to pup. You can override by passing -n my-custom-name.

For the full manual, see https://pup.56k.guru

Single command example

It is also possible to use pup to keep a process alive temporary, without a pup.json or system service.

To achieve this, use pup run with --cmd and a start policy.

pup run --autostart --cmd "deno run server.ts"

Example setups

Full examples available at /docs/src/examples

Release channels

  • stable: This channel is currently empty, but will provide stable releases of Pup in the future. It is recommended for production environments where stability is a priority.

  • prerelease: This channel offers pre-release versions of Pup that include new features and improvements. It is suitable for users who want to test the latest enhancements before they are officially released.

  • canary: The canary channel provides the most up-to-date and cutting-edge versions of Pup. It includes the latest changes and may not be as stable as the other channels. It is primarily intended for developers and early adopters who want to stay on the bleeding edge of Pup's development. Based on the current state of the main repo of the github repository.

Note Built-in plugins, such as splunk-hec and webinterace does not work with canary versions right now.

Each channel serves different purposes, so choose the one that best fits your needs and requirements.

Contributions and Development

Contributions to Pup are very welcome! Please read the contributing section of the manual, fork the repository, make your changes, and submit a pull request.

We appreciate all feedback and contributions that help make Pup better!

Examples of areas that need extra attention right now

  • Plugin development: Invent new plugins for Pup, or help out by improving the existing (work in progress) web-interface plugin. See https://pup.56k.guru/examples/plugins/README.html to get started on plugin development in general. See https://github.com/Hexagon/pup/blob/main/plugins/web-interface/README.md for instructions on how to rebuild the web-interface.
  • Testing: Pup needs to be thoroughly tested; help out by using and testing it in various scenarios. Report any issues you encounter.
  • Reading: Review the documentation and report any issues or areas for improvement.
  • Bugfixes: Find bugs, report them, and optionally create a PR to fix the issue.
  • Spread the word: If you find Pup useful, spread the word to attract more users, developers, and testers to the community. Sharing your experience and showcasing Pup's capabilities can help grow and strengthen the project.

pup's People

Contributors

gauben avatar hexagon avatar leokuma avatar mattbretl avatar naltun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pup's Issues

Type error

lib/core/pup.ts
Error lines, 55, 59 - Property 'name' does not exist on type 'ProcessConfiguration'.deno-ts(2339)

Watcher doesn't stop on Mac

When I configure pup to run with the watcher config using ctrl + c stops the processes but not the watcher.

Here is my console when I run pup run

2023-10-21T11:39:13.737Z [LOG] [core:processes] Process 'api' loaded
2023-10-21T11:39:13.740Z [LOG] [api:starting] Process starting, reason: autostart
2023-10-21T11:39:14.916Z [LOG] [api:stdout] The manifest has been generated for 5 routes and 1 islands.
2023-10-21T11:39:14.930Z [LOG] [api:stdout] 
2023-10-21T11:39:14.930Z [LOG] [api:stdout] 
2023-10-21T11:39:14.930Z [LOG] [api:stdout]     Local: http://localhost:8000/
2023-10-21T11:39:14.930Z [LOG] [api:stdout]  ๐Ÿ‹ Fresh ready 

This is when I press ctrl + c

2023-10-21T11:39:20.641Z [LOG] [core:terminate] Termination requested
2023-10-21T11:39:20.649Z [LOG] [cron:block] Process blocked, reason: terminating
2023-10-21T11:39:20.644Z [LOG] [cron:errored] Process exited with error: Error: Exited with code: 130
2023-10-21T11:39:20.653Z [LOG] [api:errored] Process exited with error: Error: Aborted with exit code: 130
2023-10-21T11:39:20.651Z [LOG] [api:stop] Process stopped, reason: terminating
2023-10-21T11:39:20.650Z [LOG] [api:stopping] Stopping process, reason: terminating
2023-10-21T11:39:20.649Z [LOG] [api:block] Process blocked, reason: terminating
2023-10-21T11:39:20.651Z [INFO] [core:cleanup] /Users/xxx/xxx/xxx/api/.pup.json-tmp removed.

At this point the terminal is still engaged. When I edit one of the watched files I see this:

2023-10-21T11:40:05.166Z [LOG] [cron:watcher] File change detected

Would love to have some help. Let me know if I can share any more information

Documentation: Example for Docker

There should be an example describing how to use pup to run a scheduled task in the official deno docker image

There should also be an example showing a kept-alive server with some croned worker processes doing stuff in separata processes

Feedback/ideas/thoughts

Awesome project! Thanks for your work on this. I'm in the process of attempting to switch from pm2 to pup, and I thought it might be useful to share some thoughts given that it looks like you're heading toward v1.0. Please take each of these suggestions with a grain of salt. And I'll pre-apologise here for any suggestions/thoughts that have stemmed from misunderstandings in the way Pup works.

Confusion around pup run vs pup start and pup terminate vs pup stop - and "apps" vs "ecosystems" vs "processes"

Intuitively, here's how I think pup should work:

  1. Install pup
  2. Enable it on startup with sudo pup startup enable or something
  3. Create a pup.json file in your app/server directory
  4. Run pup start in the same directory to start app (and causes pup to track that config file - e.g. for startup stuff)
  5. To stop, run pup stop in that directory (or run pup stop the-app-id), and it stops all the processes for that app/ecosystem (and untracks config file)

Controlling individual processes within an app is something that should be possible, but (at least in my experience) is not as common, so it should not use up the precious/intuitive start and stop commands. By far the most common commands I use with pm2 are start/stop/restart/logs, and they all apply to apps, not processes within an app.

I think this is the most important change that should be made for v1.0. If the current CLI design decisions were made to support more complex use cases that I'm not considering here, then I think "simple things should be simple, complex things should be possible" might be worth applying here. Need to avoid making simple things unsimple in order to make complex things simple-ish. Instead, move the burden to people doing complex things, because there are far fewer of them, and they (basically by definition) have the time + skill to go a little deeper in the config docs, or whatever.

The other huge advantage of this is that I think 90% of people will be migrating here from pm2, and IIUC this is basically how pm2 does it: https://pm2.keymetrics.io/docs/usage/application-declaration/ It's much easier to adopt new software if things work just like you expect - both intuitively, and from experience with related, popular software. Diverging from that is a cost that would need to give significant returns to be justified (Deno team realized this recently with deno install, for example). It's probably only worth diverging from pm2 in aspects where it's kinda confusing/bad.

Also perhaps worth mentioning: With the current CLI commands, I'm not actually sure how I'm supposed to use pup run, since it runs in the foreground instead of starting all the app's processes in the background like I expected. Also, when I try exiting with Ctrl+C, sometimes it hangs:

joe@test:~/app$ pup run
2024-04-11T07:15:50.617Z [LOG] [core:processes] Process 'app' loaded
2024-04-11T07:15:50.617Z [LOG] [app:starting] Process starting, reason: autostart
2024-04-11T07:15:50.651Z [LOG] [app:stdout] Listening on http://localhost:80/
2024-04-11T07:15:50.656Z [LOG] [app:stdout] HTTP server running. Access it at: http://localhost:80/
^C2024-04-11T07:16:00.685Z [LOG] [core:terminate] Termination requested
2024-04-11T07:16:00.689Z [LOG] [app:block] Process blocked, reason: terminating
2024-04-11T07:16:00.690Z [INFO] [core:cleanup] /home/joe/app/.pup.jsonc-tmp removed.
2024-04-11T07:16:00.687Z [LOG] [app:errored] Process exited with error: Error: Exited with code: 130
^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C

and I need to close the terminal to actually stop it. Other times it exits fine. But in both cases the pup status tells me No running instance found..

Where is Pup's "ground truth" for config?

IIUC, the pm2 save command snapshots the configs and uses that saved snapshot to e.g. determine whether an app should start on machine startup. I'm wondering how pup handles this? The pm2 save command was always a little bit confusing/annoying to me. Ideally, in my mind, pup would use the actual config files in the app directories as ground truth. So pup start would just add that config file's path to pup's internal "known config files" list, which it uses at machine startup to fetch the actual config file contents, and determine whether the app should be started. And I think pup stop should remove the config file from pup's internal "known config files" list.

There are tradeoffs here, but I think I would prefer if pup held as little "internal state" as possible - so I can just e.g. edit the config file and run pup restart in the same directory, and I know that I'm editing the actual "ground truth" that Pup is using.

I think there's a temptation here to, for example, not bundle pup's untracking of a config file with stop-ing the app because that's not always what would be desirable - but I'd appeal to the "simple things should be simple" principle again here - it's easy to add some extra (more "granular") commands like pup track and pup untrack, or whatever, which can be used in cases where devs are heading off the beaten path.

Document a few of the most common/useful commands in readme

E.g. pup status, pup logs - a quick dot-point list of these in the readme as part of the "quick start" would have been handy for me to quickly get the rough idea. And maybe add a final dot point linking them to e.g. https://github.com/Hexagon/pup/blob/main/docs/src/usage/index.md for the rest of the commands.

Document configuration defaults

This page: https://pup.56k.guru/usage/configuration/#general should have the defaults for all options documented. This one is pretty important I think. It'd also be worth mentioning a few of the most important defaults in the readme I think.

Related: I love opinionated defaults that make it easy for people to get started, but I'm a little bit weary of "overly specific" defaults like watcher.exts = ["ts", "tsx", "js", "jsx", "json"] which might not be very future proof. E.g. could probably add yaml, json5, etc. to that - there's a long tail. It might be best to just watch all extensions by default, but I'm not confident what the best approach is here. Current defaults are not unreasonable, but worth thinking about in terms of forward compatibility and future breaking changes.

pup logs should stream by default

I use pm2 logs <all|app-id> on a daily basis - it's very handy to have logs streaming in my console as I'm coding, so I can e.g. see errors during startup after saving the file, or see live logs on a production server.

Can console.warn be made orange in logs?

I've wished for a long time that pm2 did this. It sounds like a small thing, but I really appreciate that Chrome's devtools does this when I'm remotely inspecting a Deno/Node process. I just wish it were possible for terminal logs to make a visual distinction between warnings and errors. That said, I'm guessing it might not be possible due to console.warn maybe just being a stderr log without any distinction from console.error at the level at which pup "sees" those logs.

A log file with errors and normal logs interspersed

Another annoying thing with pm2 is that (AFAIK) I'm not able to see a log file that has errors and logs interspersed. The reason this is annoying is because the logs that came before an error are often quite relevant to the cause of the error. So, while debugging, I end up needing to switch back and forth between them and rely on timestamps for aligning them.

Switch from JSONC to JSON5, or support both

I hadn't heard of JSONC before - maybe I'm just out of the loop on that. I have used JSON5 before though, and seems to be more commonly used?

JSON5 is nice because you don't need quotes around keys like with JS POJO declarations - makes config files really clean.

Move .pup.jsonc-tmp, .pup.jsonc-data, etc. into .pup

This reduces clutter - especially if more pup-related files are needed in the app directory in the future.

Densify pup status, add colors for skimming, and num restarts + uptime

For pup status, "number of restarts" and "uptime" would be handy, and pm2-style density with skimmable (green=good) would be awesome:

image

Rather than having a separator between rows, I mean. I also think pm2 status could be made a lot more dense - e.g. by using emojis (which work fine in terminal, of course) for boolean/enum fields like status, watch, etc. The denser the better imo.

Also, I think pm2's "cpu" column is kind of useless since IIUC it's the CPU usage at that exact instant - it'd be much more useful for me to see average or total CPU usage over the last 30 minutes, or something.


Please don't feel the need to reply to all/any of the above points. I just hope that these thoughts have been at least somewhat useful. Thanks again for all your work on this!

pup upgrade --channel canary does not work

After the migration to jsr.io (with dependencies moved from deps.ts into deno.json), installing the canary version of pup doesn't work:

โžœ  ~ pup upgrade --channel canary

Warning: Installing using Deno flag --unstable due to version requirements.

Running: deno install -qfr -A --unstable-kv -n pup https://raw.githubusercontent.com/Hexagon/pup/main/pup.ts
error: Relative import path "@cross/utils" not prefixed with / or ./ or ../
    at https://raw.githubusercontent.com/Hexagon/pup/main/lib/cli/main.ts:32:30

imports from deno.json doesn't seem to be handled when installing over https. -c does not seem to work over https either.

Processes never finish using 1.0.0-rc.8

Processes is marked as running even after exiting, seems to be regardless of version

A workaround is to explicitly run Deno.exit(0) in the scheduled processes.

Fails to autostart on reboot on Debian

It's very unstable. I also have the problem that the service will not properly activate on reboot. systemd --user also hangs, something is off.

{
  "processes": [
    {
      "id": "cronmon",
      "cmd": "deno run --ext=ts --unstable --allow-read --allow-net --import-map=deno.json --lock=lock.json cronmon.ts",
      "autostart": true
    }
  ]
}

is my pup.json. pup status says nothing is running. systemd --user hangs, so I can only <C-c>. After installing the service things worked only partially, the service was active, but Deno wasn't really running, sounds like the issue #21, but this is Debian. I uninstalled the service and re-installed carefully. Then systemctl --user daemon-reload even reported Failed to connect to bus: No such file or directory.

What seems to work though is uninstalling the service before reboot and re-installing the service after reboot.

Feature: Environment variable filter

It should be possible to filter away system environment variables. Could possibly be done by explicitly appending filtered variables with value undefined to the env-option passed to Deno.run

Feature: Interface for plugins

It should be possible to write plugins that can control every aspect of pup. Plugins should be included with one script url, and one object containing plugin configuration.

Configuration example
{ ..., plugins: [ { url: "deno.land.x...", config: { ... } ], ... }

Thoughts on this?

Restart on crash?

I am trying to understand better how crash works. If my service crashes owing to an uncaught error is there a way to restart it? I simulated this scenario using

throw new Error("test error");

And setting restart to "always" but it only restarts on file changes.

Any tips? Thanks!

Documentation: Logotype

Pup should have a nice logotype, maybe a Denosaur pup, or something high tech related to processes "Process UP" (?)

Ideas?

Allow $schema in pup.json

Hey! I just discovered pup and it's really promising.

I'd like pup to accept "$schema" in pup.json for it to work out of the box, without needing a custom editor config.

{
  "$schema": "https://deno.land/x/pup/docs/pup.schema.json",
  "processes": [
    // ...
  ]
}

Command not found error

Hello,

I've installed Pup on a Ubuntu instance, but I get the following error:

root@webapp:~# deno install -Afr https://deno.land/x/pup/pup.ts
Warning Implicitly using latest version (1.0.0-beta.26) for https://deno.land/x/pup/pup.ts
โœ… Successfully installed pup
/root/.deno/bin/pup
โ„น๏ธ  Add /root/.deno/bin to PATH
    export PATH="/root/.deno/bin:$PATH"
root@webapp:~# pup
Command 'pup' not found, but there are 16 similar ones.

I get this after restarting the terminal.

I'm using Ubuntu:

Release:        22.10
Codename:       kinetic

Feature: Allow basic configuration of more features by cli

It should be possible to configure basic features of clusters and logging by using command line flags, when using init or append, should also be used when using run without a configuration file.

Remember to update documentation, and --help

Feature: Web interface plugin: Show log history

Right now only new logs are shown (by being added live) in the global/per-process log history area.

A number of historic rows should be pulled each time a process (or global view) is selected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.