zachallaun
Hey friends, wanted to share a tiny shell script I’ve been using to start Livebook with easy access to either a running production server or a development server. This is based on the fly.io guide and offers nothing really new or novel beyond some small conveniences:
- Starts Livebook with a default data directory set.
- Sets the default runtime to be
Attached, configured for your development or production server, so that you can immediately get going in that environment without having to set anything up.
Pre-reqs for development server:
- For Livebook to connect, you need to start it with an sname and cookie:
$ iex --sname my-server --cookie my-server-cookie -S mix phx.server
Pre-reqs for production fly.io server:
- You’ll need to have set a static cookie.
- You need to have set up your fly.io Wireguard tunnel.
Script:
#!/bin/sh
# connect-live.sh
fly_app=my-fly-app
fly_cookie=$ERL_COOKIE
dev_app=my-server
dev_app_cookie=my-server-cookie
data_path=notebooks
home=notebooks
case "$1" in
"prod")
ip=$(fly ips private --app $fly_app | cut -f 3 | sed -n 2p)
node=$fly_app@$ip
ERL_AFLAGS="-proto_dist inet6_tcp" \
livebook server \
--name livebook@127.0.0.1 \
--default-runtime attached:$node:$fly_cookie \
--data-path $data_path \
--home $home
;;
*)
node=$dev_app@$(hostname)
livebook server \
--default-runtime attached:$node:$dev_cookie \
--data-path $data_path \
--home $home
;;
esac
Make sure to chmod +x connect-live.sh, then getting things going is as easy as:
$ ./connect-live.sh # start with development defaults
$ ./connect-live.sh prod # start with production defaults
As a final note: I do next to no shell scripting and the above may be total crap, but it took me a bit longer than I’d like to get this kind of thing set up in the first place and now it’s very convenient & easy, so I thought I’d share!
Trending in Guides/Tuts
# ~/src/livebook/.iex.exs
System.cmd("xdg-open", [ LivebookWeb.Endpoint.access_url() ] )
Because Livebook requires a unique passcode on ...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachallaun
Script updated for Livebook 0.8.1 using environment variables instead of flags:
linusdm
That’s a nice alternative to doing all that manual setup to connect to a remote fly app. I recently was thinking of something similar.
If you keep your secrets in a password manager like 1password, you could use their cli to inject the cookie too. You’d be prompted for a password, and nothing else. I like to keep all secrets related to one deployment in a secured note (there are probably better ways to do it though).
Just out of curiosity: what kind of things do you do when connected to a remote host?
zachallaun
Nice tip on the password manager! I personally use direnv, so project secrets are kept in an
.envrcthat’s gitignored.Some context first: my primary project is a site for our business of which I’m the sole developer, so I’m able to play some things a little more fast-and-loose than I might otherwise.
Two primary use-cases for me:
Debugging. When something’s reported, it’s really convenient to just be able to poke around and see what’s up, what state things are in, etc. instead of having to rely on what Zach of yesterday thought to log.
Performing one-off or infrequent tasks that I haven’t gotten around to making a UI for. Basically using Livebook as a bespoke admin interface. There are some things that are really easy in code, e.g. nested data structures, that are kind of a pain in the ass otherwise, e.g. nested forms. This lets me play around with new features that have a business-logic implementation but don’t yet have a nailed down UI.
Overall I’ve found it extremely productive and pretty indispensable as a solo dev! As mentioned, if I were working on a larger team and hadn’t written literally all of it myself, I’d exercise more caution on making sure that I don’t break something.
That said, I do have a scratch notebook that I use for all this that has this nice warning at the top:
linusdm
Those are the usages I had in mind too! It’s much nicer than a plain IEx session. And the notebook allows to set up some scenario’s that you can easily repeat.
That screenshot is great
good reminder of the responsibilities that come with this power…