raisedragon / pircbotx

Automatically exported from code.google.com/p/pircbotx
0 stars 0 forks source link

Run PircBotx as Deamon #90

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create the bot as a 'monitoring service' to some process running as a Daemon
2. The Daemon process shuts down. (but fails to notify the bot)
3. The jvm will be kept alive by the pircBotX

What is the expected output? What do you see instead?
The option to specify the bot running in Daemon mode causing it to shutdown 
when the JVM fails.

What version of the product are you using? On what operating system?
PircBotX-1-7

Please provide any additional information below.
We are currently attempting to use PircBot as a log appender in Logback. 
(Obtained though LoggerFactory) so the application doesnt know about whether 
its logging to irc or not.

Some of the proccesses we would like to use this logger on dont always behave 
correctly or chrash thus missing the opportunity to shutdown the this ircbot 
logger.
Because the bot contains non-deamon threads  it leaves de JVM alive 
indefinately.

I attached a quick workaround we are currently thinking about using. however if 
this is something which would be accepted as a feature of PircBotX i could work 
out a cleaner (full) patch if needed.

Regards,
Pieter Goddijn.

Original issue reported on code.google.com by pvgodd...@gmail.com on 30 Oct 2012 at 12:05

Attachments:

GoogleCodeExporter commented 9 years ago
Can you run the latest snapshot version ( 
http://code.google.com/p/pircbotx/wiki/DevVersion )? There is a regression in 
1.7 where OutputThread never was killed so the JVM just sat there

Just to let you know, your fix (marking the thread as a dameon thread) has been 
brought up before but simply won't work. This is because now the JVM will exit 
either randomly or right after you connect because there are no threads keeping 
it open (remember all Listener threads are marked as dameon as well). 

Original comment by Lord.Qua...@gmail.com on 30 Oct 2012 at 12:11

GoogleCodeExporter commented 9 years ago
I know this 'fix' wont work in the normal case where the bot is run as a 
standalone bot. (this is why it should ofcourse be optional and default off)

The problem i have is when i try to run the bot as a dependant process to a 
(unreliable) non-daemon process. (and am unable to always call shutdown from 
the non-deamon process)

Original comment by pvgodd...@gmail.com on 30 Oct 2012 at 1:18

GoogleCodeExporter commented 9 years ago
That's why I'm suggesting trying the latest dev version as the current release 
version has a bug in these circumstances. It should solve your problem 

Original comment by Lord.Qua...@gmail.com on 30 Oct 2012 at 1:21

GoogleCodeExporter commented 9 years ago
Hi,

I just tried i with the latest dev version but this doesnt solve the problem i 
have.

The following is psuedocode simplification of my problem

main(String[] args) {
PircBot bot = new Bot();
bot.connect(..);

LoggerFactory.createLogger(new IrcLogger(bot));

Thread nonDeamon = new Thread(new Runnable() {
          //code effectively out of my control
          Logger logbot  =LoggerFactory.getLogger('irc'); // no direct reference to the bot

          while(true_for_some_time) {

               //This is the core proc
               String stuff = doStuff();
               log.info(stuff); ---> this goes to IRC
          }
    });
nonDeamon.start();
}

Because the main thread terminates after starting the process i want to log to 
IRC i cant shut down the logger in the main thread. (this would be too soon). 
Shutting down the bot in the forked thread is also not an option because this 
is largely out of my control.

In this case the PircBotx's in/outputThreads keep the JVM alive after my 
runnable is done. Again this is not a problem if the bot is a standalone bot, 
and i dont regard it as a Bug Per-se

What i'm looking for is the irc bot automatically shut it self down if there 
are no other (nondaemon) thread alive in the VM. The shutdown hooks seems to 
make this a clean process (cleaning up the connections)

Hopefully this clarifies my problem a bit better.
If this feature isnt added i can work around it so it fine with me if you 
reject it.

Regards,
Pieter Goddijn.

}

Original comment by pvgodd...@gmail.com on 30 Oct 2012 at 2:36

GoogleCodeExporter commented 9 years ago
Hi i've been looking into the construction with the shutdownHook some more, and 
i think in most cases this would ensure the behavior i would want (bot disposes 
as it goes out of scope). I'm my case this doesnt happen because the the 
logAppender hold a reference to the bot.

So i think this makes my problem too much of an edgecase to actually justify 
adding this as a feature. I still need to workaround myself because the 
lifecycle of our loggers are not managed well enough.

Thanks for the quick replies and the upgrade of PircBot to PircBotX though!
With all the private finals in the original i was unable to work around this. 
The event system also look nice.

Regards,
Pieter Goddijn

Original comment by pvgodd...@gmail.com on 30 Oct 2012 at 4:41

GoogleCodeExporter commented 9 years ago
I still think that you are probably doing something wrong, but if you want you 
can override createInputThread() and createOuputThread() in PircBotX and mark 
the threads as dameon threads there. Just make sure you have another thread 
always waiting. 

I'm going to go ahead and mark this as Invalid, but please comment again if you 
need more help

Original comment by Lord.Qua...@gmail.com on 30 Oct 2012 at 4:49

GoogleCodeExporter commented 9 years ago
np
Thanks for the feedback

Original comment by pvgodd...@gmail.com on 30 Oct 2012 at 11:57