ibz / lightning-shell

The shell for your personal server
https://lightningshell.app
MIT License
24 stars 13 forks source link

How to schedule commands (e.g. cron) on Umbrel? #6

Closed decentropy closed 2 years ago

decentropy commented 2 years ago

is there a way to schedule these commands with Umbrel, or can they only be run manually via the web UI?

ibz commented 2 years ago

Good point! This seems like a pretty important feature.

For now, the only way to run cron jobs is by SSH-ing into Umbrel and scheduling them there, but that's not very nice.

I'll look into a way of scheduling cron jobs from within Lightning Shell.

decentropy commented 2 years ago

For now, the only way to run cron jobs is by SSH-ing into Umbrel and scheduling them there

This could work for now.. what would the command look like, to call lightning-shell command from the Umbrel OS?

ibz commented 2 years ago

Lightning Shell is a Docker container running on Umbrel.

  1. run docker ps to find the container ID
  2. run docker exec -it <container ID> <command> to execute a command inside the container
decentropy commented 2 years ago

Thanks... so docker exec works with charge-lnd, but getting an error with rebalance-lnd

OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "rebalance-lnd -c": executable file not found in $PATH: unknown

ibz commented 2 years ago

Ideally you execute the scripts in /home/lnshell/.local/bin and they will know what to do.

For example, use /home/lnshell/.local/bin/rebalance-lnd rather than straight rebalance-lnd. This script will know where to find the real one. More so, it will tell the real one how to connect to LND so you don't need to pass --grpc params and such.

decentropy commented 2 years ago

That worked, thanks!

decentropy commented 2 years ago

One related question... If I am cron scheduling charge-lnd, what's the best way to pass config file? Will a charge-lnd config saved inside lightning-shell get overwritten next version upgrade?

ibz commented 2 years ago

Good question. Stuff saved inside the /data directory of the Lightning Shell container should be preserved, according to Umbrel. I haven't personally tested this yet though, but an update will be out soon, so this would be a good time to try.

decentropy commented 2 years ago

Yep... I will just use docker cp /home/umbrel/charge.config <containerID>:/home/lnshell/charge.config to copy over my config if I change it. Then docker exec -it <containerID> /home/lnshell/.local/bin/charge-lnd -c /home/lnshell/charge.config works like a charm. (It seems you can't attach a volume with -v after the container is running)

Thanks for this app! It's great to not have to deal with installing/updating these utilities separately...

PS - It may be better to use <containerName> instead of <containerID> in cron... in case the ID changes upon update? Not sure about that, just a thought

ibz commented 2 years ago

Yes, the volume is attached when the container is started, but you can copy the file to the Umbrel side of the volume - /mnt/data/umbrel/app-data/lightning-shell/data/ - and it will show up inside the container, then you can just edit it from Umbrel and there is no need to copy it again, as the changes will be reflected in the container. But anyway, using docker cp also works.

Indeed, ideally you use containerName instead of containerID, but I don't think Umbrel gives a name to this container when it gets started, unfortunately. It would be nice though... What I meant though was to use docker ps and sed to get the container ID on every cron job run. That should be safe. Definitely do not hardcode the ID in cron!

Yes, the whole point of this app was to have all utilities installed at once. I spent lot of time installing them myself and I thought I could save others that time. Not to mention updates...

msimion commented 2 years ago

I have finally set the charge-lnd cron job in umbrel.

In case it helps anyone, I have documented the steps in the gist below:

https://gist.github.com/msimion/e756bbe95426a91d7a0aa9912c7d0619

ibz commented 2 years ago

Beautiful, thank you @msimion ! I'll try to make your gist into a man page to make it easier to read inside lightning-shell, but currently I have another project - making the Bitcoin whitepaper into a man page! I'll finish that first!

ibz commented 2 years ago

I added lsh_exec.sh in v0.1.8 (which will be out in the next Umbrel update).

This script will find the container ID and execute the Lightning Shell command from Umbrel's OS, so you don't need to worry about this anymore.

Documented the feature here: https://lightningshell.app/faq/#cron