Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Publicaciones sobre linux

KV: a remote KVM application

I had been read­ing about re­mote KVMs for a while. There are sev­er­al, like PiKVM, JetKVM, etc. I de­cid­ed I want­ed one to ac­cess my serv­er at home be­cause it has a nasty ten­den­cy to lose net­work con­nec­tiv­i­ty, and I want­ed to be able to fix it with­out hav­ing to go to the of­fice and plug in stuff in­to it.

This is not like run­ning RDP or VNC on the serv­er in that to the serv­er this is hard­ware. It works no mat­ter how crashed or dis­con­nect­ed the serv­er is, as long as it has pow­er. It is like hav­ing a mon­i­tor, key­board and mouse plugged in to the server, but re­mote­ly.

I had all the hard­ware I need­ed:

  • A Radxa Ze­ro, which has OTG sup­port so I could use it as a USB de­vice.
  • A USB cap­ture don­gle, which are cheap and easy to find, to cap­ture the HD­MI out­put of the serv­er.

But I just could not make it work. PiKVM, the most pop­u­lar one, makes it pret­ty dif­fi­cult to make it work on any­thing oth­er than the ex­act hard­ware con­figs they sup­port, and those are ex­act­ly the ones I don't have.

I could not find any im­ple­men­ta­tion that was easy to set­up and sup­port­ed the hard­ware I had, so I de­cid­ed to write my own.

You can get the code at GitHub of course. It com­piles to a sin­gle bi­na­ry. It on­ly re­quires you to have ffm­peg in­stalled, and it should just work as long as your hard­ware sup­ports OT­G, you have a USB cap­ture don­gle, and you plug all the ca­bles cor­rect­ly.

One USB ca­ble and one HD­MI ca­ble go from the serv­er to the Radxa Ze­ro (the HD­MI via cap­ture don­gle) and you run the one bi­na­ry built from this code on the Radxa Ze­ro. It will start a web serv­er on port 3000, and you can ac­cess it from any brows­er.

The web in­ter­face is very sim­ple, but it work­s. You can see the video feed, and you can send key­board and mouse events to the serv­er. You can even pro­vide a disk im­age that the serv­er will think is a USB drive. I sup­pose you can even in­stall the OS in the serv­er that way, but I have not tried it.

If you want to ac­cess it more re­mote­ly, just set­up a VPN in the KVM it­self.

Ideas for programs that don't exist: 3

This is an oc­ca­sion­al se­ries of posts where I will share ideas for pro­grams that don't ex­ist, but should. The goal is to in­spire de­vel­op­ers to cre­ate use­ful tools that can make our lives eas­i­er. Or, more like­ly, to re­mind me about these ideas so I can cre­ate them my­self. Or even more like­ly, to just get them out of my head so I can stop think­ing about them.

Idea 3: A program that does backups the way I want

I don't want to con­fig­ure things on many com­put­er­s. I want to con­fig­ure things once in one com­put­er and have back­ups for ev­ery­thing I care about, done prop­er­ly.

There is a great back­up pro­gram called restic that does back­ups RIGHT. It is fast, it is se­cure, it is easy to use, and it has a lot of fea­tures.

There is a frontend for it called backrest that does a lot of things right. It separates the concept of repo which is what you backup to and plan which is what and when you backup.

But I want more, I want to separate plan (when and how) from source (where the data is)

I want to work like this:

  1. Create a repo like "this folder here on this computer is a repo called 'foo' and it has a password and whatnot"
  2. Create a plan like "every day at 3 AM, backup to 'foo', keep 30 days of backups there, and every week at 2am on sundays, backup to 'bar' which is a remote repo and keep 10 weeks of backups there"
  3. Create a source like "the /home/ralsina folder in my notebook"
  4. Create a backup which is a combination of a source and a plan like "backup the /home/ralsina folder in my notebook to 'foo' every day at 3 AM"

Fur­ther, I want this to just work on all my com­put­ers as long as I have ssh cor­rect­ly con­fig­ured to al­low it.

My back­up con­troller should log in­to what­ev­er com­put­er the re­po is in and in­stall restic there. Then log in­to the source com­put­er anb in­stall restic there. Then cre­ate the re­po, and when the plan says it's time to back­up, it should log in­to the source com­put­er and run the back­up com­mand there, and then log in­to the re­po com­put­er and run some­thing there if it needs run­ning.

Then I want it to keep logs and no­ti­fy me via go­ti­fy or some­thing if some­thing goes wrong.

Is that too much to ask?

Ideas for programs that don't exist: 2

This is a new oc­ca­sion­al se­ries of posts where I will share ideas for pro­grams that don't ex­ist, but should. The goal is to in­spire de­vel­op­ers to cre­ate use­ful tools that can make our lives eas­i­er. Or, more like­ly, to re­mind me about these ideas so I can cre­ate them my­self. Or even more like­ly, to just get them out of my head so I can stop think­ing about them.

Idea 2: A nice web frontend for journald

I do some self host­ing. It's tempt­ing, when you self­-host, to run things as if it was a com­pa­ny's pro­duc­tion set­up. So, there are some who run mul­ti­ple large servers on ku­ber­netes and so on.

Not me, I run a sin­gle SBC with a bunch of dock­er­ized ser­vices.

So, how do I see logs if some­thing goes wrong?

Well, I log to the system's journal, so I can use journalctl to see the logs.

It's just this bit of YAML in your com­pos­er def­i­ni­tion:

  logging:
    driver: "journald"
    options:
      tag: "whatever"

That tags the logs from that con­tain­er with "what­ev­er". So, I can run:

journalctl -t whatever

This tool, journalctl is quite nice, and you can filter by date, grep for things, follow the live logs, and so on. But it's a command line tool, which I like.

But the ¨do it like a re­al prod thing"crowd us­es logstash or some­such, and have a web dash­board for this kind of things.

Well, I should have one of those too, but backed by journalctl

There is one that comes with sys­temd, but it's sort of crap­py, and there is no rea­son for it to be. It's run­ning in the same serv­er where the logs are, it's sim­ple, and it would be a nice lit­tle project to do.

Ideas for programs that don't exist: 1

This is a new oc­ca­sion­al se­ries of posts where I will share ideas for pro­grams that don't ex­ist, but should. The goal is to in­spire de­vel­op­ers to cre­ate use­ful tools that can make our lives eas­i­er. Or, more like­ly, to re­mind me about these ideas so I can cre­ate them my­self. Or even more like­ly, to just get them out of my head so I can stop think­ing about them.

Idea 1: A program that can automatically configure complex machine/monitor setups

My desk­top has mul­ti­ple ma­chines shar­ing mul­ti­ple mon­i­tors via one or more HD­MI switch­es. Those mon­i­tors are land­scape or por­trait, some are built in­to lap­tops and oth­ers are ex­ter­nal. Some are di­rect­ly con­nect­ed, some are not. A com­put­er may have be­tween ze­ro and three mon­i­tors con­nect­ed at any one time.

When they are con­nect­ed, in some cas­es, I want to run bar­ri­er to share the mouse and key­board, but with dif­fer­ent con­fig­u­ra­tions de­pend­ing on what mon­i­tors are con­nect­ed to what (say, is this com­put­er us­ing the mon­i­tor at the left of the one for the com­put­er with the key­board and mouse?).

So:

  • I want to be able to con­fig­ure the mon­i­tors and their ori­en­ta­tion­s, and the key­board­/­mouse shar­ing, for each ma­chine.
  • This should hap­pen au­to­mat­i­cal­ly when I con­nect a mon­i­tor or switch the HD­MI switch.
  • It should start/stop/re­con­fig­ure bar­ri­er on each ma­chine.

Of course this does­n't ex­ist and is pretttt­ty hard to do.

For de­tails on how my set­up works now: mon­i­tors and kb­d/­mouse

