From Daniel.Berger at qwest.com Thu Nov 10 10:12:09 2005 From: Daniel.Berger at qwest.com (Daniel Berger) Date: Thu, 10 Nov 2005 08:12:09 -0700 Subject: [Win32utils-devel] Windows UNC's In-Reply-To: <5F8B169E44CF3B4D8D099CF83FCD5CE30C206ED2@bebrmx06.merck.com> References: <5F8B169E44CF3B4D8D099CF83FCD5CE30C206ED2@bebrmx06.merck.com> Message-ID: <43736349.70405@qwest.com> Hi Graham, In that case I'll have to redefine File.delete and Dir.rmdir in the win32-file package and win32-dir packages, respectively. Please add a feature request on the project page so I don't forget. I should have it done this weekend. Dan Foster, Graham wrote: > I want to create a long UNC based path.. Server and top level will exist, > but subdirectories won't (FileUtils.mkdir_p fails with a unc). I'd like to > remove a none empty filetree from a UNC (FileUtils.rm fails with a unc). I'd > like to recursively copy a filetree to a destination (FileUtils.cp_r fails > with a UNC) > > All work with mapped drive letters... So I need to create / re-use a drive > mapping and then iterate through my 1.7Tb of data. > > I tried rio, and that doesn't work with drive letters, let alone UNC's :-) > Graham > > > -----Original Message----- > From: Berger, Daniel [mailto:Daniel.Berger at qwest.com] > Sent: 10 November 2005 14:52 > To: Foster, Graham > Subject: RE: Windows UNC's > > > Hi Graham, > > The win32-file package handles UNC paths for those methods that I've > redefined, not all File methods. What method in particular are you > trying to use? > > Dan > > >>-----Original Message----- >>From: Foster, Graham [mailto:graham_foster at merck.com] >>Sent: Thursday, November 10, 2005 6:37 AM >>To: Berger, Daniel >>Subject: Windows UNC's >> >> >>Hi Daniel >> >>As the "guru" on all things Windows & Ruby I hope you can >>answer a quick question. >> >>It seems that the Ruby FileUtils module doesn't understand >>UNC's, and only works with mapped drives. (Ruby >>out-of-the-box doesn't seem to understand most things Windows >>in fact! - so much for cross platform) >> >>Which Ruby module(s) do I need to dynamically map drive >>letters please. (I couldn't see it in the Win32/File module either) >> >>Thx >>Graham >> >> >> >> >>-------------------------------------------------------------- >>---------------- >>Notice: This e-mail message, together with any attachments, >>contains information of Merck & Co., Inc. (One Merck Drive, >>Whitehouse Station, New Jersey, USA 08889), and/or its >>affiliates (which may be known outside the United States as >>Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as >>Banyu) that may be confidential, proprietary copyrighted >>and/or legally privileged. It is intended solely for the use >>of the individual or entity named on this message. If you >>are not the intended recipient, and have received this >>message in error, please notify us immediately by reply >>e-mail and then delete it from your system. >>-------------------------------------------------------------- >>---------------- >> > > > > > ------------------------------------------------------------------------------ > Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system. > ------------------------------------------------------------------------------ From noreply at rubyforge.org Thu Nov 10 10:17:19 2005 From: noreply at rubyforge.org (noreply@rubyforge.org) Date: Thu, 10 Nov 2005 15:17:19 GMT Subject: [Win32utils-devel] [ win32utils-Feature Requests-2811 ] Add UNC support to file / dir Message-ID: <200511101517.jAAFHJC8029770@rubyforge.org> Feature Requests item #2811, was opened at 2005-11-10 15:17 You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=414&aid=2811&group_id=85 Category: None Group: None Status: Open Resolution: None Priority: 3 Submitted By: graham foster (fosterg2) Assigned to: Nobody (None) Summary: Add UNC support to file / dir Initial Comment: I'd like to see win32 support for UNC's on the file management level, i.e. FileUtils for Windows Enable UNC support for the following (with recursive options please) directory delete file delete file copy directory copy file move directory move Another option would be to add a 'map to driveletter' method (as once done, the existing FileUtils module works OK.) Not sure is this should be a win32 request or a FileUtils request?? Graham ---------------------------------------------------------------------- You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=414&aid=2811&group_id=85 From zdennis at mktec.com Thu Nov 10 19:48:27 2005 From: zdennis at mktec.com (zdennis) Date: Thu, 10 Nov 2005 19:48:27 -0500 Subject: [Win32utils-devel] [ win32utils-Feature Requests-2811 ] Add UNC support to file / dir In-Reply-To: <200511101517.jAAFHJC8029770@rubyforge.org> References: <200511101517.jAAFHJC8029770@rubyforge.org> Message-ID: <4373EA5B.8080005@mktec.com> noreply at rubyforge.org wrote: > Feature Requests item #2811, was opened at 2005-11-10 15:17 > You can respond by visiting: > http://rubyforge.org/tracker/?func=detail&atid=414&aid=2811&group_id=85 > > Category: None > Group: None > Status: Open > Resolution: None > Priority: 3 > Submitted By: graham foster (fosterg2) > Assigned to: Nobody (None) > Summary: Add UNC support to file / dir > > Initial Comment: > I'd like to see win32 support for UNC's on the file management level, i.e. FileUtils for Windows > Enable UNC support for the following (with recursive options please) > > directory delete > file delete > file copy > directory copy > file move > directory move > > Another option would be to add a 'map to driveletter' method (as once done, the existing FileUtils module works OK.) > > Not sure is this should be a win32 request or a FileUtils request?? > I believe I have the code to utilize WIN32OLE to handle the map-to-drive letter. If Daniel is interested I can submit it for review... Zach From djberg96 at gmail.com Thu Nov 10 20:45:43 2005 From: djberg96 at gmail.com (Daniel Berger) Date: Thu, 10 Nov 2005 18:45:43 -0700 Subject: [Win32utils-devel] [ win32utils-Feature Requests-2811 ] Add UNC support to file / dir In-Reply-To: <4373EA5B.8080005@mktec.com> References: <200511101517.jAAFHJC8029770@rubyforge.org> <4373EA5B.8080005@mktec.com> Message-ID: <4373F7C7.8040508@gmail.com> zdennis wrote: >noreply at rubyforge.org wrote: > > >>Feature Requests item #2811, was opened at 2005-11-10 15:17 >>You can respond by visiting: >>http://rubyforge.org/tracker/?func=detail&atid=414&aid=2811&group_id=85 >> >>Category: None >>Group: None >>Status: Open >>Resolution: None >>Priority: 3 >>Submitted By: graham foster (fosterg2) >>Assigned to: Nobody (None) >>Summary: Add UNC support to file / dir >> >>Initial Comment: >>I'd like to see win32 support for UNC's on the file management level, i.e. FileUtils for Windows >>Enable UNC support for the following (with recursive options please) >> >>directory delete >>file delete >>file copy >>directory copy >>file move >>directory move >> >>Another option would be to add a 'map to driveletter' method (as once done, the existing FileUtils module works OK.) >> >>Not sure is this should be a win32 request or a FileUtils request?? >> >> >> > >I believe I have the code to utilize WIN32OLE to handle the map-to-drive >letter. If Daniel is interested I can submit it for review... > >Zach >_______________________________________________ >win32utils-devel mailing list >win32utils-devel at rubyforge.org >http://rubyforge.org/mailman/listinfo/win32utils-devel > > > Actually, I just realized that win32.c already defines File.unlink and Dir.rmdir separately, so I'm not sure why they would fail (within FileUtils), so that's not a Ruby specific issue I don't think Zach, please submit your code for review. Thanks, Dan From Daniel.Berger at qwest.com Fri Nov 11 11:33:32 2005 From: Daniel.Berger at qwest.com (Daniel Berger) Date: Fri, 11 Nov 2005 09:33:32 -0700 Subject: [Win32utils-devel] [Fwd: Thanks for win32-service] Message-ID: <4374C7DC.10502@qwest.com> Nice. :) -------------- next part -------------- An embedded message was scrubbed... From: Jamey Cribbs Subject: Thanks for win32-service Date: Fri, 11 Nov 2005 11:33:13 -0500 Size: 2505 Url: http://rubyforge.org/pipermail/win32utils-devel/attachments/20051111/5b46cd4f/Thanksforwin32-service.eml From zdennis at mktec.com Mon Nov 14 08:37:03 2005 From: zdennis at mktec.com (zdennis) Date: Mon, 14 Nov 2005 08:37:03 -0500 Subject: [Win32utils-devel] [ win32utils-Feature Requests-2811 ] Add UNC support to file / dir In-Reply-To: <4373F7C7.8040508@gmail.com> References: <200511101517.jAAFHJC8029770@rubyforge.org> <4373EA5B.8080005@mktec.com> <4373F7C7.8040508@gmail.com> Message-ID: <437892FF.5070405@mktec.com> Daniel Berger wrote: > > Zach, please submit your code for review. > This is the raw code, how I use it currently. I can clean it up and make it meet any interfaces you're looking for. I use this code on windows 2000 and Windows xp workstations, I haven't had an older version of windows around to test it on. Let me know if any questions or comment. ttyl, Zach -------------- next part -------------- A non-text attachment was scrubbed... Name: windows_host.rb Type: application/x-ruby Size: 4864 bytes Desc: not available Url : http://rubyforge.org/pipermail/win32utils-devel/attachments/20051114/6642f918/windows_host.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: wscript.rb Type: application/x-ruby Size: 1928 bytes Desc: not available Url : http://rubyforge.org/pipermail/win32utils-devel/attachments/20051114/6642f918/wscript.bin From Daniel.Berger at qwest.com Tue Nov 22 17:06:24 2005 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Tue, 22 Nov 2005 16:06:24 -0600 Subject: [Win32utils-devel] Win32 Service Timeout command Message-ID: <39AA6550E5AA554AB1456707D6E5563DBCFD4A@QTOMAE2K3M01.AD.QINTRA.COM> > -----Original Message----- > From: Jamey Cribbs [mailto:cribbsj at oakwood.org] > Sent: Tuesday, November 22, 2005 2:44 PM > To: Berger, Daniel > Subject: Win32 Service Timeout command > > > Hi, Dan. I have a quick question. Is there a way to set a timeout > variable when starting/creating a win32 service using your package? > When I attempt to start a KirbyBase process as a service, I have > KirbyBase building in-memory indexes before it returns. This > can take a > few seconds for large indexes. When I attempt to do this by > starting it > as a win32 service, it bombs out telling me the application didn't > respond in a timely manner. > > If I remove the indexes so that KirbyBase initialization > returns a lot > sooner, everything works fine. Is there any way to tell > win32 service > to increase the timeout variable? > > I looked through the docs and the example programs but didn't see > anything. I googled and did find something about a "timeout > hint", but > I don't know how to apply it to your package. > > Thanks for any help you can give! > > Jamey Cribbs Hi Jamey, I've cc'd the win32utils-devel mailing list for some additional feedback. Heesob, is this because of the default 2 second WaitHint value that StartService() uses? If so, I think the solution is to allow a "timeout=" option in the Service.create_service method, and wrap the StartService() function in a "while dwCurrentState == SERVICE_START_PENDING; sleep(x)" type of loop. I'm basing my opinion on this link: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc /base/starting_a_service.asp Does that seem a reasonable approach? Of course, this would still mean Jamey would have to guess at a timeout value. Is there a better approach in general? Regards, Dan From phasis at nownuri.net Tue Nov 22 22:59:42 2005 From: phasis at nownuri.net (=?EUR-KR?Q?=B9=DA=C8=F1=BC=B7?=) Date: Wed, 23 Nov 2005 12:59:42 +0900 Subject: [Win32utils-devel] Win32 Service Timeout command In-Reply-To: <39AA6550E5AA554AB1456707D6E5563DBCFD4A@QTOMAE2K3M01.AD.QINTRA.COM> References: <39AA6550E5AA554AB1456707D6E5563DBCFD4A@QTOMAE2K3M01.AD.QINTRA.COM> Message-ID: <20051123034849.M42180@nownuri.net> Hi, On Tue, 22 Nov 2005 16:06:24 -0600, Berger, Daniel wrote > > -----Original Message----- > > From: Jamey Cribbs [mailto:cribbsj at oakwood.org] > > Sent: Tuesday, November 22, 2005 2:44 PM > > To: Berger, Daniel > > Subject: Win32 Service Timeout command > > > > > > Hi, Dan. I have a quick question. Is there a way to set a timeout > > variable when starting/creating a win32 service using your package? > > When I attempt to start a KirbyBase process as a service, I have > > KirbyBase building in-memory indexes before it returns. This > > can take a > > few seconds for large indexes. When I attempt to do this by > > starting it > > as a win32 service, it bombs out telling me the application didn't > > respond in a timely manner. > > > > If I remove the indexes so that KirbyBase initialization > > returns a lot > > sooner, everything works fine. Is there any way to tell > > win32 service > > to increase the timeout variable? > > > > I looked through the docs and the example programs but didn't see > > anything. I googled and did find something about a "timeout > > hint", but > > I don't know how to apply it to your package. > > > > Thanks for any help you can give! > > > > Jamey Cribbs > > Hi Jamey, > > I've cc'd the win32utils-devel mailing list for some additional > feedback. > > Heesob, is this because of the default 2 second WaitHint value that > StartService() uses? > > If so, I think the solution is to allow a "timeout=" option in the > Service.create_service method, and wrap the StartService() function in a > "while dwCurrentState == SERVICE_START_PENDING; sleep(x)" type of loop. > I'm basing my opinion on this link: > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc > /base/starting_a_service.asp > > Does that seem a reasonable approach? > > Of course, this would still mean Jamey would have to guess at a timeout > value. Is there a better approach in general? > > Regards, > > Dan > I think the following is a reasonable approach. Call the function SetTheServiceStatus(SERVICE_START_PENDING, NO_ERROR, checkpoint, 0); with incremented checkpoint each step of initializing process. I'm basing my opinion on this link: http://msdn.microsoft.com/library/default.asp?url=/library/en- us/dllproc/base/service_status_process_str.asp dwCheckPoint Check-point value that the service increments periodically to report its progress during a lengthy start, stop, pause, or continue operation. For example, the service should increment this value as it completes each step of its initialization when it is starting up. The user interface program that invoked the operation on the service uses this value to track the progress of the service during a lengthy operation. This value is not valid and should be zero when the service does not have a start, stop, pause, or continue operation pending. Regards, Park Heesob From phasis at nownuri.net Wed Nov 23 08:15:40 2005 From: phasis at nownuri.net (Park Heesob) Date: Wed, 23 Nov 2005 22:15:40 +0900 Subject: [Win32utils-devel] Some code change suggestions of then win32-service package References: <4374C7DC.10502@qwest.com> Message-ID: <00a701c5f030$00c67630$0da0b7d2@2xnm9896kmqn5b9> Hi, I'd like to suggest some code modifications and tests. In service.c line # 50 : Commet out 1 line // SetTheServiceStatus(SERVICE_RUNNING, NO_ERROR, 0, 0); line # 260 : Insert 4 lines if(rb_respond_to(self,rb_intern("service_init"))){ rb_funcall(self,rb_intern("service_init"),0); } SetTheServiceStatus(SERVICE_RUNNING, NO_ERROR, 0, 0); In Ruby source Insert 'service_init' method for initialization I tested with long initialization and it worked fine. def service_init for i in 1..10 File.open("c:\\test2.log","a+"){ |f| f.puts("#{i}") } sleep 10 end end I think it is not a perfect solution but at least better than the current verison. Regards, Park Heesob From Daniel.Berger at qwest.com Wed Nov 23 09:42:34 2005 From: Daniel.Berger at qwest.com (Berger, Daniel) Date: Wed, 23 Nov 2005 08:42:34 -0600 Subject: [Win32utils-devel] Some code change suggestions of thenwin32-service package Message-ID: <39AA6550E5AA554AB1456707D6E5563DBCFD4B@QTOMAE2K3M01.AD.QINTRA.COM> > -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org > [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of > Park Heesob > Sent: Wednesday, November 23, 2005 6:16 AM > To: Development and ideas for win32utils projects > Subject: [Win32utils-devel] Some code change suggestions of > thenwin32-service package > > > Hi, > > I'd like to suggest some code modifications and tests. > > In service.c > line # 50 : Commet out 1 line > // SetTheServiceStatus(SERVICE_RUNNING, NO_ERROR, 0, 0); > > line # 260 : Insert 4 lines > if(rb_respond_to(self,rb_intern("service_init"))){ > rb_funcall(self,rb_intern("service_init"),0); > } > SetTheServiceStatus(SERVICE_RUNNING, NO_ERROR, 0, 0); > > In Ruby source > Insert 'service_init' method for initialization > > I tested with long initialization and it worked fine. > > def service_init > for i in 1..10 > File.open("c:\\test2.log","a+"){ |f| f.puts("#{i}") } > sleep 10 > end > end > > I think it is not a perfect solution but at least better than > the current > verison. > > Regards, > > Park Heesob This looks reasonable. Did we still want to use SetTheServiceStatus(SERVICE_START_PENDING, NO_ERROR, checkpoint, 0) somewhere during initialization, or does the creation of a service_init method eliminate the need for it? Thanks, Dan From phasis at nownuri.net Sat Nov 26 10:50:53 2005 From: phasis at nownuri.net (Park Heesob) Date: Sun, 27 Nov 2005 00:50:53 +0900 Subject: [Win32utils-devel] Another patch of win32-service for nice startup. Message-ID: <006f01c5f2a1$2edfc300$f00d5bd2@2xnm9896kmqn5b9> Hi, I believe this patch would be a perfect solution for a lengthy initialization application. Added hStartEvent, service_init, checkpoint increments. ============================================================ --- temp/service.c 2005-11-27 00:03:30.000000000 +0900 +++ service.c 2005-11-27 00:01:58.000000000 +0900 @@ -14,6 +14,7 @@ static VALUE cDaemonError; static VALUE rbServiceStruct, rbServiceStatusStruct; +static HANDLE hStartEvent; static HANDLE hStopEvent; static SERVICE_STATUS_HANDLE ssh; static DWORD dwServiceState; @@ -33,6 +34,7 @@ { DWORD bRet; DWORD dwWaitRes; + int i; // Obtain the name of the service. LPTSTR lpszServiceName = lpszArgv[0]; @@ -46,6 +48,15 @@ rb_raise(cDaemonError,"RegisterServiceCtrlHandler failed"); } + // wait for sevice initialization + for(i=1;TRUE;i++) + { + if(WaitForSingleObject(hStartEvent, 1000) == WAIT_OBJECT_0) + break; + + SetTheServiceStatus(SERVICE_START_PENDING, 0, i, 1000); + } + // The service has started. SetTheServiceStatus(SERVICE_RUNNING, NO_ERROR, 0, 0); @@ -241,9 +252,9 @@ } #endif - // Create Thread for service main - hThread = CreateThread(NULL,0,ThreadProc,0,0,&ThreadId); - if(hThread == INVALID_HANDLE_VALUE){ + // Create the event to signal the service to start. + hStartEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if(hStartEvent == NULL){ strcpy(error,ErrorDescription(GetLastError())); ErrorStopService(); rb_raise(cDaemonError,error); @@ -257,11 +268,20 @@ rb_raise(cDaemonError,error); } - // Wait for SERVICE_RUNNING - while(dwServiceState != SERVICE_RUNNING){ - sleep(10); + // Create Thread for service main + hThread = CreateThread(NULL,0,ThreadProc,0,0,&ThreadId); + if(hThread == INVALID_HANDLE_VALUE){ + strcpy(error,ErrorDescription(GetLastError())); + ErrorStopService(); + rb_raise(cDaemonError,error); + } + + if(rb_respond_to(self,rb_intern("service_init"))){ + rb_funcall(self,rb_intern("service_init"),0); } + SetEvent(hStartEvent); + // Call service_main method if(rb_respond_to(self,rb_intern("service_main"))){ rb_funcall(self,rb_intern("service_main"),0); ======================================================== I tested with the code of 400 seconds initialization and work fine. def service_init for i in 1..20 File.open("c:\\test2.log","a+"){ |f| f.puts("#{i}") } sleep 20 end end Regards, Park Heesob From djberg96 at gmail.com Sat Nov 26 19:32:07 2005 From: djberg96 at gmail.com (Daniel Berger) Date: Sat, 26 Nov 2005 17:32:07 -0700 Subject: [Win32utils-devel] Another patch of win32-service for nice startup. In-Reply-To: <006f01c5f2a1$2edfc300$f00d5bd2@2xnm9896kmqn5b9> References: <006f01c5f2a1$2edfc300$f00d5bd2@2xnm9896kmqn5b9> Message-ID: <4388FE87.9060902@gmail.com> Excellent. Patch committed. I'll have a release out tonight or tomorrow. Thanks! Dan Park Heesob wrote: >Hi, > >I believe this patch would be a perfect solution for a lengthy >initialization application. >Added hStartEvent, service_init, checkpoint increments. > >============================================================ >--- temp/service.c 2005-11-27 00:03:30.000000000 +0900 >+++ service.c 2005-11-27 00:01:58.000000000 +0900 >@@ -14,6 +14,7 @@ > static VALUE cDaemonError; > static VALUE rbServiceStruct, rbServiceStatusStruct; > >+static HANDLE hStartEvent; > static HANDLE hStopEvent; > static SERVICE_STATUS_HANDLE ssh; > static DWORD dwServiceState; >@@ -33,6 +34,7 @@ > { > DWORD bRet; > DWORD dwWaitRes; >+ int i; > > // Obtain the name of the service. > LPTSTR lpszServiceName = lpszArgv[0]; >@@ -46,6 +48,15 @@ > rb_raise(cDaemonError,"RegisterServiceCtrlHandler failed"); > } > >+ // wait for sevice initialization >+ for(i=1;TRUE;i++) >+ { >+ if(WaitForSingleObject(hStartEvent, 1000) == WAIT_OBJECT_0) >+ break; >+ >+ SetTheServiceStatus(SERVICE_START_PENDING, 0, i, 1000); >+ } >+ > // The service has started. > SetTheServiceStatus(SERVICE_RUNNING, NO_ERROR, 0, 0); > >@@ -241,9 +252,9 @@ > } > #endif > >- // Create Thread for service main >- hThread = CreateThread(NULL,0,ThreadProc,0,0,&ThreadId); >- if(hThread == INVALID_HANDLE_VALUE){ >+ // Create the event to signal the service to start. >+ hStartEvent = CreateEvent(NULL, TRUE, FALSE, NULL); >+ if(hStartEvent == NULL){ > strcpy(error,ErrorDescription(GetLastError())); > ErrorStopService(); > rb_raise(cDaemonError,error); >@@ -257,11 +268,20 @@ > rb_raise(cDaemonError,error); > } > >- // Wait for SERVICE_RUNNING >- while(dwServiceState != SERVICE_RUNNING){ >- sleep(10); >+ // Create Thread for service main >+ hThread = CreateThread(NULL,0,ThreadProc,0,0,&ThreadId); >+ if(hThread == INVALID_HANDLE_VALUE){ >+ strcpy(error,ErrorDescription(GetLastError())); >+ ErrorStopService(); >+ rb_raise(cDaemonError,error); >+ } >+ >+ if(rb_respond_to(self,rb_intern("service_init"))){ >+ rb_funcall(self,rb_intern("service_init"),0); > } > >+ SetEvent(hStartEvent); >+ > // Call service_main method > if(rb_respond_to(self,rb_intern("service_main"))){ > rb_funcall(self,rb_intern("service_main"),0); >======================================================== > >I tested with the code of 400 seconds initialization and work fine. > > def service_init > for i in 1..20 > File.open("c:\\test2.log","a+"){ |f| f.puts("#{i}") } > sleep 20 > end > end > > >Regards, > >Park Heesob > > > > > > >_______________________________________________ >win32utils-devel mailing list >win32utils-devel at rubyforge.org >http://rubyforge.org/mailman/listinfo/win32utils-devel > > > From stephenh at chase3000.com Wed Nov 30 21:51:29 2005 From: stephenh at chase3000.com (Stephen Haberman) Date: Wed, 30 Nov 2005 20:51:29 -0600 Subject: [Win32utils-devel] service_cli.rb Message-ID: <001601c5f622$21915220$6501a8c0@sh4> Hi, I just got done using win32/service to run a very small/hack-ish "Riki" WEBrick service. Very cool stuff. Thanks. So, in the process, I noticed a lot of the "control" start/install/etc. command line parser stuff looked a bit boilerplate, so I pulled it out into a helper function "service_cli" (for lack of a better name). Its simple, but it allows me to do away with a Riki-specific control script. So I can just do: riki.rb: ---- $LOAD_PATH.unshift File.dirname(__FILE__) require 'service_cli' class RikiDaemon < Win32::Daemon def self.setup(s) s.binary_path_name = "ruby #{__FILE__} --service" end ...service_main/service_stop... end service_cli('Riki', RikiDaemon) ---- So now the "control" and "daemon" functions are both handled from the same generic script (I added an odd but effective command line parameter of --service which means its getting started by win32 and should call daemon_class.new.mainloop). And now "service_cli.rb" is just generic code I could potentially reuse across other services. So, I dunno, perhaps this is too simple or utility-ish, but it has the potential to remove ~50 lines of boilerplate control/command line code, so I thought maybe I'd send it in and see if it was interesting enough to include in the distribution. (Also, I apologize if you're getting this twice, but I sent this about a week ago but from an email address other than the one I signed up to the list for, so it likely did not go through. Since then, I have added a -a/--standalone flag for easily starting the service_main/service_stop for debugging purposes and thought I'd submit it again.) Thanks, Stephen -------------- next part -------------- A non-text attachment was scrubbed... Name: service_cli.rb Type: application/octet-stream Size: 2288 bytes Desc: not available Url : http://rubyforge.org/pipermail/win32utils-devel/attachments/20051130/9fa1ee67/service_cli.obj