Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#580 closed enhancement (fixed)

signal to restart i2p while running in console mode

Reported by: k0e Owned by: zzz
Priority: minor Milestone: 0.8.13
Component: router/general Version: 0.8.12
Keywords: Cc:
Parent Tickets: Sensitive: no

Description

Could there be a way to send a signal, for ex: sighup, to i2psvc and have it trigger a restart (kinda how it does when it detects an update archive)?

at the moment sending sigup kills the i2p process

Subtickets

Change History (9)

comment:1 Changed 8 years ago by killyourtv

That would be functionality needed for the wrapper. In Tanuki's changelog for 3.3.0, I see

* Add support for the SIGUSR1 and SIGUSR2 signals so they can now trigger a
  shutdown, restart or be forwarded to the JVM for custom functionality.
  See the wrapper.signal.mode.usr1 and wrapper.signal.mode.usr2 properties.
  Based on a patch by Robey Pointer.  Note that the JVM process does not
  trap SIGUSR1 or SIGUSR2 signals as they are used internally by the JVM
  as part of the garbage collection process.

…which means that the feature you're requesting is already there.

See wrapper.signal.mode.usr1 & wrapper.signal.mode.usr2 (but I've not tried this; I've just used "i2prouter restart" when in console mode)

comment:2 Changed 8 years ago by killyourtv

Or *functionality may be there.

I don't know that sending a restart signal to the JVM will actually restart I2P….

comment:3 Changed 8 years ago by zzz

It would be nice. We would need some code to handle the signals. I tried to implement it and USR1 and USR2 don't seem to work. One of them actually crashes the JVM (can't remember which one).

We can handle HUP, but HUP is used for regular shutdown now. Perhaps INT or QUIT. But it depends on JVM and platform, and using the wrong one could, for example, prevent C from working. See also http://www.ibm.com/developerworks/java/library/i-signalhandling/

The supported way, now, is to use the i2pcontrol plugin. http://www.i2p2.i2p/i2pcontrol . Ask hottuna on IRC for some JSON shell scripts for it. I believe graceful shutdown/restart is working but ask him.

comment:4 Changed 8 years ago by zzz

hmm. now I know how to do superscripts in markdown

comment:5 Changed 8 years ago by zzz

OK

Only HUP, USR1, and USR2 can be configured. But what Tanuki is saying is that in theory you can FORWARD USR1 and USR2 and do custom handling, in practice you can't because they are used internally in the JVM.

So the only one we could use for custom actions is HUP.

But that would break compatibility with old i2prouter scripts. So the best we could do is have an advanced router config that specifies graceful shutdown on HUP. We could set that for new installs but others would have to add it manually.

So in i2prouter for new installs, we would change stop to send INT or TERM instead of HUP. And we would send HUP for graceful.

And in wrapper.config we set wrapper.signal.mode.usr1 and wrapper.signal.mode.usr2 to IGNORE or SHUTDOWN since they are really bad to forward.

comment:6 Changed 8 years ago by zzz

Milestone: 0.8.13
Owner: set to zzz
Status: newaccepted

comment:7 Changed 8 years ago by zzz

Resolution: fixed
Status: acceptedclosed

Support added (and numerous shutdown bugs fixed) in 0.8.12-1.

To do a graceful shutdown on SIGHUP, set router.gracefulHUP=true in advanced config.

If you do this, get the updated i2prouter script so that 'i2prouter stop' sends a SIGTERM and 'i2prouter graceful' is supported to send the HUP.

The major bugfix is that since 0.8.8, 'i2prouter stop' or SIGHUP/TERM/INT did not trigger the router shutdown code, it just shut the JVM down hard. The router should now shut down cleanly again with i2prouter stop or the signals.

As we only have one signal (HUP) to play with, we can't do both graceful shutdown and graceful restart with signals. Use the I2PControl plugin for that.

comment:8 Changed 8 years ago by zzz

<k[0]e> CRIT [vent-Monitor] outer.web.ConfigServiceHandler?: Hard shutdown initiated by SIGHUP
<k[0]e> zzz, is that expected bahavior on sighup?
<k[0]e> as per the ticket, i wanted hup to do a restart
<k[0]e> or can i just change one of the wrapper.on_exit directives to RESTART?
<k[0]e> brb gonna try that
<zzz> k0e, i have to apologize.
<zzz> somehow I got caught up fixing the bugs and messing with graceful, and I did something completely different than what you asked for, then closed the ticket
<zzz> I think wrapper.signal.mode.hup=RESTART should do what you want?
<KillYourTV> yes, that works
<KillYourTV> wrapper | HUP trapped. Restarting JVM.
<KillYourTV> jvm 1 | CRIT [r 1 shutdown] net.i2p.router.Router : Shutting down the router…
<KillYourTV> jvm 1 | CRIT [r 1 shutdown] net.i2p.router.Router : Starting final shutdown(3)
<KillYourTV> jvm 1 | CRIT [r 1 shutdown] net.i2p.router.Router : Shutdown(3) complete
<KillYourTV> wrapper | Launching a JVM…
<zzz> I don't know how I got sidetracked and forgot the original question.

comment:9 Changed 8 years ago by zzz

<MTN> i2p.i2p kytv@… * Really send HUP signal when called with the graceful parameter: http://stats.i2p/cgi-bin/viewmtn/revision/info/a04e4a4f80413882e4b19337268dddc6938f21c7

  • Parad0x2 (Parad0x@irc2p-8EE4B9C7) has joined #i2p-dev

<zzz> really?
<zzz> oh, the default wasn't HUP?
<KillYourTV> since it just had "kill $pid" it probably sent a TERM
<KillYourTV> so i made it explicitly HUP
<zzz> reading the man page now
<zzz> gosh I have really made a mess of this
<zzz> yeah the default is TERM
<zzz> in that case I can make HUP default to graceful for everybody since it wasnt used before
<KillYourTV> I think that'd be good

Note: See TracTickets for help on using tickets.