All Self-Hosted Faas Solutions Suck?

I have a few small projects where I need a serv­er as back­end. That means I need to run a server, which usu­al­ly means I need to do a lot of stuff. BUT these are as­ton­ish­ing­ly sim­ple back­end­s. Usu­al­ly just one end­point, which does one thing.

For ex­am­ple, con­sid­er nom­bres a web­site where you can ex­am­ine his­tor­i­cal in­for­ma­tion about names in Ar­genti­na. Like, how has the pop­u­lar­i­ty of the name "Juan" changed over time?

Like this:

The name Juan is the most popular male name in Argentina

That is lit­er­al­ly one func­tion that takes as ar­gu­ment names, does a cou­ple of queries to a database, builds a chart and re­turns that. De­ploy­ing that should not re­quire me set­ting up in­fra­struc­ture spe­cial­ly be­cause I have like 5 or 10 of those and they are ac­cessed 10 times a day or so.

If I were to use "the cloud" the so­lu­tion would be to use AWS Lamb­da, or the sim­i­lar clones in Azure or Google Cloud. But I don't want to pay for things, so I looked for a way to do that in my own server, which I al­ready have and has more than enough pow­er to han­dle it.

So, I did it! I used faasd which lead to a whole slew of prob­lems that you can see in this post.

Ba­si­cal­ly faasd hates shar­ing the ma­chine it's in with any­thing else, so I seg­re­gat­ed it to a VM us­ing Ig­nite. Now, I am con­sid­er­ing mov­ing to a new­er, more pow­er­ful serv­er (A Radxa Rock 5C) and I look at set­ting up Ig­nite and ... it's ob­so­lete.

It says the re­place­ment is Flint­lock­... which is "on hold", which means aban­doned.

So I try set­ting up a VM us­ing lib­virt, but since this is ar­m64, things are a bit com­pli­cat­ed, so I say, damn, let's just use QE­mu, which works ... as long as I don't use KVM, be­cause it makes the VM su­per flaky.

So I can choose a su­per flaky VM, or a very slow VM, or use ob­so­lete soft­ware, all be­cause I want to run a func­tion that takes a few sec­onds to run and is ac­cessed 10 times a day and faasd is needy.

So, I say­d, what the heck, faasd can't be the on­ly thing. Let's look again!

  • Open­Faas: by the same peo­ple as faas­d, needs ku­ber­netes, way overkill
  • Fx: looks good and sim­ple, lit­er­al­ly does­n't work.

You don't be­lieve me? Here is what hap­pens when I fol­low the in­struc­tions to run fx, on a nor­mal x86 ma­chine:

> curl -o- https://raw.githubusercontent.com/metrue/fx/master/scripts/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1471  100  1471    0     0   4138      0 --:--:-- --:--:-- --:--:--  4143
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  8635  100  8635    0     0  17948      0 --:--:-- --:--:-- --:--:-- 17914
Downloading fx from https://github.com/metrue/fx/releases/download/0.9.48-alpha.d91a7a0/fx_0.9.48-alpha.d91a7a0_Tux_64-
Download complete, saved to /home/ralsina/fx/fx.tar.gz
Installing fx to /home/ralsina/fx
fx
fx installed successfully at /home/ralsina/fx
fx version 0.9.48
Cleaning up /home/ralsina/fx/fx.tar.gz

> cat > func.js
module.exports = (ctx) => {
  ctx.body = 'hello world'
}

> ./fx up -p 8080 func.js
2024/06/28 10:52:54  info provisioning localhost ...
*****************
exit status 125
*****************

I spent an hour or so on it, it just does­n't work.

What else is out there?

  • Apache Open­Whisk looks promis­ing, I will try it out nex­t, need to see if it works in my re­source-lim­it­ed serv­er.

If it does­n't work out I swear I am rolling my own.

UP­DATE: Looks like I am rolling my own:

it needs kafka and couchdb?


Contents © 2000-2025 Roberto Alsina