MooseX-Daemonize-0.18/000755 000767 000024 00000000000 12144240137 015037 5ustar00etherstaff000000 000000 MooseX-Daemonize-0.18/Changes000644 000767 000024 00000010473 12144240137 016337 0ustar00etherstaff000000 000000 Revision history for MooseX-Daemonize 0.18 2013-05-13 12:34:52 PDT-0700 - make tests a bit more tolerant of slow systems, by waiting longer for processes to die (RT#85229, Chisel Wright) 0.17 2013-04-20 - Makefile.PL now prevents installation on MSWin32 0.16 2013-04-14 - fix incompatibilities with Test::Builder 1.005+ (schwern, RT#76523) - add missing dependency on the version of File::Path which added make_path (RT#79169, Jonathan Sailor) - add missing test dependency on Test::Exception (RT#70382) - document the 'basedir' attribute and its behaviour (RT#83055) - add 'documentation' keys for public attributes, to be used when displaying --help (RT#54295) 0.15 2012-05-31 - fix versions 0.14 2012-05-30 - recommend Daemon::Control instead - fix bug with pidbase dir not being created if it doesn't already exist 0.13 2011-07-06 - adding docs related to closing all filehandles and the issues that can cause with things like Log::Log4Perl (thanks to Maik Hentsche via RT #67016) - updating copyright dates 0.12 2010-07-11 - release without the .git directory in it 0.11 2010-07-10 * MooseX::Daemonize::Core - make the options to daemonize() into proper attributes but still retained back-compat (Thanks to Magnus Erixzon) - adjusted docs and tests - removed the pod.t and pod-coverage.t tests 0.10 2010-04-17 - updated copyrights - removed the POE test because it was causing random failures when installing from CPAN and not adding enough value to keep around - applied POD corrections from RT #50091 (thanks to Kostyuk Oleg) 0.09 2009-10-05 * s/no_plan => 1/'no_plan'/g (Dave Rolsky) * Synchronize Version numbers 0.08 2008-09-07 * t/ - Removed usage of Cwd in favour of a temporary dir to prevent test fails when running in an unwritable dir - patch to ensure that t/01.filecreate.t passes (thanks to Jose Luis Rey) 0.07 2008-05-24 * MooseX::Daemonize - Made default pidbase '/var/run' rather than './var/run' * t/ - Small fixups to pidfile testing in t/31.with_pid_file_and_poe.t ~ Removed the Build.PL since Module::Install has removed their support 0.06 2007-12-21 * MooseX::Daemonize - Fix logic that kills process so it doens't always warn about undead process - Added stop_timeout to allow user to control timings. - Refactored to roles - removed Proc::Daemon dependency - removed File::Pid dependency - added exit_code and status_message to capture the exit code and a status message :) - refactored start/stop/restart to use these - added tests for this - added a &status command which returns a bool telling you if the daemon is running or not - added tests for this * Test::MooseX::Daemonize - updated docs - removed Proc::Daemon dependency * MooseX::Daemonize::Core - the core daemonization methods are here - added tests for this * MooseX::Daemonize::WithPidFile - the PID file handling is added to the core here - added tests for this * MooseX::Daemonize::Pid - added this package to replace the File::Pid stuff * MooseX::Daemonize::Pid::File - added this package to replace the File::Pid stuff, it is a subclass of MooseX::Daemonize::Pid (stevan) - added tests for this (stevan) 0.05 2007-11-18 - Fix logic that kills process so it doens't always warn about undead process - Added stop_timeout to allow user to control timings. 0.04 2007-11-11 - Fix stupid perlcritic.t cause the Module::Starter::PBP tests were stupid but I didn't realize it. 0.03 2007-10-22 - Add File::Slurp to dependencies so our tests pass better 0.02 2007-09-19 - Fixed bug where sometimes the pidfile is writeable but pidbase is not -- reported by dec - Fixed bug where the pidfile wasn't being updated properly -- reported by dec - Added is_daemon attribute - Added another fork to make sure we short circuit out of the daemonize process properly - Switch to File::Pid - Add the GetOpt prereq - Adjust the kill timings - Added THANKS to pod 0.0.1 2007-05-16 Initial release. MooseX-Daemonize-0.18/dist.ini000644 000767 000024 00000002472 12144240137 016510 0ustar00etherstaff000000 000000 name = MooseX-Daemonize author = Chris Prather copyright_holder = Chris Prather license = Perl_5 [Git::NextVersion] [Authority] authority = cpan:PERIGRIN [Prereqs / RuntimeRequires] Moose = 0.33 MooseX::Getopt = 0.07 MooseX::Types::Path::Class = 0 File::Path = 2.08 Sub::Exporter = 0 [Prereqs / TestRequires] Test::More = 0.88 Test::Fatal = 0 Test::Moose = 0 [MetaNoIndex] directory = t directory = examples [MetaResources] bugtracker.web = https://rt.cpan.org/Dist/Display.html?Name=MooseX-Daemonize bugtracker.mailto = bug-MooseX-Daemonize@rt.cpan.org ; r/w: gitmo@git.moose.perl.org:MooseX-Daemonize.git repository.url = git://git.moose.perl.org/MooseX-Daemonize.git repository.web = http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo/MooseX-Daemonize.git;a=summary repository.type = git [MetaJSON] [MetaConfig] [ContributorsFromGit] [PkgVersion] [NextRelease] :version = 4.300018 format = %-8V %{yyyy-MM-dd HH:mm:ss ZZZZ}d [Git::Check] :version = 1.122460 allow_dirty = [Git::Commit] allow_dirty = Changes commit_msg = %N-%v%t%n%n%c [Git::Tag] tag_format = v%v%t tag_message = v%v%t [Git::Push] ; this is last so ConfirmRelease loads last [@Basic] ; must be after MakeMaker plugin [AssertOS] os = -MSWin32 MooseX-Daemonize-0.18/inc/000755 000767 000024 00000000000 12144240137 015610 5ustar00etherstaff000000 000000 MooseX-Daemonize-0.18/lib/000755 000767 000024 00000000000 12144240137 015605 5ustar00etherstaff000000 000000 MooseX-Daemonize-0.18/LICENSE000644 000767 000024 00000043656 12144240137 016062 0ustar00etherstaff000000 000000 This software is copyright (c) 2013 by Chris Prather. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2013 by Chris Prather. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2013 by Chris Prather. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End MooseX-Daemonize-0.18/Makefile.PL000644 000767 000024 00000003144 12144240137 017013 0ustar00etherstaff000000 000000 use lib 'inc'; use Devel::AssertOS qw[-MSWin32]; use strict; use warnings; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "Role for daemonizing your Moose based application", "AUTHOR" => "Chris Prather ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "MooseX-Daemonize", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "MooseX::Daemonize", "PREREQ_PM" => { "File::Path" => "2.08", "Moose" => "0.33", "MooseX::Getopt" => "0.07", "MooseX::Types::Path::Class" => 0, "Sub::Exporter" => 0 }, "TEST_REQUIRES" => { "Test::Fatal" => 0, "Test::Moose" => 0, "Test::More" => "0.88" }, "VERSION" => "0.18", "test" => { "TESTS" => "t/*.t" } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { my $tr = delete $WriteMakefileArgs{TEST_REQUIRES}; my $br = $WriteMakefileArgs{BUILD_REQUIRES}; for my $mod ( keys %$tr ) { if ( exists $br->{$mod} ) { $br->{$mod} = $tr->{$mod} if $tr->{$mod} > $br->{$mod}; } else { $br->{$mod} = $tr->{$mod}; } } } unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); MooseX-Daemonize-0.18/MANIFEST000644 000767 000024 00000000706 12144240137 016173 0ustar00etherstaff000000 000000 Changes LICENSE MANIFEST MANIFEST.SKIP META.json META.yml Makefile.PL README dist.ini inc/Devel/AssertOS.pm inc/Devel/AssertOS/MSWin32.pm inc/Devel/CheckOS.pm lib/MooseX/Daemonize.pm lib/MooseX/Daemonize/Core.pm lib/MooseX/Daemonize/Pid.pm lib/MooseX/Daemonize/Pid/File.pm lib/MooseX/Daemonize/WithPidFile.pm lib/Test/MooseX/Daemonize.pm t/00.load.t t/01.filecreate.t t/02.stdout.t t/10.pidfile.t t/20.core.t t/21.core-back-compat.t t/30.with_pid_file.t MooseX-Daemonize-0.18/MANIFEST.SKIP000644 000767 000024 00000000311 12144240137 016730 0ustar00etherstaff000000 000000 ^_build ^Build$ ^blib ~$ \.bak$ CVS \.svn \.git \.DS_Store cover_db \..*\.sw.?$ ^Makefile$ ^pm_to_blib$ ^MakeMaker-\d ^blibdirs$ \.old$ ^#.*#$ ^\.# ^TODO$ ^PLANS$ ^benchmarks ^\._.*$ IDEAS examples labMooseX-Daemonize-0.18/META.json000644 000767 000024 00000017767 12144240137 016502 0ustar00etherstaff000000 000000 { "abstract" : "Role for daemonizing your Moose based application", "author" : [ "Chris Prather " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300034, CPAN::Meta::Converter version 2.130880", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "MooseX-Daemonize", "no_index" : { "directory" : [ "inc" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "runtime" : { "requires" : { "File::Path" : "2.08", "Moose" : "0.33", "MooseX::Getopt" : "0.07", "MooseX::Types::Path::Class" : "0", "Sub::Exporter" : "0" } }, "test" : { "requires" : { "Test::Fatal" : "0", "Test::Moose" : "0", "Test::More" : "0.88" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-MooseX-Daemonize@rt.cpan.org", "web" : "https://rt.cpan.org/Dist/Display.html?Name=MooseX-Daemonize" }, "repository" : { "type" : "git", "url" : "git://git.moose.perl.org/MooseX-Daemonize.git", "web" : "http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo/MooseX-Daemonize.git;a=summary" } }, "version" : "0.18", "x_Dist_Zilla" : { "perl" : { "version" : "5.016003" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::Git::NextVersion", "name" : "Git::NextVersion", "version" : "2.013" }, { "class" : "Dist::Zilla::Plugin::Authority", "name" : "Authority", "version" : "1.006" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "runtime", "type" : "requires" } }, "name" : "RuntimeRequires", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "test", "type" : "requires" } }, "name" : "TestRequires", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::MetaNoIndex", "name" : "MetaNoIndex", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::MetaResources", "name" : "MetaResources", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "MetaJSON", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "MetaConfig", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ContributorsFromGit", "name" : "ContributorsFromGit", "version" : "0.006001" }, { "class" : "Dist::Zilla::Plugin::PkgVersion", "name" : "PkgVersion", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "NextRelease", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "name" : "Git::Check", "version" : "2.013" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "name" : "Git::Commit", "version" : "2.013" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "name" : "Git::Tag", "version" : "2.013" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "name" : "Git::Push", "version" : "2.013" }, { "class" : "Dist::Zilla::Plugin::GatherDir", "name" : "@Basic/GatherDir", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@Basic/PruneCruft", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@Basic/ManifestSkip", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@Basic/MetaYAML", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@Basic/License", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::Readme", "name" : "@Basic/Readme", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ExtraTests", "name" : "@Basic/ExtraTests", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Basic/ExecDir", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@Basic/ShareDir", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "name" : "@Basic/MakeMaker", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@Basic/Manifest", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@Basic/TestRelease", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@Basic/ConfirmRelease", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@Basic/UploadToCPAN", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::AssertOS", "name" : "AssertOS", "version" : "0.04" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "4.300034" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : "0" }, "version" : "4.300034" } }, "x_authority" : "cpan:PERIGRIN", "x_contributors" : [ "Ash Berlin ", "Brandon L Black ", "Chisel Wright ", "Dave Rolsky ", "Jonathan Sailor ", "Karen Etheridge ", "Michael Reddick ", "Michael Schwern ", "Stevan Little ", "Yuval Kogman " ] } MooseX-Daemonize-0.18/META.yml000644 000767 000024 00000012207 12144240137 016312 0ustar00etherstaff000000 000000 --- abstract: 'Role for daemonizing your Moose based application' author: - 'Chris Prather ' build_requires: Test::Fatal: 0 Test::Moose: 0 Test::More: 0.88 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300034, CPAN::Meta::Converter version 2.130880' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: MooseX-Daemonize no_index: directory: - inc requires: File::Path: 2.08 Moose: 0.33 MooseX::Getopt: 0.07 MooseX::Types::Path::Class: 0 Sub::Exporter: 0 resources: bugtracker: https://rt.cpan.org/Dist/Display.html?Name=MooseX-Daemonize repository: git://git.moose.perl.org/MooseX-Daemonize.git version: 0.18 x_Dist_Zilla: perl: version: 5.016003 plugins: - class: Dist::Zilla::Plugin::Git::NextVersion name: Git::NextVersion version: 2.013 - class: Dist::Zilla::Plugin::Authority name: Authority version: 1.006 - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: runtime type: requires name: RuntimeRequires version: 4.300034 - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: test type: requires name: TestRequires version: 4.300034 - class: Dist::Zilla::Plugin::MetaNoIndex name: MetaNoIndex version: 4.300034 - class: Dist::Zilla::Plugin::MetaResources name: MetaResources version: 4.300034 - class: Dist::Zilla::Plugin::MetaJSON name: MetaJSON version: 4.300034 - class: Dist::Zilla::Plugin::MetaConfig name: MetaConfig version: 4.300034 - class: Dist::Zilla::Plugin::ContributorsFromGit name: ContributorsFromGit version: 0.006001 - class: Dist::Zilla::Plugin::PkgVersion name: PkgVersion version: 4.300034 - class: Dist::Zilla::Plugin::NextRelease name: NextRelease version: 4.300034 - class: Dist::Zilla::Plugin::Git::Check name: Git::Check version: 2.013 - class: Dist::Zilla::Plugin::Git::Commit name: Git::Commit version: 2.013 - class: Dist::Zilla::Plugin::Git::Tag name: Git::Tag version: 2.013 - class: Dist::Zilla::Plugin::Git::Push name: Git::Push version: 2.013 - class: Dist::Zilla::Plugin::GatherDir name: '@Basic/GatherDir' version: 4.300034 - class: Dist::Zilla::Plugin::PruneCruft name: '@Basic/PruneCruft' version: 4.300034 - class: Dist::Zilla::Plugin::ManifestSkip name: '@Basic/ManifestSkip' version: 4.300034 - class: Dist::Zilla::Plugin::MetaYAML name: '@Basic/MetaYAML' version: 4.300034 - class: Dist::Zilla::Plugin::License name: '@Basic/License' version: 4.300034 - class: Dist::Zilla::Plugin::Readme name: '@Basic/Readme' version: 4.300034 - class: Dist::Zilla::Plugin::ExtraTests name: '@Basic/ExtraTests' version: 4.300034 - class: Dist::Zilla::Plugin::ExecDir name: '@Basic/ExecDir' version: 4.300034 - class: Dist::Zilla::Plugin::ShareDir name: '@Basic/ShareDir' version: 4.300034 - class: Dist::Zilla::Plugin::MakeMaker name: '@Basic/MakeMaker' version: 4.300034 - class: Dist::Zilla::Plugin::Manifest name: '@Basic/Manifest' version: 4.300034 - class: Dist::Zilla::Plugin::TestRelease name: '@Basic/TestRelease' version: 4.300034 - class: Dist::Zilla::Plugin::ConfirmRelease name: '@Basic/ConfirmRelease' version: 4.300034 - class: Dist::Zilla::Plugin::UploadToCPAN name: '@Basic/UploadToCPAN' version: 4.300034 - class: Dist::Zilla::Plugin::AssertOS name: AssertOS version: 0.04 - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: 4.300034 - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: 4.300034 - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: 4.300034 - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: 4.300034 - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: 4.300034 - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: 4.300034 zilla: class: Dist::Zilla::Dist::Builder config: is_trial: 0 version: 4.300034 x_authority: cpan:PERIGRIN x_contributors: - 'Ash Berlin ' - 'Brandon L Black ' - 'Chisel Wright ' - 'Dave Rolsky ' - 'Jonathan Sailor ' - 'Karen Etheridge ' - 'Michael Reddick ' - 'Michael Schwern ' - 'Stevan Little ' - 'Yuval Kogman ' MooseX-Daemonize-0.18/README000644 000767 000024 00000000477 12144240137 015727 0ustar00etherstaff000000 000000 This archive contains the distribution MooseX-Daemonize, version 0.18: Role for daemonizing your Moose based application This software is copyright (c) 2013 by Chris Prather. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. MooseX-Daemonize-0.18/t/000755 000767 000024 00000000000 12144240137 015302 5ustar00etherstaff000000 000000 MooseX-Daemonize-0.18/t/00.load.t000644 000767 000024 00000000242 12144240137 016622 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More tests => 1; BEGIN { use_ok( 'MooseX::Daemonize' ); } diag( "Testing MooseX::Daemonize $MooseX::Daemonize::VERSION" ); MooseX-Daemonize-0.18/t/01.filecreate.t000644 000767 000024 00000006124 12144240137 020014 0ustar00etherstaff000000 000000 use strict; use warnings; use File::Spec::Functions; use Test::More tests => 29; use Test::Moose; use File::Temp qw(tempdir); my $dir = tempdir( CLEANUP => 1 ); BEGIN { use_ok('MooseX::Daemonize'); } use constant DEBUG => 0; my $FILENAME = catfile($dir, "im_alive"); $ENV{MX_DAEMON_STDOUT} = catfile($dir, 'Out.txt'); $ENV{MX_DAEMON_STDERR} = catfile($dir, 'Err.txt'); { package FileMaker; use Moose; with qw(MooseX::Daemonize); has filename => ( isa => 'Str', is => 'ro' ); after start => sub { my $self = shift; if ($self->is_daemon) { $self->create_file( $self->filename ); } }; sub create_file { my ( $self, $file ) = @_; open( my $FILE, ">$file" ) || die $!; close($FILE); sleep 1 while 1; } } my $app = FileMaker->new( pidbase => "$dir/subdir", filename => $FILENAME, ); isa_ok($app, 'FileMaker'); does_ok($app, 'MooseX::Daemonize'); does_ok($app, 'MooseX::Daemonize::WithPidFile'); does_ok($app, 'MooseX::Daemonize::Core'); isa_ok($app->pidfile, 'MooseX::Daemonize::Pid::File'); is($app->pidfile->file, catfile("$dir/subdir", "filemaker.pid"), '... got the right PID file path'); ok(not(-e $app->pidfile->file), '... our pidfile does not exist'); ok(!$app->status, '... the daemon is running'); is($app->exit_code, MooseX::Daemonize->ERROR, '... got the right error code'); ok($app->stop, '... the app will stop cause its not running'); is($app->status_message, "Not running", '... got the correct status message'); is($app->exit_code, MooseX::Daemonize->OK, '... got the right error code'); diag $$ if DEBUG; ok($app->start, '... daemon started'); is($app->status_message, "Start succeeded", '... got the correct status message'); is($app->exit_code, MooseX::Daemonize->OK, '... got the right error code'); sleep(1); # give it a second ... ok(-e $app->pidfile->file, '... our pidfile exists' ); my $pid = $app->pidfile->pid; isnt($pid, $$, '... the pid in our pidfile is correct (and not us)'); ok($app->status, '... the daemon is running'); is($app->status_message, "Daemon is running with pid ($pid)", '... got the correct status message'); is($app->exit_code, MooseX::Daemonize->OK, '... got the right error code'); if (DEBUG) { diag `ps $pid`; diag "Status is: " . $app->status_message; } ok( -e $app->filename, "file exists" ); if (DEBUG) { diag `ps $pid`; diag "Status is: " . $app->status_message; } ok( $app->stop, '... app stopped' ); is($app->status_message, "Stop succeeded", '... got the correct status message'); is($app->exit_code, MooseX::Daemonize->OK, '... got the right error code'); ok(!$app->status, '... the daemon is no longer running'); is($app->status_message, "Daemon is not running with pid ($pid)", '... got the correct status message'); is($app->exit_code, MooseX::Daemonize->ERROR, '... got the right error code'); if (DEBUG) { diag `ps $pid`; diag "Status is: " . $app->status_message; } ok( not(-e $app->pidfile->file) , '... pidfile gone' ); unlink $FILENAME; unlink $ENV{MX_DAEMON_STDOUT}; unlink $ENV{MX_DAEMON_STDERR}; MooseX-Daemonize-0.18/t/02.stdout.t000644 000767 000024 00000002335 12144240137 017234 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; use Test::Builder; use Test::MooseX::Daemonize; use MooseX::Daemonize; my $Test = Test::Builder->new; { package TestOutput; use Moose; with qw(MooseX::Daemonize); with qw(Test::MooseX::Daemonize::Testable); # setup our test environment after start => sub { my ($self) = @_; $self->output_ok() if $self->is_daemon; }; sub output_ok { my ($self) = @_; my $count = 1; for ( 0 .. 3 ) { $Test->ok( $count++, "$count output_ok" ); sleep(1); } } no Moose; } package main; use strict; use warnings; use File::Spec::Functions; use File::Temp qw(tempdir); my $dir = tempdir( CLEANUP => 1 ); ## Try to make sure we are in the test directory my $app = TestOutput->new( pidbase => $dir, test_output => catfile($dir, 'results'), ); daemonize_ok( $app, 'child forked okay' ); sleep(3); # give ourself a chance to produce some output my $warnings = ""; { local $SIG{__WARN__} = sub { $warnings .= $_[0]; warn @_ }; $app->stop( no_exit => 1 ); } is($warnings, "", "No warnings from stop"); check_test_output($app); unlink( $app->test_output ); done_testing; exit; MooseX-Daemonize-0.18/t/10.pidfile.t000644 000767 000024 00000004163 12144240137 017326 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More tests => 25; use Test::Fatal; BEGIN { use_ok('MooseX::Daemonize::Pid::File'); } { my $f = MooseX::Daemonize::Pid::File->new( file => [ 't', 'foo.pid' ] ); isa_ok($f, 'MooseX::Daemonize::Pid::File'); isa_ok($f->file, 'Path::Class::File'); is($f->pid, $$, '... the PID is our current process'); is( exception { $f->write }, undef, '... writing the PID file', ); is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct'); ok($f->is_running, '... it is running too'); is( exception { $f->remove }, undef, '... removing the PID file', ); ok(!-e $f->file, '... the PID file does not exist anymore'); } { my $f = MooseX::Daemonize::Pid::File->new( file => [ 't', 'bar.pid' ] ); isa_ok($f, 'MooseX::Daemonize::Pid::File'); isa_ok($f->file, 'Path::Class::File'); is( exception { $f->write }, undef, '... writing the PID file', ); is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct'); is($f->pid, $$, '... the PID is our current process'); ok($f->is_running, '... it is running too'); is( exception { $f->remove }, undef, '... removing the PID file', ); ok(!-e $f->file, '... the PID file does not exist anymore'); } { my $PID = 9999; my $f = MooseX::Daemonize::Pid::File->new( file => [ 't', 'baz.pid' ], pid => $PID, ); isa_ok($f, 'MooseX::Daemonize::Pid::File'); isa_ok($f->file, 'Path::Class::File'); is($f->pid, $PID, '... the PID is our made up PID'); is( exception { $f->write }, undef, '... writing the PID file', ); is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct'); ok(!$f->is_running, '... it is not running (cause we made the PID up)'); is( exception { $f->remove }, undef, '... removing the PID file', ); ok(!-e $f->file, '... the PID file does not exist anymore'); } MooseX-Daemonize-0.18/t/20.core.t000644 000767 000024 00000004467 12144240137 016652 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; use Test::Fatal; use Test::Moose; use File::Temp qw(tempdir); use File::Spec::Functions; my $dir = tempdir( CLEANUP => 1 ); BEGIN { use_ok('MooseX::Daemonize::Core'); use_ok('MooseX::Daemonize::Pid'); } use constant DEBUG => 0; $ENV{MX_DAEMON_STDOUT} = catfile($dir, 'Out.txt'); $ENV{MX_DAEMON_STDERR} = catfile($dir, 'Err.txt'); { package MyFooDaemon; use Moose; with 'MooseX::Daemonize::Core'; has 'daemon_pid' => (is => 'rw', isa => 'MooseX::Daemonize::Pid'); # capture the PID from the fork around 'daemon_fork' => sub { my $next = shift; my $self = shift; if (my $pid = $self->$next(@_)) { $self->daemon_pid( MooseX::Daemonize::Pid->new(pid => $pid) ); } }; sub start { my $self = shift; # tell it to ignore zombies ... $self->ignore_zombies( 1 ); $self->no_double_fork( 1 ); $self->daemonize; return unless $self->is_daemon; # change to our local dir # so that we can debug easier chdir $dir; # make it easy to find with ps $0 = 'test-app'; $SIG{INT} = sub { print "Got INT! Oh Noes!"; exit; }; while (1) { print "Hello from $$\n"; sleep(10); } exit; } } my $d = MyFooDaemon->new; isa_ok($d, 'MyFooDaemon'); does_ok($d, 'MooseX::Daemonize::Core'); is( exception { $d->start }, undef, '... successfully daemonized from (' . $$ . ')', ); my $p = $d->daemon_pid; isa_ok($p, 'MooseX::Daemonize::Pid'); ok($p->is_running, '... the daemon process is running (' . $p->pid . ')'); my $pid = $p->pid; if (DEBUG) { diag `ps $pid`; diag "-------"; diag `ps -x | grep test-app`; diag "-------"; diag "killing $pid"; } kill INT => $p->pid; diag "killed $pid" if DEBUG; # give the process time to be killed on slow/loaded systems for (1..10) { last unless kill 0 => $pid; # sleep a little before retrying sleep(2); } if (DEBUG) { diag `ps $pid`; diag "-------"; diag `ps -x | grep test-app`; } ok(!$p->is_running, '... the daemon process is no longer running (' . $p->pid . ')'); unlink $ENV{MX_DAEMON_STDOUT}; unlink $ENV{MX_DAEMON_STDERR}; done_testing; MooseX-Daemonize-0.18/t/21.core-back-compat.t000644 000767 000024 00000004474 12144240137 021030 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; use Test::Fatal; use Test::Moose; use File::Temp qw(tempdir); use File::Spec::Functions; my $dir = tempdir( CLEANUP => 1 ); BEGIN { use_ok('MooseX::Daemonize::Core'); use_ok('MooseX::Daemonize::Pid'); } use constant DEBUG => 0; $ENV{MX_DAEMON_STDOUT} = catfile($dir, 'Out.txt'); $ENV{MX_DAEMON_STDERR} = catfile($dir, 'Err.txt'); { package MyFooDaemon; use Moose; with 'MooseX::Daemonize::Core'; has 'daemon_pid' => (is => 'rw', isa => 'MooseX::Daemonize::Pid'); # capture the PID from the fork around 'daemon_fork' => sub { my $next = shift; my $self = shift; if (my $pid = $self->$next(@_)) { $self->daemon_pid( MooseX::Daemonize::Pid->new(pid => $pid) ); } }; sub start { my $self = shift; # tell it to ignore zombies ... $self->daemonize( ignore_zombies => 1, no_double_fork => 1, ); return unless $self->is_daemon; # change to our local dir # so that we can debug easier chdir $dir; # make it easy to find with ps $0 = 'test-app'; $SIG{INT} = sub { print "Got INT! Oh Noes!"; exit; }; while (1) { print "Hello from $$\n"; sleep(10); } exit; } } my $d = MyFooDaemon->new; isa_ok($d, 'MyFooDaemon'); does_ok($d, 'MooseX::Daemonize::Core'); is( exception { $d->start }, undef, '... successfully daemonized from (' . $$ . ')', ); my $p = $d->daemon_pid; isa_ok($p, 'MooseX::Daemonize::Pid'); ok($p->is_running, '... the daemon process is running (' . $p->pid . ')'); my $pid = $p->pid; if (DEBUG) { diag `ps $pid`; diag "-------"; diag `ps -x | grep test-app`; diag "-------"; diag "killing $pid"; } kill INT => $p->pid; diag "killed $pid" if DEBUG; # give the process time to be killed on slow/loaded systems for (1..10) { last unless kill 0 => $pid; # sleep a little before retrying sleep(2); } if (DEBUG) { diag `ps $pid`; diag "-------"; diag `ps -x | grep test-app`; } ok(!$p->is_running, '... the daemon process is no longer running (' . $p->pid . ')'); unlink $ENV{MX_DAEMON_STDOUT}; unlink $ENV{MX_DAEMON_STDERR}; done_testing; MooseX-Daemonize-0.18/t/30.with_pid_file.t000644 000767 000024 00000005025 12144240137 020520 0ustar00etherstaff000000 000000 use strict; use warnings; use File::Spec::Functions; use Test::More; use Test::Fatal; use Test::Moose; use File::Temp qw(tempdir); my $dir = tempdir( CLEANUP => 1 ); BEGIN { use_ok('MooseX::Daemonize::Core'); } use constant DEBUG => 0; my $PIDFILE = catfile($dir, 'test-app.pid'); $ENV{MX_DAEMON_STDOUT} = catfile($dir, 'Out.txt'); $ENV{MX_DAEMON_STDERR} = catfile($dir, 'Err.txt'); { package MyFooDaemon; use Moose; with 'MooseX::Daemonize::WithPidFile'; sub init_pidfile { MooseX::Daemonize::Pid::File->new( file => $PIDFILE ) } sub start { my $self = shift; # this tests our bad PID # cleanup functionality. print "Our parent PID is " . $self->pidfile->pid . "\n" if ::DEBUG; $self->daemonize; return unless $self->is_daemon; # make it easy to find with ps $0 = 'test-app-2'; $SIG{INT} = sub { print "Got INT! Oh Noes!"; $self->pidfile->remove; exit; }; while (1) { print "Hello from $$\n"; sleep(10); } exit; } } my $d = MyFooDaemon->new( pidfile => $PIDFILE ); isa_ok($d, 'MyFooDaemon'); does_ok($d, 'MooseX::Daemonize::Core'); does_ok($d, 'MooseX::Daemonize::WithPidFile'); ok($d->has_pidfile, '... we have a pidfile value'); { my $p = $d->pidfile; isa_ok($p, 'MooseX::Daemonize::Pid::File'); #diag $p->dump; } ok(!(-e $PIDFILE), '... the PID file does not exist yet'); is( exception { $d->start }, undef, '... successfully daemonized from (' . $$ . ')', ); my $p = $d->pidfile; isa_ok($p, 'MooseX::Daemonize::Pid::File'); #diag $p->dump; sleep(2); ok($p->does_file_exist, '... the PID file exists'); ok($p->is_running, '... the daemon process is running (' . $p->pid . ')'); my $pid = $p->pid; if (DEBUG) { diag `ps $pid`; diag "-------"; diag `ps -x | grep test-app`; diag "-------"; diag "killing $pid"; } kill INT => $p->pid; diag "killed $pid" if DEBUG; # give the process time to be killed on slow/loaded systems for (1..10) { last unless kill 0 => $pid; # sleep a little before retrying sleep(2); } if (DEBUG) { diag `ps $pid`; diag "-------"; diag `ps -x | grep test-app`; } ok(!$p->is_running, '... the daemon process is no longer running (' . $p->pid . ')'); ok(!(-e $PIDFILE), '... the PID file has been removed'); unlink $ENV{MX_DAEMON_STDOUT}; unlink $ENV{MX_DAEMON_STDERR}; done_testing; MooseX-Daemonize-0.18/lib/MooseX/000755 000767 000024 00000000000 12144240137 017017 5ustar00etherstaff000000 000000 MooseX-Daemonize-0.18/lib/Test/000755 000767 000024 00000000000 12144240137 016524 5ustar00etherstaff000000 000000 MooseX-Daemonize-0.18/lib/Test/MooseX/000755 000767 000024 00000000000 12144240137 017736 5ustar00etherstaff000000 000000 MooseX-Daemonize-0.18/lib/Test/MooseX/Daemonize.pm000644 000767 000024 00000012466 12144240137 022220 0ustar00etherstaff000000 000000 package Test::MooseX::Daemonize; { $Test::MooseX::Daemonize::VERSION = '0.18'; } use strict; our $AUTHORITY = 'cpan:PERIGRIN'; # BEGIN CARGO CULTING use Sub::Exporter; use Test::Builder; { my @exports = qw[ daemonize_ok check_test_output ]; Sub::Exporter::setup_exporter( { exports => \@exports, groups => { default => \@exports } } ); } our $Test = Test::Builder->new; sub daemonize_ok { my ( $daemon, $msg ) = @_; unless ( my $pid = fork ) { $daemon->start(); exit; } else { sleep(1); # Punt on sleep time, 1 seconds should be enough $Test->ok( $daemon->pidfile->does_file_exist, $msg ) || $Test->diag( 'Pidfile (' . $daemon->pidfile->file . ') not found.' ); } } sub check_test_output { my ($app) = @_; open( my $stdout_in, '<', $app->test_output ) or die "can't open test output: $!"; while ( my $line = <$stdout_in> ) { $line =~ s/\s+\z//; my $label; if ( $line =~ /\A((not\s+)?ok)(?:\s+-)(?:\s+(.*))\z/ ) { my ( $status, $not, $text ) = ( $1, $2, $3 ); $text ||= ''; # We don't just call ok(!$not), because that generates diagnostics of # its own for failures. We only want the diagnostics from the child. my $orig_no_diag = $Test->no_diag; $Test->no_diag(1); $Test->ok(!$not, $text); $Test->no_diag($orig_no_diag); } elsif ( $line =~ s/\A#\s?// ) { $Test->diag($line); } else { $Test->diag("$label: $line (unrecognised)\n"); } } } package Test::MooseX::Daemonize::Testable; { $Test::MooseX::Daemonize::Testable::VERSION = '0.18'; } use Moose::Role; has test_output => ( isa => 'Str', is => 'ro', required => 1, ); after daemonize => sub { $Test->use_numbers(0); $Test->no_ending(1); open my $out, '>', $_[0]->test_output or die "Cannot open test output: $!"; my $fileno = fileno $out; open STDERR, ">&=", $fileno or die "Can't redirect STDERR"; open STDOUT, ">&=", $fileno or die "Can't redirect STDOUT"; $Test->output($out); $Test->failure_output($out); $Test->todo_output($out); }; 1; __END__ =pod =head1 NAME Test::MooseX::Daemonize - Tool to help test MooseX::Daemonize applications =head1 SYNOPSIS use File::Spec::Functions; use File::Temp qw(tempdir); my $dir = tempdir( CLEANUP => 1 ); ## Try to make sure we are in the test directory my $file = catfile( $dir, "im_alive" ); my $daemon = FileMaker->new( pidbase => $dir, filename => $file ); daemonize_ok( $daemon, 'child forked okay' ); ok( -e $file, "$file exists" ); =head1 DESCRIPTION This module provides some basic Test::Builder compatible test methods to use when writing tests for you MooseX::Daemonize based modules. =head1 EXPORTED FUNCTIONS =over 4 =item B This will attempt to daemonize your C<$daemon> returning ok on success and not ok on failure. =item B This is expected to be used with a C<$daemon> which does the B role (included in this package see the source for more info). It will collect the test output from your daemon and apply it in the parent process by mucking around with L stuff, again, read the source for more info. If we get time we will document this more thoroughly. =back =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to C, or through the web interface at L. =head1 SEE ALSO L =head1 AUTHOR Chris Prather C<< >> =head1 LICENCE AND COPYRIGHT Copyright (c) 2007-2011, Chris Prather C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. =cut MooseX-Daemonize-0.18/lib/MooseX/Daemonize/000755 000767 000024 00000000000 12144240137 020732 5ustar00etherstaff000000 000000 MooseX-Daemonize-0.18/lib/MooseX/Daemonize.pm000644 000767 000024 00000036267 12144240137 021306 0ustar00etherstaff000000 000000 package MooseX::Daemonize; { $MooseX::Daemonize::VERSION = '0.18'; } BEGIN { $MooseX::Daemonize::AUTHORITY = 'cpan:PERIGRIN'; } use strict; # because Kwalitee is pedantic use Moose::Role; use MooseX::Types::Path::Class; use File::Path qw(make_path); with 'MooseX::Daemonize::WithPidFile', 'MooseX::Getopt'; sub OK () { 0 } sub ERROR () { 1 } has progname => ( metaclass => 'Getopt', isa => 'Str', is => 'ro', lazy => 1, required => 1, default => sub { ( my $name = lc $_[0]->meta->name ) =~ s/::/_/g; return $name; }, documentation => 'the name of the daemon', ); has pidbase => ( metaclass => 'Getopt', isa => 'Path::Class::Dir', is => 'ro', coerce => 1, required => 1, lazy => 1, default => sub { Path::Class::Dir->new('', 'var', 'run') }, documentation => 'the base for our pid (default: /var/run)', ); has basedir => ( metaclass => 'Getopt', isa => 'Path::Class::Dir', is => 'ro', coerce => 1, required => 1, lazy => 1, default => sub { Path::Class::Dir->new('/') }, documentation => 'the directory to chdir to (default: /)', ); has foreground => ( metaclass => 'Getopt', cmd_aliases => 'f', isa => 'Bool', is => 'ro', default => sub { 0 }, documentation => 'if true, the process won\'t background', ); has stop_timeout => ( metaclass => 'Getopt', isa => 'Int', is => 'rw', default => sub { 2 }, documentation => 'number of seconds to wait for the process to stop, before trying harder to kill it (default: 2 s)', ); # internal book-keeping has status_message => ( metaclass => 'NoGetopt', isa => 'Str', is => 'rw', clearer => 'clear_status_message', ); has exit_code => ( metaclass => 'NoGetopt', isa => 'Int', is => 'rw', clearer => 'clear_exit_code', ); # methods ... ## PID file related stuff ... sub init_pidfile { my $self = shift; my $file = $self->pidbase . '/' . $self->progname . '.pid'; if ( !-d $self->pidbase ) { make_path( $self->pidbase, { error => \my $err } ); if (@$err) { confess sprintf( "Cannot create pidbase directory '%s': %s", $self->pidbase, @$err ); } } confess "Cannot write to $file" unless (-e $file ? -w $file : -w $self->pidbase); MooseX::Daemonize::Pid::File->new( file => $file ); } # backwards compat, sub check { (shift)->pidfile->is_running } sub save_pid { (shift)->pidfile->write } sub remove_pid { (shift)->pidfile->remove } sub get_pid { (shift)->pidfile->pid } ## signal handling ... sub setup_signals { my $self = shift; $SIG{'INT'} = sub { $self->shutdown }; # I can't think of a sane default here really ... # $SIG{'HUP'} = sub { $self->handle_sighup }; } sub shutdown { my $self = shift; $self->pidfile->remove if $self->pidfile->pid == $$; exit(0); } ## daemon control methods ... sub start { my $self = shift; $self->clear_status_message; $self->clear_exit_code; if ($self->pidfile->is_running) { $self->exit_code($self->OK); $self->status_message('Daemon is already running with pid (' . $self->pidfile->pid . ')'); return !($self->exit_code); } if ($self->foreground) { $self->is_daemon(1); } else { eval { $self->daemonize }; if ($@) { $self->exit_code($self->ERROR); $self->status_message('Start failed : ' . $@); return !($self->exit_code); } } unless ($self->is_daemon) { $self->exit_code($self->OK); $self->status_message('Start succeeded'); return !($self->exit_code); } $self->pidfile->pid($$); # Change to basedir chdir $self->basedir; $self->pidfile->write; $self->setup_signals; return $$; } sub status { my $self = shift; $self->clear_status_message; $self->clear_exit_code; if ($self->pidfile->is_running) { $self->exit_code($self->OK); $self->status_message('Daemon is running with pid (' . $self->pidfile->pid . ')'); } else { $self->exit_code($self->ERROR); $self->status_message('Daemon is not running with pid (' . $self->pidfile->pid . ')'); } return !($self->exit_code); } sub restart { my $self = shift; $self->clear_status_message; $self->clear_exit_code; unless ($self->stop) { $self->exit_code($self->ERROR); $self->status_message('Restart (Stop) failed : ' . $@); } unless ($self->start) { $self->exit_code($self->ERROR); $self->status_message('Restart (Start) failed : ' . $@); } if ($self->exit_code == $self->OK) { $self->exit_code($self->OK); $self->status_message("Restart successful"); } return !($self->exit_code); } # Make _kill *really* private my $_kill; sub stop { my $self = shift; $self->clear_status_message; $self->clear_exit_code; # if the pid is not running # then we dont need to stop # anything ... if ($self->pidfile->is_running) { # if we are foreground, then # no need to try and kill # ourselves unless ($self->foreground) { # kill the process ... eval { $self->$_kill($self->pidfile->pid) }; # and complain if we can't ... if ($@) { $self->exit_code($self->ERROR); $self->status_message('Stop failed : ' . $@); } # or gloat if we succeed .. else { $self->exit_code($self->OK); $self->status_message('Stop succeeded'); } } } else { # this just returns the OK # exit code for now, but # we should make this overridable $self->exit_code($self->OK); $self->status_message("Not running"); } # if we are returning to our script # then we actually need the opposite # of what the system/OS expects return !($self->exit_code); } $_kill = sub { my ( $self, $pid ) = @_; return unless $pid; unless ( CORE::kill 0 => $pid ) { # warn "$pid already appears dead."; return; } if ( $pid eq $$ ) { die "$pid is us! Can't commit suicide."; } my $timeout = $self->stop_timeout; # kill 0 => $pid returns 0 if the process is dead # $!{EPERM} could also be true if we cant kill it (permission error) # Try SIGINT ... 2s ... SIGTERM ... 2s ... SIGKILL ... 3s ... UNDEAD! my $terminating_signal; for ( [ 2, $timeout ], [15, $timeout], [9, $timeout * 1.5] ) { my ($signal, $timeout) = @$_; $timeout = int $timeout; CORE::kill($signal, $pid); while ($timeout) { unless(CORE::kill 0 => $pid or $!{EPERM}) { $terminating_signal = $signal; last; } $timeout--; sleep(1) if $timeout; } last if $terminating_signal; } if($terminating_signal) { if($terminating_signal == 9) { # clean up the pidfile ourselves iff we used -9 and it worked warn "Had to resort to 'kill -9' and it worked, wiping pidfile"; eval { $self->pidfile->remove }; if ($@) { warn "Could not remove pidfile (" . $self->pidfile->file . ") because : $!"; } } return; } # IF it is still running Carp::carp "$pid doesn't seem to want to die."; # AHH EVIL DEAD! }; 1; __END__ =pod =head1 NAME MooseX::Daemonize - Role for daemonizing your Moose based application =head1 WARNING The maintainers of this module now recommend using L instead. =head1 SYNOPSIS package My::Daemon; use Moose; with qw(MooseX::Daemonize); # ... define your class .... after start => sub { my $self = shift; return unless $self->is_daemon; # your daemon code here ... }; # then in your script ... my $daemon = My::Daemon->new_with_options(); my ($command) = @{$daemon->extra_argv} defined $command || die "No command specified"; $daemon->start if $command eq 'start'; $daemon->status if $command eq 'status'; $daemon->restart if $command eq 'restart'; $daemon->stop if $command eq 'stop'; warn($daemon->status_message); exit($daemon->exit_code); =head1 DESCRIPTION Often you want to write a persistant daemon that has a pid file, and responds appropriately to Signals. This module provides a set of basic roles as an infrastructure to do that. =head1 CAVEATS When going into background MooseX::Daemonize closes all open file handles. This may interfere with you logging because it may also close the log file handle you want to write to. To prevent this you can either defer opening the log file until after start. Alternatively, use can use the 'dont_close_all_files' option either from the command line or in your .sh script. Assuming you want to use Log::Log4perl for example you could expand the MooseX::Daemonize example above like this. after start => sub { my $self = shift; return unless $self->is_daemon; Log::Log4perl->init(\$log4perl_config); my $logger = Log::Log4perl->get_logger(); $logger->info("Daemon started"); # your daemon code here ... }; =head1 ATTRIBUTES This list includes attributes brought in from other roles as well we include them here for ease of documentation. All of these attributes are settable though L's command line handling, with the exception of C. =over =item I The name of our daemon, defaults to C<$package_name =~ s/::/_/>; =item I The base for our PID, defaults to C =item I The directory we chdir to; defaults to C. =item I The file we store our PID in, defaults to C<$pidbase/$progname.pid> =item I If true, the process won't background. Useful for debugging. This option can be set via Getopt's -f. =item I If true, the process will not perform the typical double-fork, which is extra added protection from your process accidentally aquiring a controlling terminal. More information can be found by Googling "double fork daemonize". =item I If true, the process will not clean up zombie processes. Normally you don't want this. =item I If true, the objects open filehandles will not be closed when daemonized. Normally you don't want this. =item I If true, the process is the backgrounded daemon process, if false it is the parent process. This is useful for example in an C sub { }> block. B This option is explicitly B available through L. =item I Number of seconds to wait for the process to stop, before trying harder to kill it. Defaults to 2 seconds. =back These are the internal attributes, which are not available through MooseX::Getopt. =over 4 =item I =item I =back =head1 METHODS =head2 Daemon Control Methods These methods can be used to control the daemon behavior. Every effort has been made to have these methods DWIM (Do What I Mean), so that you can focus on just writing the code for your daemon. Extending these methods is best done with the L method modifiers, such as C, C and C. =over 4 =item B Setup a pidfile, fork, then setup the signal handlers. =item B Stop the process matching the pidfile, and unlinks the pidfile. =item B Literally this is: $self->stop(); $self->start(); =item B =item B =back =head2 Pidfile Handling Methods =over 4 =item B This method will create a L object and tell it to store the PID in the file C<$pidbase/$progname.pid>. =item B This checks to see if the daemon process is currently running by checking the pidfile. =item B Returns the PID of the daemon process. =item B Write the pidfile. =item B Removes the pidfile. =back =head2 Signal Handling Methods =over 4 =item B Setup the signal handlers, by default it only sets up handlers for SIGINT and SIGHUP. If you wish to add more signals just use the C method modifier and add them. =item B Handle a INT signal, by default calls C<$self->stop()> =item B Handle a HUP signal. By default calls C<$self->restart()> =back =head2 Exit Code Methods These are overriable constant methods used for setting the exit code. =over 4 =item OK Returns 0. =item ERROR Returns 1. =back =head2 Introspection =over 4 =item meta() The C method from L =back =head1 DEPENDENCIES L, L, L and L =head1 INCOMPATIBILITIES None reported. Although obviously this will not work on Windows. =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to C, or through the web interface at L. =head1 SEE ALSO L, L, L =head1 AUTHORS Chris Prather C<< > Stevan Little C<< >> =head1 THANKS Mike Boyko, Matt S. Trout, Stevan Little, Brandon Black, Ash Berlin and the #moose denzians Some bug fixes sponsored by Takkle Inc. =head1 LICENCE AND COPYRIGHT Copyright (c) 2007-2011, Chris Prather C<< >>. Some rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. =cut MooseX-Daemonize-0.18/lib/MooseX/Daemonize/Core.pm000644 000767 000024 00000027051 12144240137 022165 0ustar00etherstaff000000 000000 package MooseX::Daemonize::Core; { $MooseX::Daemonize::Core::VERSION = '0.18'; } BEGIN { $MooseX::Daemonize::Core::AUTHORITY = 'cpan:PERIGRIN'; } use strict; # cause Perl::Critic errors are annoying use MooseX::Getopt; # to load the NoGetopt metaclass use Moose::Role; use POSIX (); has is_daemon => ( # NOTE: # this should never be accessible # from the command line # - SL metaclass => 'NoGetopt', isa => 'Bool', is => 'rw', default => sub { 0 }, ); has ignore_zombies => ( metaclass => 'Getopt', isa => 'Bool', is => 'rw', default => sub { 0 }, ); has no_double_fork => ( metaclass => 'Getopt', isa => 'Bool', is => 'rw', default => sub { 0 }, ); has dont_close_all_files => ( metaclass => 'Getopt', isa => 'Bool', is => 'rw', default => sub { 0 }, ); sub _get_options { my ($self, %options) = @_; # backwards compability.. old code might be calling daemon_fork/_detach with options foreach my $opt (qw( ignore_zombies no_double_fork dont_close_all_files )) { $self->$opt( $options{ $opt } ) if ( defined $options{ $opt } ); } } sub daemon_fork { my ($self, %options) = @_; $self->_get_options( %options ); $SIG{CHLD} = 'IGNORE' if $self->ignore_zombies;; if (my $pid = fork) { return $pid; } else { $self->is_daemon(1); return; } } sub daemon_detach { my ($self, %options) = @_; return unless $self->is_daemon; # return if parent ... $self->_get_options( %options ); # now we are in the daemon ... (POSIX::setsid) # set session id || confess "Cannot detach from controlling process"; unless ( $self->no_double_fork ) { $SIG{'HUP'} = 'IGNORE'; fork && exit; } chdir '/'; # change to root directory umask 0; # clear the file creation mask unless ( $self->dont_close_all_files ) { # get the max numnber of possible file descriptors my $openmax = POSIX::sysconf( &POSIX::_SC_OPEN_MAX ); $openmax = 64 if !defined($openmax) || $openmax < 0; # close them all POSIX::close($_) foreach (0 .. $openmax); } # fixup STDIN ... open(STDIN, "+>/dev/null") or confess "Could not redirect STDOUT to /dev/null"; # fixup STDOUT ... if (my $stdout_file = $ENV{MX_DAEMON_STDOUT}) { open STDOUT, ">", $stdout_file or confess "Could not redirect STDOUT to $stdout_file : $!"; } else { open(STDOUT, "+>&STDIN") or confess "Could not redirect STDOUT to /dev/null"; } # fixup STDERR ... if (my $stderr_file = $ENV{MX_DAEMON_STDERR}) { open STDERR, ">", $stderr_file or confess "Could not redirect STDERR to $stderr_file : $!"; } else { open(STDERR, "+>&STDIN") or confess "Could not redirect STDERR to /dev/null"; ; } # do a little house cleaning ... # Avoid 'stdin reopened for output' # warning with newer perls open( NULL, '/dev/null' ); if (0); # return success return 1; } sub daemonize { my ($self, %options) = @_; $self->daemon_fork(%options); $self->daemon_detach(%options); } 1; __END__ =pod =head1 NAME MooseX::Daemonize::Core - A Role with the core daemonization features =head1 SYNOPSIS package My::Daemon; use Moose; with 'MooseX::Daemonize::Core'; sub start { my $self = shift; # daemonize me ... $self->daemonize; # return from the parent,... return unless $self->is_daemon; # but continue on in the child (daemon) } =head1 DESCRIPTION This is the basic daemonization Role, it provides a few methods (see below) and the minimum features needed to properly daemonize your code. =head2 Important Notes None of the methods in this role will exit the parent process for you, it only forks and detaches your child (daemon) process. It is your responsibility to exit the parent process in some way. There is no PID or PID file management in this role, that is your responsibility (see some of the other roles in this distro for that). =head1 ATTRIBUTES =over =item I rw, isa => Bool)> This attribute is used to signal if we are within the daemon process or not. =item I rw, isa => Bool)> Setting this attribute to true will cause this method to not perform the typical double-fork, which is extra added protection from your process accidentally aquiring a controlling terminal. More information can be found above, and by Googling "double fork daemonize". If you the double-fork behavior off, you might want to enable the I. =item I rw, isa => Bool)> Setting this attribute to a true value will result in setting the C<$SIG{CHLD}> handler to C. This tells perl to clean up zombie processes. By default, and for the most part you don't I it, only when you turn off the double fork behavior (with the I attribute) do you sometimes want this behavior. =item I rw, isa => Bool)> Setting this attribute to true will cause it to skip closing all the filehandles. This is useful if you are opening things like sockets and such in the pre-fork. =back =head1 METHODS =over =item B This forks off the child process to be daemonized. Just as with the built in fork, it returns the child pid to the parent process, 0 to the child process. It will also set the is_daemon flag appropriately. The C<%options> argument remains for backwards compatability, but it is suggested that you use the attributes listed above instead. =item B This detaches the new child process from the terminal by doing the following things. The C<%options> argument remains for backwards compatability, but it is suggested that you use the attributes listed above instead. =over 4 =item Becomes a session leader This detaches the program from the controlling terminal, it is accomplished by calling POSIX::setsid. =item Performing the double-fork See below for information on how to change this part of the process. =item Changes the current working directory to "/" This is standard daemon behavior, if you want a different working directory then simply change it later in your daemons code. =item Clears the file creation mask. =item Closes all open file descriptors. See the I attribute for information on how to change this part of the process. =item Reopen STDERR, STDOUT & STDIN to /dev/null This behavior can be controlled slightly though the MX_DAEMON_STDERR and MX_DAEMON_STDOUT environment variables. It will look for a filename in either of these variables and redirect STDOUT and/or STDERR to those files. This is useful for debugging and/or testing purposes. B If called from within the parent process (the is_daemon flag is set to false), this method will simply return and do nothing. =item B This will simply call C followed by C. The C<%options> argument remains for backwards compatability, but it is suggested that you use the attributes listed above instead. =item meta() The C method from L =back =back =head1 STUFF YOU SHOULD READ =over 4 =item Note about double fork Taken from L in a comment entitled I, it is not the definitive statement on the issue, but it's clear and well written enough so I decided to reproduce it here. The first fork accomplishes two things - allow the shell to return, and allow you to do a setsid(). The setsid() removes yourself from your controlling terminal. You see, before, you were still listed as a job of your previous process, and therefore the user might accidentally send you a signal. setsid() gives you a new session, and removes the existing controlling terminal. The problem is, you are now a session leader. As a session leader, if you open a file descriptor that is a terminal, it will become your controlling terminal (oops!). Therefore, the second fork makes you NOT be a session leader. Only session leaders can acquire a controlling terminal, so you can open up any file you wish without worrying that it will make you a controlling terminal. So - first fork - allow shell to return, and permit you to call setsid() Second fork - prevent you from accidentally reacquiring a controlling terminal. That said, you don't always want this to be the behavior, so you are free to specify otherwise using the I attribute. =item Note about zombies Doing the double fork (see above) tends to get rid of your zombies since by the time you have double forked your daemon process is then owned by the init process. However, sometimes the double-fork is more than you really need, and you want to keep your daemon processes a little closer to you. In this case you have to watch out for zombies, you can avoid then by just setting the I attribute (see above). =back =head1 ENVIRONMENT VARIABLES These variables are best just used for debugging and/or testing, but not used for actual logging. For that, you should reopen STDOUT/ERR on your own. =over 4 =item B A filename to redirect the daemon STDOUT to. =item B A filename to redirect the daemon STDERR to. =back =head1 DEPENDENCIES L, L =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to C, or through the web interface at L. =head1 SEE ALSO L This code is based B on L, we originally depended on it, but we needed some more flexibility, so instead we just stole the code. =head1 AUTHOR Stevan Little C<< >> =head1 LICENCE AND COPYRIGHT Copyright (c) 2007-2011, Chris Prather C<< >>. All rights reserved. Portions heavily borrowed from L which is copyright Earl Hood. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. =cut MooseX-Daemonize-0.18/lib/MooseX/Daemonize/Pid/000755 000767 000024 00000000000 12144240137 021446 5ustar00etherstaff000000 000000 MooseX-Daemonize-0.18/lib/MooseX/Daemonize/Pid.pm000644 000767 000024 00000006172 12144240137 022012 0ustar00etherstaff000000 000000 package MooseX::Daemonize::Pid; { $MooseX::Daemonize::Pid::VERSION = '0.18'; } BEGIN { $MooseX::Daemonize::Pid::AUTHORITY = 'cpan:PERIGRIN'; } use strict; # because Kwalitee is pedantic use Moose; use Moose::Util::TypeConstraints; coerce 'MooseX::Daemonize::Pid' => from 'Int' => via { MooseX::Daemonize::Pid->new( pid => $_ ) }; has 'pid' => ( is => 'rw', isa => 'Int', lazy => 1, clearer => 'clear_pid', predicate => 'has_pid', default => sub { $$ } ); sub is_running { kill(0, (shift)->pid) ? 1 : 0 } 1; __END__ =pod =head1 NAME MooseX::Daemonize::Pid - PID management for MooseX::Daemonize =head1 DESCRIPTION This is a very basic Pid management object, it doesn't do all that much, and mostly just serves as a base class for L. =head1 ATTRIBUTES =over 4 =item I =back =head1 METHODS =over 4 =item B This will clear the value of the I attribute. It is useful for making sure that the parent process does not have a bad value stored in it. =item B This is a predicate method to tell you if your I attribute has been initialized yet. =item B This checks to see if the I is running. =item meta() The C method from L =back =head1 DEPENDENCIES Obviously L =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to C, or through the web interface at L. =head1 AUTHOR Stevan Little C<< >> =head1 LICENCE AND COPYRIGHT Copyright (c) 2007-2011, Chris Prather C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. =cut MooseX-Daemonize-0.18/lib/MooseX/Daemonize/WithPidFile.pm000644 000767 000024 00000010563 12144240137 023445 0ustar00etherstaff000000 000000 package MooseX::Daemonize::WithPidFile; { $MooseX::Daemonize::WithPidFile::VERSION = '0.18'; } BEGIN { $MooseX::Daemonize::WithPidFile::AUTHORITY = 'cpan:PERIGRIN'; } use strict; # cause Perl::Critic errors are annoying use MooseX::Getopt; # to load the Getopt metaclass use Moose::Role; use MooseX::Daemonize::Pid::File; with 'MooseX::Daemonize::Core'; requires 'init_pidfile'; has pidfile => ( # NOTE: # this should always be accessible # from the command line IMO # - SL metaclass => 'Getopt', isa => 'MooseX::Daemonize::Pid::File', is => 'rw', lazy => 1, coerce => 1, predicate => 'has_pidfile', builder => 'init_pidfile', ); after 'daemonize' => sub { my $self = shift; # NOTE: # make sure that we do not have # any bad PID values stashed around # - SL $self->pidfile->clear_pid; if ($self->is_daemon) { $self->pidfile->write; } }; 1; __END__ =pod =head1 NAME MooseX::Daemonize::WithPidFile - A Role with the core daemonization and pidfile management =head1 SYNOPSIS package My::Daemon; use Moose; with 'MooseX::Daemonize::WithPidFile'; sub start { my $self = shift; # daemonize me ... $self->daemonize; # << this will write the pidfile for you # return from the parent,... return unless $self->is_daemon; # but continue on in the child (daemon) } =head1 DESCRIPTION This is a slightly extended basic daemonization Role, it provides Pidfile management along with the core daemonization features found in L. =head1 ATTRIBUTES =over =item I rw, isa => MooseX::Daemonize::Pid::File)> This attribute holds the L object used to manage the Pidfile. It will initialize the object using the C method (which is required by this role). =back =head1 REQUIRED METHODS =over 4 =item I This method is used to build the I attribute's object. It should return a L object. =item B This is a predicate method to tell you if your I attribute has been initialized yet. =back =head1 METHODS =over 4 =item B This adds an C method modifier to the C method (from L) and handles writing your Pidfile for you. =item B The C method from L =back =head1 DEPENDENCIES L, L and L =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to C, or through the web interface at L. =head1 AUTHOR Stevan Little C<< >> =head1 LICENCE AND COPYRIGHT Copyright (c) 2007-2011, Chris Prather C<< >>. All rights reserved. Portions heavily borrowed from L which is copyright Earl Hood. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. =cut MooseX-Daemonize-0.18/lib/MooseX/Daemonize/Pid/File.pm000644 000767 000024 00000011123 12144240137 022661 0ustar00etherstaff000000 000000 package MooseX::Daemonize::Pid::File; BEGIN { $MooseX::Daemonize::Pid::File::AUTHORITY = 'cpan:PERIGRIN'; } use strict; # because Kwalitee is pedantic use Moose; use Moose::Util::TypeConstraints; our $VERSION = '0.15'; use MooseX::Types::Path::Class; use MooseX::Getopt::OptionTypeMap; # NOTE: # set up some basic coercions # that will come in handy # - SL coerce 'MooseX::Daemonize::Pid::File' => from 'Str' => via { MooseX::Daemonize::Pid::File->new( file => $_ ) } => from 'ArrayRef' => via { MooseX::Daemonize::Pid::File->new( file => $_ ) } => from 'Path::Class::File' => via { MooseX::Daemonize::Pid::File->new( file => $_ ) }; # NOTE: # make sure this class plays # well with MooseX::Getopt # - SL MooseX::Getopt::OptionTypeMap->add_option_type_to_map( 'MooseX::Daemonize::Pid::File' => '=s', ); extends 'MooseX::Daemonize::Pid'; has '+pid' => ( default => sub { my $self = shift; $self->does_file_exist ? $self->file->slurp(chomp => 1) : $$ } ); has 'file' => ( is => 'ro', isa => 'Path::Class::File', coerce => 1, required => 1, handles => [ 'remove' ] ); sub does_file_exist { -s (shift)->file } sub write { my $self = shift; my $fh = $self->file->openw; $fh->print($self->pid . "\n"); $fh->close; } override 'is_running' => sub { return 0 unless (shift)->does_file_exist; super(); }; 1; __END__ =pod =head1 NAME MooseX::Daemonize::Pid::File - PID file management for MooseX::Daemonize =head1 DESCRIPTION This object extends L to add persistence in a Pidfile. This class sets up some basic coercion routines for itself so that it can be created from a I (a file name), I (an array of path components for a filename) or a I object. This class registers it's type with L as well, and is expected to be passed on the command line as a string (which will then go through the coercion routines mentioned above). =head1 ATTRIBUTES =over =item I This is inherited from L and extended here to get it's default value from the Pidfile (if available). =item I =back =head1 METHODS =over =item B =item B Both of these methods are inherited from L see that module for more information. =item B This removes the Pidfile. =item B This writes the Pidfile. =item B This checks if the Pidfile exists. =item B This checks if the Pidfile exists, if it does it checks to see if the process is running, if the Pidfile doesn't exist, it returns false. =item meta() The C method from L =back =head1 DEPENDENCIES Obviously L =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to C, or through the web interface at L. =head1 AUTHOR Stevan Little C<< >> =head1 LICENCE AND COPYRIGHT Copyright (c) 2007-2011, Chris Prather C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. =cut MooseX-Daemonize-0.18/inc/Devel/000755 000767 000024 00000000000 12144240137 016647 5ustar00etherstaff000000 000000 MooseX-Daemonize-0.18/inc/Devel/AssertOS/000755 000767 000024 00000000000 12144240137 020352 5ustar00etherstaff000000 000000 MooseX-Daemonize-0.18/inc/Devel/AssertOS.pm000644 000767 000024 00000004720 12144240137 020713 0ustar00etherstaff000000 000000 package # Devel::AssertOS; use Devel::CheckOS; use strict; use vars qw($VERSION); $VERSION = '1.21'; # localising prevents the warningness leaking out of this module local $^W = 1; # use warnings is a 5.6-ism =head1 NAME Devel::AssertOS - require that we are running on a particular OS =head1 DESCRIPTION Devel::AssertOS is a utility module for Devel::CheckOS and Devel::AssertOS::*. It is nothing but a magic C that lets you do this: use Devel::AssertOS qw(Linux FreeBSD Cygwin); which will die unless the platform the code is running on is Linux, FreeBSD or Cygwin. To assert that the OS is B a specific platform, prepend the platform name with a minus sign. For example, to run on anything but Amiga, do: use Devel::AssertOS qw(-Amiga); =cut sub import { shift; die("Devel::AssertOS needs at least one parameter\n") unless(@_); my @oses = @_; my ( @must, @must_not ); for my $os ( @oses ) { if ( $os =~ s/^-// ) { push @must_not, $os; } else { push @must, $os; } } Devel::CheckOS::die_if_os_is(@must_not) if @must_not; Devel::CheckOS::die_if_os_isnt(@must) if @must; } =head1 BUGS and FEEDBACK I welcome feedback about my code, including constructive criticism. Bug reports should be made using L or by email. You will need to include in your bug report the exact value of $^O, what the OS is called (eg Windows Vista 64 bit Ultimate Home Edition), and, if relevant, what "OS family" it should be in and who wrote it. If you are feeling particularly generous you can encourage me in my open source endeavours by buying me something from my wishlist: L =head1 SEE ALSO $^O in L L L L The use-devel-assertos script L =head1 AUTHOR David Cantrell EFE Thanks to David Golden for suggesting that I add this utility module. =head1 COPYRIGHT and LICENCE Copyright 2007 David Cantrell This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. =head1 CONSPIRACY This module is also free-as-in-mason software. =cut $^O; MooseX-Daemonize-0.18/inc/Devel/CheckOS.pm000644 000767 000024 00000022736 12144240137 020476 0ustar00etherstaff000000 000000 package # Devel::CheckOS; use strict; use Exporter; use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS); $VERSION = '1.71'; # localising prevents the warningness leaking out of this module local $^W = 1; # use warnings is a 5.6-ism @ISA = qw(Exporter); @EXPORT_OK = qw(os_is os_isnt die_if_os_is die_if_os_isnt die_unsupported list_platforms list_family_members); %EXPORT_TAGS = ( all => \@EXPORT_OK, booleans => [qw(os_is os_isnt die_unsupported)], fatal => [qw(die_if_os_is die_if_os_isnt)] ); =head1 NAME Devel::CheckOS - check what OS we're running on =head1 DESCRIPTION A learned sage once wrote on IRC: $^O is stupid and ugly, it wears its pants as a hat Devel::CheckOS provides a more friendly interface to $^O, and also lets you check for various OS "families" such as "Unix", which includes things like Linux, Solaris, AIX etc. It spares perl the embarrassment of wearing its pants on its head by covering them with a splendid Fedora. =head1 SYNOPSIS use Devel::CheckOS qw(os_is); print "Hey, I know this, it's a Unix system\n" if(os_is('Unix')); print "You've got Linux 2.6\n" if(os_is('Linux::v2_6')); =head1 USING IT IN Makefile.PL or Build.PL If you want to use this from Makefile.PL or Build.PL, do not simply copy the module into your distribution as this may cause problems when PAUSE and search.cpan.org index the distro. Instead, use the use-devel-assertos script. =head1 FUNCTIONS Devel::CheckOS implements the following functions, which load subsidiary OS-specific modules on demand to do the real work. They can be exported by listing their names after C. You can also export groups of functions thus: use Devel::CheckOS qw(:booleans); # export the boolean functions # and 'die_unsupported' use Devel::CheckOS qw(:fatal); # export those that die on no match use Devel::CheckOS qw(:all); # export everything =head2 Boolean functions =head3 os_is Takes a list of OS names. If the current platform matches any of them, it returns true, otherwise it returns false. The names can be a mixture of OSes and OS families, eg ... os_is(qw(Unix VMS)); # Unix is a family, VMS is an OS =cut sub os_is { my @targets = @_; my $rval = 0; foreach my $target (@targets) { die("Devel::CheckOS: $target isn't a legal OS name\n") unless($target =~ /^\w+(::\w+)*$/); eval "use Devel::AssertOS::$target"; if(!$@) { no strict 'refs'; $rval = 1 if(&{"Devel::AssertOS::${target}::os_is"}()); } } return $rval; } =head3 os_isnt If the current platform matches any of the parameters it returns false, otherwise it returns true. =cut sub os_isnt { my @targets = @_; my $rval = 1; foreach my $target (@targets) { $rval = 0 if(os_is($target)); } return $rval; } =head2 Fatal functions =head3 die_if_os_isnt As C, except that it dies instead of returning false. The die() message matches what the CPAN-testers look for to determine if a module doesn't support a particular platform. =cut sub die_if_os_isnt { os_is(@_) ? 1 : die_unsupported(); } =head3 die_if_os_is As C, except that it dies instead of returning false. =cut sub die_if_os_is { os_isnt(@_) ? 1 : die_unsupported(); } =head2 And some utility functions ... =head3 die_unsupported This function simply dies with the message "OS unsupported", which is what the CPAN testers look for to figure out whether a platform is supported or not. =cut sub die_unsupported { die("OS unsupported\n"); } =head3 list_platforms When called in list context, return a list of all the platforms for which the corresponding Devel::AssertOS::* module is available. This includes both OSes and OS families, and both those bundled with this module and any third-party add-ons you have installed. In scalar context, returns a hashref keyed by platform with the filename of the most recent version of the supporting module that is available to you. This is to make sure that the use-devel-assertos script Does The Right Thing in the case where you have installed the module in one version of perl, then upgraded perl, and installed it again in the new version. Sometimes the old version of perl and all its modules will still be hanging around and perl "helpfully" includes the old perl's search path in its own. Unfortunately, on some platforms this list may have file case broken. eg, some platforms might return 'freebsd' instead of 'FreeBSD'. This is because they have case-insensitive filesystems so things should Just Work anyway. =cut my ($re_Devel, $re_AssertOS); sub list_platforms { eval " # only load these if needed use File::Find::Rule; use File::Spec; "; die($@) if($@); if (!$re_Devel) { my $case_flag = File::Spec->case_tolerant ? '(?i)' : ''; $re_Devel = qr/$case_flag ^Devel$/x; $re_AssertOS = qr/$case_flag ^AssertOS$/x; } # sort by mtime, so oldest last my @modules = sort { (stat($a->{file}))[9] <=> (stat($b->{file}))[9] } map { my (undef, $dir_part, $file_part) = File::Spec->splitpath($_); $file_part =~ s/\.pm$//; my (@dirs) = grep {+length} File::Spec->splitdir($dir_part); foreach my $i (reverse 1..$#dirs) { next unless $dirs[$i] =~ $re_AssertOS && $dirs[$i - 1] =~ $re_Devel; splice @dirs, 0, $i + 1; last; } { module => join('::', @dirs, $file_part), file => File::Spec->canonpath($_) } } File::Find::Rule->file()->name('*.pm')->in( grep { -d } map { File::Spec->catdir($_, qw(Devel AssertOS)) } @INC ); my %modules = map { $_->{module} => $_->{file} } @modules; if(wantarray()) { return sort keys %modules; } else { return \%modules; } } =head3 list_family_members Takes the name of an OS 'family' and returns a list of all its members. In list context, you get a list, in scalar context you get an arrayref. If called on something that isn't a family, you get an empty list (or a ref to an empty array). =cut sub list_family_members { my $family = shift() || die(__PACKAGE__."::list_family_members needs a parameter\n"); # this will die if it's the wrong OS, but the module is loaded ... eval qq{use Devel::AssertOS::$family}; # ... so we can now query it my @members = eval qq{ no strict 'refs'; &{"Devel::AssertOS::${family}::matches"}() }; return wantarray() ? @members : \@members; } =head1 PLATFORMS SUPPORTED To see the list of platforms for which information is available, run this: perl -MDevel::CheckOS -e 'print join(", ", Devel::CheckOS::list_platforms())' Note that capitalisation is important. These are the names of the underlying Devel::AssertOS::* modules which do the actual platform detection, so they have to be 'legal' filenames and module names, which unfortunately precludes funny characters, so platforms like OS/2 are mis-spelt deliberately. Sorry. Also be aware that not all of them have been properly tested. I don't have access to most of them and have had to work from information gleaned from L and a few other places. For a complete list of OS families, see L. If you want to add your own OSes or families, see L and please feel free to upload the results to the CPAN. =head1 BUGS and FEEDBACK I welcome feedback about my code, including constructive criticism. Bug reports should be made using L or by email. You will need to include in your bug report the exact value of $^O, what the OS is called (eg Windows Vista 64 bit Ultimate Home Edition), and, if relevant, what "OS family" it should be in and who wrote it. If you are feeling particularly generous you can encourage me in my open source endeavours by buying me something from my wishlist: L =head1 SEE ALSO $^O in L L L L L The use-devel-assertos script L =head1 AUTHOR David Cantrell EFE Thanks to David Golden for the name and ideas about the interface, and to the cpan-testers-discuss mailing list for prompting me to write it in the first place. Thanks to Ken Williams, from whose L I lifted some of the information about what should be in the Unix family. Thanks to Billy Abbott for finding some bugs for me on VMS. Thanks to Matt Kraai for information about QNX. Thanks to Kenichi Ishigaki and Gabor Szabo for reporting a bug on Windows, and to the former for providing a patch. Thanks to Paul Green for some information about VOS. Thanks to Yanick Champoux for a patch to let Devel::AssertOS support negative assertions. =head1 SOURCE CODE REPOSITORY L =head1 COPYRIGHT and LICENCE Copyright 2007-2012 David Cantrell This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. =head1 HATS I recommend buying a Fedora from L. =head1 CONSPIRACY This module is also free-as-in-mason software. =cut 1; MooseX-Daemonize-0.18/inc/Devel/AssertOS/MSWin32.pm000644 000767 000024 00000001333 12144240137 022052 0ustar00etherstaff000000 000000 # $Id: MSWin32.pm,v 1.4 2008/11/05 22:52:34 drhyde Exp $ package # Devel::AssertOS::MSWin32; use Devel::CheckOS; $VERSION = '1.2'; sub os_is { $^O eq 'MSWin32' ? 1 : 0; } sub expn { join("\n", "The operating system is Microsoft Windows, and perl was built using", "the Win32 API" ) } Devel::CheckOS::die_unsupported() unless(os_is()); =head1 COPYRIGHT and LICENCE Copyright 2007 - 2008 David Cantrell This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. =cut 1;