Live data from Hacker News

Show HN: Servicer, pm2 alternative built on Rust and systemd

servicer.dev

1–10 of 41 posts

Show HN: Servicer, pm2 alternative built on Rust and systemd

#1
Servicer is a CLI to create and manage services on systemd. I have used pm2 in production and find it easy to use. However a lot of its functionality is specific to node.js, and I would prefer not to run my rust server as a fork of a node process. Systemd on the other hand has most of the things I need, but I found it cumbersome to use. There are a bunch of different commands and configurations- the .service file, systemctl to view status, journald to view logs which make systemd more complex to setup. I had to google for the a template and commands every time.

Servicer abstracts this setup behind an easy to use CLI, for instance you can use `ser create index.js --interpreter node --enable --start` to create a `.service` file, enable it on boot and start it. Servicer will also help if you wish to write your own custom `.service` files. Run `ser edit foo --editor vi` to create a service file in Vim. Servicer will provide a starting template so you don't need to google it. There are additional utilities like `ser which index.js` to view the path of the service and unit file.

``` Paths for index.js.ser.service: +--------------+-----------------------------------------------------------+ | name | path | +--------------+-----------------------------------------------------------+ | Service file | /etc/systemd/system/index.js.ser.service | +--------------+-----------------------------------------------------------+ | Unit file | /org/freedesktop/systemd1/unit/index_2ejs_2eser_2eservice | +--------------+-----------------------------------------------------------+ ```

Servicer is daemonless and does not run in the background. It simply sets up systemd and gets out of the way. There are no forked services, everything is natively set up on systemd. You don't need to worry about resource consumption or servicer going down which will cause your app to stop.

Do give it a spin and review the codebase. The code is open source and MIT licensed- https://github.com/servicer-labs/servicer

Show HN: Servicer, pm2 alternative built on Rust and systemd
servicer.dev

Re: Show HN: Servicer, pm2 alternative built on Rust and systemd

#3
> Systemd on the other hand has most of the things I need, but I found it cumbersome to use

Could you please expand on this? From what I understand, to use systemd to deploy a microservice is basically one file:

    # /etc/systemd/system/myservice.service
    
    [Unit]
    Description=My Microservice
    After=network.target
    
    [Service]
    ExecStart=/path/to/myservice
    Restart=always
    User=myuser
    Group=mygroup
    Environment=VARIABLE=value
    WorkingDirectory=/path/to/service/directory
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=myservice
    
    [Install]
    WantedBy=multi-user.target
Then, to "use" it:

    # reload systemd
    sudo systemctl daemon-reload
    # start service
    sudo systemctl start myservice
    # enable service at boot
    sudo systemctl enable myservice
    # check status
    sudo systemctl status myservice
    # check logs
    journalctl -u myservice
What more advanced stuff were you trying to do that you ran into that made systemd seem cumbersome?

Re: Show HN: Servicer, pm2 alternative built on Rust and systemd

#4
You might like systemd's run command, it's a hidden little gem that basically does what your tool does--it turns some CLI params into a transient service file: https://www.freedesktop.org/software/systemd/man/systemd-run...

I dunno if this was a more recent addition to systemd, but it's pretty slick in my limited use. I use it for exactly the scenarios you mention, like quickly spinning up some local user services during development. It can do stuff like setup a listening socket, timer (cron) or file watcher service all from the CLI too.

Re: Show HN: Servicer, pm2 alternative built on Rust and systemd

#7
When I picked up Deno, I couldn't use it with PM2 so I ended up learning systemd which turned out to be quite easy. I like however the added tooling and dev-ux this tool provides.

Reading your post here it seems there's more interpreters you support, however the landing page has no reference to it.

Re: Show HN: Servicer, pm2 alternative built on Rust and systemd

#8

> Systemd on the other hand has most of the things I need, but I found it cumbersome to use Could you please expand on this? From what I understand, to use systemd to deploy a microservice is basically one file: # /etc/systemd/system/myservice.service [Unit] Description=My Microservice After=network.target [Service] ExecStart=/path/to/myservice Restart=always User=myuser Group=mygroup Environment=VARIABLE=value Worki…

I built the tool simply to improve developer experience. Run `systemctl list-units` and the console is flooded with a wall of services, most of them are not mine. Run `ser status` and I only see the ones that I created. The activity state, CPU and memory usage is displayed so I don't need to run a separate command.

    hp@hp:~$ ser status
    +-----+-------------+----------+----------------+-------+--------+
    | pid | name        | active   | enable on boot | cpu % | memory |
    +-----+-------------+----------+----------------+-------+--------+
    | 0   | hello-world | inactive | false          | 0     | 0      |
    +-----+-------------+----------+----------------+-------+--------+
    | 0   | index.js    | inactive | false          | 0     | 0      |
    +-----+-------------+----------+----------------+-------+--------+
Another UX improvement is the template generation. I found myself googling it everytime. I f there is something more custom (etc sockets) I can use the `ser edit`, this will open nano with a pre-populated template that I can edit.

Finally why limit oneself to systemd? pm2 runs on Mac and windows, I aim to do the same. Same set of commands to create services everywhere, with details abstracted away (easier said than done, need to look into their APIs).

Re: Show HN: Servicer, pm2 alternative built on Rust and systemd

#9

When I picked up Deno, I couldn't use it with PM2 so I ended up learning systemd which turned out to be quite easy. I like however the added tooling and dev-ux this tool provides. Reading your post here it seems there's more interpreters you support, however the landing page has no reference to it.

Thanks for the heads up, I shall update the landing page. The tool tries to detect the interpreter (currently just node and python), but you can provide a custom one with `--interpreter deno`.

Re: Show HN: Servicer, pm2 alternative built on Rust and systemd

#10

You might like systemd's run command, it's a hidden little gem that basically does what your tool does--it turns some CLI params into a transient service file: https://www.freedesktop.org/software/systemd/man/systemd-run... I dunno if this was a more recent addition to systemd, but it's pretty slick in my limited use. I use it for exactly the scenarios you mention, like quickly spinning up some local user services du…

That's interesting! I wasn't aware of this command when I started working on servicer. Anyway, there are a couple of utilities like `ser status` and `ser which` which you might find useful.
Post reply on HN