How can I run a `mix run priv/foo.exs` without starting Cowboy and other genservers?

Hi,

subject says everything: how can I do a mix run without starting the webserver and a selection of other gen servers? Background: I have a maintenance.exs I want to run every night, but currently it crashes on startup because it tries to an interface already in use.

Best regards,
CK

Hey :slight_smile:

From mix help run:

--no-start - does not start applications after compilation

…so in your case:

mix run --no-start priv/maintenance.exs

Regards,
Johan

2 Likes

Hey!

oh, I missed that. Thanks!

Best regards,
CK

OK, follow-up question: how do I start Ecto when running a script with --no-start? :wink:

Like this:

repos = parse_repo([])
Enum.each(repos, fn repo ->
  ensure_repo(repo, [])
  {:ok, _pid, _apps} = ensure_started(repo, [])
end)