Show HN: Servicer, pm2 alternative built on Rust and systemd (servicer.dev)
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
40 comments
[ 2.5 ms ] story [ 90.9 ms ] threadCould you please expand on this? From what I understand, to use systemd to deploy a microservice is basically one file:
Then, to "use" it: What more advanced stuff were you trying to do that you ran into that made systemd seem cumbersome?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).
https://github.com/crazy-canux/awesome-monitoring
Check out Netadata + Nagios
https://news.ycombinator.com/item?id=36944388
Check out this as well
* systemctl status 'brand-*' That is, custom services could start with the same prefix.
I run a lot of custom services, and usually I want to check on one specifically, or if I want to look at the total service health, I also want to include the services which are "not mine".
Plus, sometimes there is no place to put them that isn't conflicting with the package manager, so "best practice" ends up being to make your own package containing the unit file, and ...
I'm not a big fan of "best practices" in general, but it'll turn into a whole rabbithole if you let it. At least with a piece of software like this, you just run a few commands and it remembers, and you get tons of sane defaults.
In practice I don't think it is a huge issue. I've just left unit files laying around on embedded devices without issue. Hard to find which ones are mine though, if I've lost my mental list of them.
(Also, writing one from scratch without a template is annoying, since I haven't memorized the format.)
https://www.freedesktop.org/software/systemd/man/systemd.uni...
The same doc also describes a "drop-in" file format, where you can override just the details you want from a system file.
I like systemd but I can see a lot of value in friendlier tools like this. What I really want is a TUI tool like Lazydocker for managing systemd services.
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.
https://github.com/servicer-labs/servicer/blob/762801e3c07b1...
There is still a benefit to requiring root to create the service file though: If the service is compromised when it's running as `User=`, it can't modify the systemd service file itself, which is owned by root.
But I suppose there isn't away to run these transient services as boot because they are definition gone after they have stopped?
Generally results of -run services can be captured through journalctl, so it's possible to run systemctl show on them and get the config.
You can abuse the fact that systemctl has the edit subcommand. It meant to modify the existing service file, but nothing means you can't just save it out elsewhere and then modify it.
Additionally, if it's a long running service it should be located where other systemd unit files are located (`$HOME/.config/systemd/user/` for user units, `/etc/systemd/system/` for service units) and just copy them while the unit is still running.
Of course this requires it to live long enough.I'm happy see this question "Why not use systemd" finally being asked. Apparently the people on NPM (2 million weekly downloads for pm2) ~~disagree~~ don't care. `pm2 start` just works, not everybody is a system admin. There are a bunch of threads around asking for a pm2 for Rust or golang. This tool tries to address this segment.
You can be a linux veteran still benefit with some commands like `ser status` which will only show the services you created, not the wall of text shown by `systemctl list-units`. CPU and Ram usage is thrown in as a bonus so you don't need to run a separate command. It's a neat trick that uses no database. The services end with `.ser.service`, this way we only see the units that servicer created. Run `ser which` and you'll get the unit and service file destination.
No commands work as you'd expect them to, and require a lot of very specific cmd line flags to do what should be the default.
I think the architecture and design of systemd might be okay but the user experience is horrible.
It's the same with git.
Reading your post here it seems there's more interpreters you support, however the landing page has no reference to it.
I think Servicer can be a good starting point for people to learn how to use Systemd services and systemd-run. Systemd is huge and can be scary to learn, so providing a set of steps to get a service running is very instructive.
But then, Servicer requires super user priviliges to modify the system, instead of running everything as the non-privileged user, via `--user` flag for systemctl or via systemd-run...
There are few commands to learn the basics when setting up a new system wide service: systemctl and journalctl. Some examples: - systemctl daemon-reload: reload all unit files - systemctl start/stop/status/restart <service>: quite intuitive, don't you think? - journalctl -u <service>: to see all logs from that service. I like to also use `-f` flag to follow new log entries. - man systemctl: the manual for systemctl - man journalctl: the manual for journalctl
Writing new service units is the "hard" part, but there are plenty of "templates" on the net, or you can browse `/usr/lib/systemd/system/` for examples.
But don't let the critics here demotivate you. You made a tool, you published it, congrats!
It uses the systemd daemon to manage the services. It's not clear what an additional service would do.
So while my first reaction was "why not use systemd?", my second reaction is "Oh yeah, I built something like that and it was helpful".
Systemd is great, but it does have a massive amount of a commands and documentation and be overkill and overwhelming.
I don't have a solution for managing services though and that has been the one pain point after moving away from containerized dev envs. The cross platform network and service management you get with docker is pretty ideal. devenv.sh is on to something with their 'services' feature but it doesn't quiet fit the bill for us yet.
[1]: https://flake.parts/options/devshell.html