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

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
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
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement