I'm honestly not sure how gracefully q() kills the VM, but both Chan and I
are giving suggestions for when you run boss:stop().

If you are going want to shut down gracefully, then I'd suggest
boss:stop(), followed by q().

Then you can be sure your shutdown scripts have been run. That said, there
are obviously numerous reasons a VM could be shut down instantly and
without a proper shutdown (kill -9, power failure, kernel panic, etc).

If you can, I recommend building around that kind of restriction, rather
than relying on a "clean shutdown" every time.

--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm
On Aug 6, 2014 5:36 AM, "chan sisowath" <[email protected]> wrote:

> this code should work :).
>
> as jesse suggested
>
>
> -module(test_script).
>
> -export([init/0, stop/1]).
> -export([watch_boss/0]).
>
>
> init() ->
>     Pid = spawn(?MODULE, watch_boss, []),
>     io:format("~n~n<<<< -------- init -------- script --------->> Pid ~p
> ~n~n",[Pid]),
>     {ok, []}.
>
> stop(_) ->
>  [].
>
> watch_boss() ->
>     Ref = monitor(process, boss_web),
>     receive
>         {Reason, _, process, {boss_web, _}, _} ->
>             %% call my awesome script
>             io:format("~n~n<<<< -------- stop -------- script --------->>
> ~p ~p<<---~n~n",[Ref, Reason])
>     end.
>
>
> 2014-08-06 15:19 GMT+08:00 Caiyun Deng <[email protected]>:
>
>> Does your stop/1 in the priv/init will be called when the server stop?
>>
>> 在 2014年8月6日星期三UTC+8下午2时40分52秒,mihawk写道:
>>>
>>> it is called when reloaded:
>>> here https://github.com/ChicagoBoss/ChicagoBoss/blob/
>>> master/src/boss/boss_web_controller.erl#L131
>>>
>>> but it is called also when boss_web_controller terminate:
>>>
>>> https://github.com/ChicagoBoss/ChicagoBoss/blob/
>>> master/src/boss/boss_web_controller.erl#L32
>>>
>>> as far as i know
>>>
>>>
>>> 2014-08-06 14:23 GMT+08:00 Caiyun Deng <[email protected]>:
>>>
>>>> I also tried stop/1 in priv/init, it does not work.
>>>> But it didn't say the stop/1 will execute when the server stop. It just
>>>> say that "stop is executed if the script is ever reloaded".
>>>>
>>>> 在 2014年8月6日星期三UTC+8下午1时38分06秒,mihawk写道:
>>>>>
>>>>> hi,
>>>>>
>>>>> same as init
>>>>>
>>>>> just implement stop/1 in you module piv/init
>>>>> if it doesn't work just make an issue.
>>>>>
>>>>> chan
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> 2014-08-06 12:51 GMT+08:00 Caiyun Deng <[email protected]>:
>>>>>
>>>>>>  Hi! I tried it,  I typed "q()" in ./init-dev.sh and "./init.sh stop"
>>>>>> in the production mode, but it does not work.
>>>>>>  spawn(fun() -> monitor_stop() end),
>>>>>> monitor_stop() ->
>>>>>>     ?TRACE_VAR(monitor_stop),
>>>>>>     Ref = erlang:monitor(process, boss_sup),
>>>>>>     receive
>>>>>>         Msg ->
>>>>>>             ?TRACE_VAR(Msg),
>>>>>>             monitor_stop()
>>>>>>     end.
>>>>>>
>>>>>>
>>>>>>
>>>>>> 在 2014年8月6日星期三UTC+8上午3时02分11秒,Jesse Gumm写道:
>>>>>>>
>>>>>>> There's not currently (As far as I know) a standard way to do that,
>>>>>>> but you could use a monitor to achieve it.
>>>>>>>
>>>>>>> Ref = monitor(process, boss_sup),
>>>>>>> receive
>>>>>>>     {'DOWN', _, process, {boss_sup, _}, _} ->
>>>>>>> run_my_other_shutdown_scripts()
>>>>>>> end.
>>>>>>>
>>>>>>> -Jesse
>>>>>>>
>>>>>>> On Mon, Aug 4, 2014 at 4:16 AM, Caiyun Deng <[email protected]>
>>>>>>> wrote:
>>>>>>> > Hi!
>>>>>>> > When i want to do something at the server start, I can do
>>>>>>> something in
>>>>>>> > priv/init.
>>>>>>> > But when i want to do something at the server stop, How can i do?
>>>>>>> >
>>>>>>> > --
>>>>>>> > You received this message because you are subscribed to the Google
>>>>>>> Groups
>>>>>>> > "ChicagoBoss" group.
>>>>>>> > To unsubscribe from this group and stop receiving emails from it,
>>>>>>> send an
>>>>>>> > email to [email protected].
>>>>>>> > Visit this group at http://groups.google.com/group/chicagoboss.
>>>>>>> > To view this discussion on the web visit
>>>>>>> > https://groups.google.com/d/msgid/chicagoboss/b1c56929-e5ac-
>>>>>>> 4990-ba10-6a3188e49ed2%40googlegroups.com.
>>>>>>> >
>>>>>>> > For more options, visit https://groups.google.com/d/optout.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Jesse Gumm
>>>>>>> Owner, Sigma Star Systems
>>>>>>> 414.940.4866 || sigma-star.com || @jessegumm
>>>>>>>
>>>>>>  --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "ChicagoBoss" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to [email protected].
>>>>>> Visit this group at http://groups.google.com/group/chicagoboss.
>>>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>>>> msgid/chicagoboss/bd266859-2009-46bb-8655-0a91df5595a0%40googl
>>>>>> egroups.com
>>>>>> <https://groups.google.com/d/msgid/chicagoboss/bd266859-2009-46bb-8655-0a91df5595a0%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>>
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "ChicagoBoss" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> Visit this group at http://groups.google.com/group/chicagoboss.
>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>> msgid/chicagoboss/f5b9ee23-79d7-4351-875f-cf003d634e7f%
>>>> 40googlegroups.com
>>>> <https://groups.google.com/d/msgid/chicagoboss/f5b9ee23-79d7-4351-875f-cf003d634e7f%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  --
>> You received this message because you are subscribed to the Google Groups
>> "ChicagoBoss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> Visit this group at http://groups.google.com/group/chicagoboss.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/chicagoboss/27e12e81-9d85-4cdf-a871-4a2caf806012%40googlegroups.com
>> <https://groups.google.com/d/msgid/chicagoboss/27e12e81-9d85-4cdf-a871-4a2caf806012%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "ChicagoBoss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> Visit this group at http://groups.google.com/group/chicagoboss.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/chicagoboss/CAB-Ofhnupg4uuEE_9amxThE_gbDqf9TqdokaZmnJZ4%3DiVNbcFA%40mail.gmail.com
> <https://groups.google.com/d/msgid/chicagoboss/CAB-Ofhnupg4uuEE_9amxThE_gbDqf9TqdokaZmnJZ4%3DiVNbcFA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/chicagoboss/CAPTXyXejDB%2BmoqzTAsb599vR5WNnBZyMv2R1%2BrKUg0OrTuA3ag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to