check_missing_reboot_apps.exs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env elixir
  2. {parsed, _argv, _errors = []} =
  3. OptionParser.parse(
  4. System.argv(),
  5. strict: [profile: :string]
  6. )
  7. profile = Keyword.fetch!(parsed, :profile)
  8. :xref.start(:xref)
  9. :xref.set_default(:xref, warnings: false)
  10. rel_dir = '_build/#{profile}/lib/'
  11. :xref.add_release(:xref, rel_dir)
  12. {:ok, calls} = :xref.q(:xref, '(App) (XC || "mria":"create_table"/".*")')
  13. emqx_calls =
  14. calls
  15. |> Enum.map(&elem(&1, 0))
  16. |> Enum.filter(&(to_string(&1) =~ "emqx_"))
  17. |> MapSet.new()
  18. Path.wildcard(rel_dir ++ "*/ebin")
  19. |> Enum.each(fn dir ->
  20. dir
  21. |> to_charlist()
  22. |> :code.add_pathz()
  23. end)
  24. Path.wildcard(rel_dir ++ "*")
  25. |> Enum.map(fn dir ->
  26. dir
  27. |> Path.basename()
  28. |> String.to_atom()
  29. |> Application.load()
  30. end)
  31. reboot_apps = :emqx_machine_boot.sorted_reboot_apps() |> MapSet.new()
  32. missing_reboot_apps = MapSet.difference(emqx_calls, reboot_apps)
  33. if MapSet.size(missing_reboot_apps) != 0 do
  34. IO.puts(
  35. :stderr,
  36. IO.ANSI.format([
  37. :red,
  38. "Some applications are missing from `emqx_machine_boot:sorted_reboot_apps/0`!\n",
  39. "Missing applications:\n",
  40. Enum.map(missing_reboot_apps, fn app ->
  41. " * #{app}\n"
  42. end),
  43. "\n",
  44. :green,
  45. "Hint: maybe add them to `emqx_machine_boot:basic_reboot_apps_edition/1`\n",
  46. "\n",
  47. :yellow,
  48. "Applications that call `mria:create_table` need to be added to that list;\n",
  49. " otherwise, when a node joins a cluster, it might lose tables.\n"
  50. ])
  51. )
  52. end