jonas_h

jonas_h

Sending messages from an external script to a running Elixir app

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!

Marked As Solved

axelson

axelson

Scenic Core Team

Also Liked

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.

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(...)"

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 ...... 
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.

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New

We're in Beta

About us Mission Statement