Changeset 110 in bookmarks for trunk/bin


Ignore:
Timestamp:
11/16/15 17:38:47 (9 years ago)
Author:
peter
Message:

#13: Add a run command to the bkmkd script.

  • bkmkd run runs the application in the foreground, making it suitable to be the ENTRYPOINT in a Docker container.
  • removed the leading underscore from the function names in bkmkd
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/bkmkd

    r104 r110  
    1818-e $CONFIG_FILE or die "Config file $CONFIG_FILE not found\n"; 
    1919my $config = YAML::LoadFile($CONFIG_FILE); 
    20 my $command = shift or die "Usage: $0 <start|stop>\n"; 
    2120 
    2221my %run = ( 
    23     start   => \&_start_server, 
    24     stop    => \&_stop_server, 
     22    run     => \&run_server, 
     23    start   => \&start_server, 
     24    stop    => \&stop_server, 
    2525    restart => sub { 
    2626        my $config = shift; 
    27         _stop_server($config); 
    28         _start_server($config); 
     27        stop_server($config); 
     28        start_server($config); 
    2929    }, 
    3030); 
     31 
     32my $command = shift or die "Usage: $0 <" . join('|', keys %run) . ">\n"; 
    3133 
    3234exists $run{$command} or die "Unrecognized command $command\n"; 
    3335$run{$command}->($config); 
    3436 
    35 sub _start_server { 
     37sub run_server { 
     38    my $config = shift; 
     39    require BookmarksApp; 
     40    my $app = BookmarksApp->new({ config => $config })->to_app; 
     41 
     42    my $server_root = $config->{server_root} || '.'; 
     43    my $listen      = ':' . ($config->{port} || 5000); 
     44 
     45    my $runner = Plack::Runner->new(server => 'Starman'); 
     46    $runner->parse_options( 
     47        '--listen',     $listen, 
     48    ); 
     49    $runner->run($app); 
     50} 
     51 
     52sub start_server { 
    3653    my $config = shift; 
    3754    require BookmarksApp; 
     
    5572} 
    5673 
    57 sub _stop_server { 
     74sub stop_server { 
    5875    my $config = shift; 
    5976    my $server_root = $config->{server_root} || '.'; 
Note: See TracChangeset for help on using the changeset viewer.