Changeset 104 in bookmarks for trunk/bin/bkmkd


Ignore:
Timestamp:
09/11/15 17:28:02 (9 years ago)
Author:
peter
Message:
  • removed the separate stop script (function now handled by bkmkd stop)
  • added a restart command to bkmkd
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/bkmkd

    r103 r104  
    2121 
    2222my %run = ( 
    23     start => sub { 
     23    start   => \&_start_server, 
     24    stop    => \&_stop_server, 
     25    restart => sub { 
    2426        my $config = shift; 
    25         require BookmarksApp; 
    26         my $app = BookmarksApp->new({ config => $config })->to_app; 
    27  
    28         my $server_root = $config->{server_root} || '.'; 
    29         my $listen      = ':' . ($config->{port} || 5000); 
    30         my $access_log  = catfile($server_root, 'access'); 
    31         my $error_log   = catfile($server_root, 'errors'); 
    32         my $pid_file    = catfile($server_root, 'pid'); 
    33  
    34         my $runner = Plack::Runner->new(server => 'Starman'); 
    35         $runner->parse_options( 
    36             '--daemonize', 
    37             '--listen',     $listen, 
    38             '--pid',        $pid_file, 
    39             '--error-log',  $error_log, 
    40             '--access-log', $access_log, 
    41         ); 
    42         $runner->run($app); 
    43     }, 
    44  
    45     stop => sub { 
    46         my $config = shift; 
    47         my $server_root = $config->{server_root} || '.'; 
    48  
    49         my $pid_file = File::Pid->new({ 
    50                 file => catfile($server_root, 'pid'), 
    51             }); 
    52  
    53         if (my $pid = $pid_file->running) { 
    54             kill 'TERM', $pid; 
    55         } 
     27        _stop_server($config); 
     28        _start_server($config); 
    5629    }, 
    5730); 
     
    5932exists $run{$command} or die "Unrecognized command $command\n"; 
    6033$run{$command}->($config); 
     34 
     35sub _start_server { 
     36    my $config = shift; 
     37    require BookmarksApp; 
     38    my $app = BookmarksApp->new({ config => $config })->to_app; 
     39 
     40    my $server_root = $config->{server_root} || '.'; 
     41    my $listen      = ':' . ($config->{port} || 5000); 
     42    my $access_log  = catfile($server_root, 'access'); 
     43    my $error_log   = catfile($server_root, 'errors'); 
     44    my $pid_file    = catfile($server_root, 'pid'); 
     45 
     46    my $runner = Plack::Runner->new(server => 'Starman'); 
     47    $runner->parse_options( 
     48        '--daemonize', 
     49        '--listen',     $listen, 
     50        '--pid',        $pid_file, 
     51        '--error-log',  $error_log, 
     52        '--access-log', $access_log, 
     53    ); 
     54    $runner->run($app); 
     55} 
     56 
     57sub _stop_server { 
     58    my $config = shift; 
     59    my $server_root = $config->{server_root} || '.'; 
     60 
     61    my $pid_path = catfile($server_root, 'pid'); 
     62    unless (-e $pid_path) { 
     63        warn "$pid_path does not exist\n"; 
     64        return; 
     65    } 
     66 
     67    my $pid_file = File::Pid->new({ 
     68        file => $pid_path, 
     69    }); 
     70 
     71    if (my $pid = $pid_file->running) { 
     72        kill 'TERM', $pid; 
     73    } 
     74} 
Note: See TracChangeset for help on using the changeset viewer.