jonas_h

jonas_h

Hey everyone.

I would like to send messages from an external script to a running Elixir app. The script should be short-lived and terminate immediately after forwarding the message. It could of course be written in Elixir too and they’ll run on the same server.

Thanks!

Showing Posts 1 to 8

speeddragon

speeddragon

I think you can do this in multiple ways. Define a port to receive messages or use the rpc to send messages directly in elixir.

/path/to/_build/prod/rel/my_app/bin/my_app rpc "Genserver.cast(...)"

Nicd

Nicd

Yep, I use something like this to update my blog when I have added a new post or modified an existing one:

sudo -u www-data /var/www/blog/bin/mebe rpc "GenServer.call(Mebe2.Engine.Worker, :refresh, 30_000)"

Mix releases include the “rpc” script builtin.

cenotaph

cenotaph

Really cool solution!

ps: Security Notes:

  • I hope your document root is not pointed at /var/www
  • You have directory listing and all the other nice stuff disabled with the default apache or another unix handler
  • For the future please create a specific user for your projects, applications, scripts and put them into respective directories and run from that location with that user

ie: blog

user: blog
homedir: /home/blog

$ > ps
... blog ...... /home/blog/bin/mebe ...... 
jonas_h

jonas_h OP

The rpc solutions looks easy, but that’s only for release? I’d like to run this in dev (maybe even test?) as well.

Nicd

Nicd

Hi and thanks for the concern. My document root is indeed not /var/www, and directory listing is not enabled. The blog could sure run with a different user, but there is nothing interesting on the server that the user could access, so I’m not too worried about it. But should leave a note to do it the next time I do something on the box.

But this is not at all related to the matter at hand.

To do this in development, you can start your application with a name (--name or --sname) and then use IEx’s --rpc-eval flag (and I think IEx also needs to be given a different name).

derek-zhou

derek-zhou

rpc is good; however fairly slow because it need to start up a separate erlang node just to talk to the existing running system. If you need to interact with the running system every second, you can make a simple server listening on a UNIX domain socket, that respond to a minimal text based API. This is fairly simple with gen_tcp. Another benefit (at least in my view) is you get to limit what you respond to. My client program is just a shell script that invokes socat.

axelson

axelson

Scenic Core Team
jonas_h

jonas_h OP

Excellent, looks like just what I wanted.

For reference, this is what I got working:

defmodule Notify do
  use GenServer

  def start_link(args) do
    GenServer.start_link(__MODULE__, args, name: __MODULE__)
  end

  @impl true
  def init(_opts) do
    BEAMNotify.start_link(
      path: "/tmp/notify_socket",
      dispatcher: &send(__MODULE__, {:notify, &1, &2})
    )
  end

  @impl true
  def handle_info({:notify, msg, _}, state) do
    IO.inspect(msg)
    {:noreply, state}
  end
end

And the script in priv:

#!/bin/sh

BEAM_NOTIFY=$(ls $(dirname $0)/../_build/dev/lib/beam_notify/priv/beam_notify)
$BEAM_NOTIFY -p /tmp/notify_socket -- $1

I’ll have to modify the beam_notify path in production, but other than that I’m good to go.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews