@@ -229,7 +229,7 @@ defmodule SafeNIF.Pool do
229229 :peer . start_link ( % {
230230 name: node_name ,
231231 wait_boot: { caller , :peer_ready } ,
232- args: [ ~c " -hidden " ]
232+ args: peer_args ( )
233233 } )
234234
235235 peer =
@@ -246,6 +246,56 @@ defmodule SafeNIF.Pool do
246246 % __MODULE__ { node: peer , controller_pid: controller_pid , last_checkin: System . monotonic_time ( ) }
247247 end
248248
249+ defp peer_args do
250+ args = [ ~c" -hidden" ]
251+ args = maybe_add_cookie_args ( args )
252+ in_release? = System . get_env ( "RELEASE_ROOT" ) != nil
253+
254+ if in_release? do
255+ add_release_boot! ( args )
256+ else
257+ args
258+ end
259+ end
260+
261+ defp maybe_add_cookie_args ( args ) do
262+ case Node . get_cookie ( ) do
263+ :nocookie -> args
264+ cookie -> [ ~c" -setcookie" , Atom . to_charlist ( cookie ) | args ]
265+ end
266+ end
267+
268+ defp add_release_boot! ( args ) do
269+ release_root = System . fetch_env! ( "RELEASE_ROOT" )
270+ release_vsn = System . fetch_env! ( "RELEASE_VSN" )
271+
272+ boot_path = Path . join ( [ release_root , "releases" , release_vsn , "start_clean" ] )
273+ boot_file = boot_path <> ".boot"
274+
275+ if not File . exists? ( boot_file ) do
276+ raise RuntimeError , """
277+ The current running node was detected to be part of a mix release,
278+ with the `RELEASE_ROOT` environment variable set to
279+ #{ System . get_env ( "RELEASE_ROOT" ) } and the `RELEASE_VSN` environment
280+ variable set to #{ System . get_env ( "RELEASE_VSN" ) } .
281+
282+ We tried to load the `start_clean` bootfile from #{ boot_file } ,
283+ but this file does not exist.
284+ """
285+ end
286+
287+ release_lib = Path . join ( release_root , "lib" )
288+
289+ [
290+ ~c" -boot" ,
291+ String . to_charlist ( boot_path ) ,
292+ ~c" -boot_var" ,
293+ ~c" RELEASE_LIB" ,
294+ String . to_charlist ( release_lib )
295+ | args
296+ ]
297+ end
298+
249299 defp rpc ( node , module , function , args ) do
250300 :rpc . block_call ( node , module , function , args )
251301 end
0 commit comments