bitwalker / distillery

Simplify deployments in Elixir with OTP releases!
MIT License
2.96k stars 397 forks source link

Hot upgraded app still using old code in custom distillery commands #602

Closed dmarkow closed 5 years ago

dmarkow commented 5 years ago

Steps to reproduce

Description of issue

Given a custom command:

defmodule Api.ReleaseTasks do
  def foo(_argv) do
    IO.puts Application.spec(:api, :vsn)
  end
end

# rel/config.exs:
# ...
set commands: [
        foo: "rel/commands/foo.sh"
      ]
# ...

Before any updates (version 0.1.0)

> bin/api foo
"0.1.0"

> bin/api remote_console
Erlang/OTP 21 [erts-10.0.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Interactive Elixir (1.7.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(api@127.0.0.1)1> Api.ReleaseTasks.foo []
"0.1.0"

Now I increment my version from 0.1.0 to 0.1.1 and run a distillery upgrade, but the custom command still outputs "0.1.0" from the first release:

> bin/api upgrade 0.1.1
...
Made release api:0.1.1 permanent

> bin/api foo
"0.1.0" (this should say 0.1.1?)

> bin/api remote_console
Erlang/OTP 21 [erts-10.0.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Interactive Elixir (1.7.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(api@127.0.0.1)1> Api.ReleaseTasks.foo []
"0.1.1"

So while running remote_console properly uses the new release code, the custom commands still use the old code. Restarting the running app doesn't help, the only way to get the new custom command code to execute is doing a full (not upgrade) release.

Distillery: 2.0.12, Erlang 1.7.4, Erlang 21.1.4

bitwalker commented 5 years ago

Could you paste the contents of foo.sh? I'd like to see how you are invoking the command so I can reproduce exactly

dmarkow commented 5 years ago

foo.sh contents:

#!/bin/sh

release_ctl eval --mfa "Api.ReleaseTasks.foo/1" --argv -- "$@"

I used https://hexdocs.pm/distillery/guides/running_migrations.html as a reference for this (ultimately I'm trying to run migrations, but even my test IO.puts line is outputting the wrong version)

ecly commented 5 years ago

While I cannot confirm that it is used old code for the ReleaseTask, I can confirm that it is using the wrong version in the executable scripts, meaning that it is looking in the old version's release folder for the migrations.

bitwalker commented 5 years ago

This is verified, and addressed in master, the fix has been ported to the 2.0.x branch as well

nanlong commented 4 years ago

I have same question. distillery version: 2.1.1