[Jifty-commit] r1185 - jifty/trunk/lib/Jifty/Script

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Jun 7 14:10:08 EDT 2006


Author: clkao
Date: Wed Jun  7 14:10:04 2006
New Revision: 1185

Modified:
   jifty/trunk/lib/Jifty/Script/Server.pm

Log:
Add jifty server --start and --stop.


Modified: jifty/trunk/lib/Jifty/Script/Server.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script/Server.pm	(original)
+++ jifty/trunk/lib/Jifty/Script/Server.pm	Wed Jun  7 14:10:04 2006
@@ -8,6 +8,7 @@
 use Jifty::Server;
 use File::Path ();
 
+use constant PIDFILE => 'var/jifty-server.pid';
 
 =head1 NAME
 
@@ -31,6 +32,8 @@
 sub options {
     (
      'p|port=s' => 'port',
+     'start'    => 'start',
+     'stop'     => 'stop',
     )
 }
 
@@ -45,12 +48,29 @@
     my $self = shift;
     Jifty->new();
 
+    if ($self->{stop}) {
+        open my $fh, '<', PIDFILE;
+        my $pid = <$fh>;
+        kill 'TERM', $pid;
+        return;
+    }
+
     # Purge stale mason cache data
     my $data_dir = Jifty->config->framework('Web')->{'DataDir'};
     if (-d $data_dir) {
         File::Path::rmtree(["$data_dir/cache", "$data_dir/obj"]);
     }
 
+    if ($self->{start}) {
+        if (fork()) {
+            return;
+        }
+    }
+    open my $fh, '>', PIDFILE or die $!;
+    print $fh $$;
+    close $fh;
+
     Jifty::Server->new(port => $self->{port})->run;
 }
+
 1;


More information about the Jifty-commit mailing list