Changeset 103 in bookmarks for trunk


Ignore:
Timestamp:
07/06/15 16:49:23 (9 years ago)
Author:
peter
Message:
  • moved scripts into the bin directory
  • combined start and stop in bkmkd
Location:
trunk/bin
Files:
1 added
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/bin/bkmk

    r100 r103  
    33 
    44use FindBin; 
    5 use lib "$FindBin::RealBin/lib"; 
     5use lib "$FindBin::RealBin/../lib"; 
    66 
    77use YAML; 
  • trunk/bin/bkmkd

    r102 r103  
    33 
    44use FindBin; 
    5 use lib "$FindBin::RealBin/lib"; 
     5use lib "$FindBin::RealBin/../lib"; 
    66 
    77use Getopt::Long; 
    88use YAML; 
    99use Plack::Runner; 
    10 use BookmarksApp; 
     10use File::Pid; 
    1111use File::Spec::Functions qw{catfile}; 
    1212 
     
    1818-e $CONFIG_FILE or die "Config file $CONFIG_FILE not found\n"; 
    1919my $config = YAML::LoadFile($CONFIG_FILE); 
    20 my $app = BookmarksApp->new({ config => $config })->to_app; 
     20my $command = shift or die "Usage: $0 <start|stop>\n"; 
    2121 
    22 my $server_root = $config->{server_root} || '.'; 
    23 my $listen      = ':' . ($config->{port} || 5000); 
    24 my $access_log  = catfile($server_root, 'access'); 
    25 my $error_log   = catfile($server_root, 'errors'); 
    26 my $pid_file    = catfile($server_root, 'pid'); 
     22my %run = ( 
     23    start => sub { 
     24        my $config = shift; 
     25        require BookmarksApp; 
     26        my $app = BookmarksApp->new({ config => $config })->to_app; 
    2727 
    28 my $runner = Plack::Runner->new(server => 'Starman'); 
    29 $runner->parse_options( 
    30     '--daemonize', 
    31     '--listen',     $listen, 
    32     '--pid',        $pid_file, 
    33     '--error-log',  $error_log, 
    34     '--access-log', $access_log, 
     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        } 
     56    }, 
    3557); 
    36 $runner->run($app); 
     58 
     59exists $run{$command} or die "Unrecognized command $command\n"; 
     60$run{$command}->($config); 
  • trunk/bin/stop

    r102 r103  
    33 
    44use FindBin; 
    5 use lib "$FindBin::RealBin/lib"; 
     5use lib "$FindBin::RealBin/../lib"; 
    66 
    77use Getopt::Long; 
Note: See TracChangeset for help on using the changeset viewer.