Changeset 869 in genapp


Ignore:
Timestamp:
Jun 20, 2016, 1:14:31 PM (6 years ago)
Author:
ehb
Message:

install changes, getapp close to ready

Location:
sbin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sbin/getapp.pl

    r850 r869  
    3333
    3434$notes =
    35 "usage[1]: $0 svntype applicationname
     35"usage[1]: $0 {options} svntype applicationname
    3636usage[2]: $0 list
    3737
     
    4141 svn checks out application and sets up paths
    4242
     43 Options:
     44   -admin user         add user name to admin list for application
     45   -force              force checkout even if directory exists
     46   -gen                run genapp.pl after install
     47   -nolinks            do not setup html links
     48
    4349when using usage[2];
    4450 this will list the available application names
     
    4753";
    4854
     55my $admin;
     56my $force;
     57my $gen;
     58my $nolinks;
     59
     60while ( $ARGV[ 0 ] =~ /^-/ ) {
     61    my $option = shift @ARGV;
     62    if ( $option =~ /^-admin$/ ) {
     63        die "$0: option $option requries an argument\n" . $notes if !@ARGV;
     64        $admin = shift @ARGV;
     65        next;
     66    }
     67    if ( $option =~ /^-force$/ ) {
     68        $force = "--force";
     69        next;
     70    }
     71    if ( $option =~ /^-gen$/ ) {
     72        $gen++;
     73        next;
     74    }
     75    if ( $option =~ /^-nolinks$/ ) {
     76        $nolinks++;
     77        next;
     78    }
     79    die "Unknown command line option specified '$option'\n" . $notes;
     80}
     81
    4982$svntype = shift || die $notes;
     83
     84#--- get config.json info
     85
     86my $cfgjson = {};
     87my $cfgjsonf = "$gb/etc/config.json";
     88my $cfgjsonnotes = '-'x80 . "\n
     89$cfgjsonf contains global system information.
     90this is used to setup individual applications values.
     91to build a default config.json file
     92$gb/sbin/setconfig.pl -pj
     93and verify the information is correct.
     94Particularly, if the machine is not publically exposed, you probably want to change the hostip and hostname, as it will likely report the public ip of your firewall.
     95The full options are listed by
     96$gb/sbin/setconfig.pl -h
     97You can also manually edit $cfgjsonf
     98
     99Once you are satisified that the setting are correct
     100you can rerun $0
     101" . '-'x80 . "\n"
     102;
     103
     104{
     105    my $f = $cfgjsonf;
     106    if ( -e $f ) {
     107        print "reading $f\n";
     108        open my $fh, $f || die "$0: can not open $f\n";
     109        my @ol = <$fh>;
     110        close $fh;
     111        my @l = grep !/^\s*#/ , @ol;
     112            my $l = join '', @l;
     113        eval {
     114            $cfgjson = decode_json( $l );
     115            1;
     116        } || do {
     117            my $e = $@;
     118           
     119            # figure out line #
     120
     121            my ( $cp ) = $e =~ /at character offset (\d+) /;
     122            my $i;
     123            my $cpos = $cp;
     124            for ( $i = 0; $i < @ol; ++$i ) {
     125                next if $ol[ $i ] =~ /^\s*#/;
     126                    $cpos -= length( $ol[ $i ] );
     127                last if $cpos < 0;
     128            }
     129
     130            my $sline = $i - 2;
     131            my $eline = $i + 2;
     132            $sline = 0 if $sline < 0;
     133            $eline = @ol - 1 if $eline >= @ol;
     134
     135            print "JSON Error in file $f near these lines:\n";
     136            for ( my $j = $sline; $j <= $eline; ++$j ) {
     137                my $uj = $j + 1;
     138                print "$uj: $ol[$j]";
     139                print "$uj: " .'^'x(length($ol[$j])) . "\n" if $j == $i;
     140            }
     141            die;
     142        };
     143    } else {
     144        my $res = `$gb/sbin/setconfig.pl -pj`;
     145        print "$0 :
     146" . '-'x80 . "
     147please verify these settings are correct
     148" . '-'x80 . "
     149$res
     150$cfgjsonnotes
     151";
     152        exit;
     153    }
     154}
    50155
    51156sub listapps {
     
    67172die "$0: svn-type must be svn or svn+ssh and you specified '$svntype'\n" if $svntype !~ /^svn(\+ssh|)$/;
    68173
    69 die "$0: $app file already exists\n" if -e $app;
     174die "$0: $app file already exists\n" if -e $app && !$force;
    70175
    71176@l = listapps();
     
    76181die "$0: Error: $app is not known as an application name\n" if !$vapp{ $app };
    77182
    78 $cmd = "svn co ${svntype}://$svnbase/$app $app";
     183$cmd = "svn $force co ${svntype}://$svnbase/$app $app";
    79184
    80185print "$cmd\n";
    81186
    82187print `$cmd`;
    83 
    84 #  add setup of default appconfig, directives info into etc (during install.pl or maybe a sysconfig setup?)
    85 #  read this sysconfig file when installing a new instance
    86 #  merge with htmlsetuppaths?
    87 
     188die "$0: checkout failed.
     189One possibility is you switched from svn to svn+ssh or vice-versa, if this is true, you will have to remove or rename the directory.
     190Other possibilities include a network issue, host issue, local diskspace or permissions issue or ?\n" if $?;
     191
     192# sets up the app's appconfig.json:
     193
     194sub setappconfig {
     195    my $app    = $_[0];
     196    my $admin  = $_[1];
     197
     198    my $json = {};
     199    $$json{ "hostip"   } = $$cfgjson{ 'hostip' }   || die "$0 hostip not defined in $cfgjsonf. $cfgjsonnotes";
     200    $$json{ "hostname" } = $$cfgjson{ 'hostname' } || die "$0 hostname not defined in $cfgjsonf. $cfgjsonnotes";
     201
     202    $$json{ "messaging" }{ "wsport" }    = $$cfgjson{ "messaging" }{ "wsport" } || die "$0 wsport not defined in $cfgjsonf. $cfgjsonnotes";
     203    $$json{ "messaging" }{ "wssport" }   = $$cfgjson{ "messaging" }{ "wssport" } || die "$0 wssport not defined in $cfgjsonf. $cfgjsonnotes";
     204    $$json{ "messaging" }{ "zmqhostip" } = $$cfgjson{ "messaging" }{ "zmqhostip" } || die "$0 zmqhostip not defined in $cfgjsonf. $cfgjsonnotes";
     205    $$json{ "messaging" }{ "zmqport" }   = $$cfgjson{ "messaging" }{ "zmqport" } || die "$0 zmqport not defined in $cfgjsonf. $cfgjsonnotes";
     206    $$json{ "messaging" }{ "udphostip" } = $$cfgjson{ "messaging" }{ "udphostip" } || die "$0 udphostip not defined in $cfgjsonf. $cfgjsonnotes";
     207    $$json{ "messaging" }{ "udpport" }   = $$cfgjson{ "messaging" }{ "udpport" } || die "$0 udpport not defined in $cfgjsonf. $cfgjsonnotes";
     208    $$json{ "messaging" }{ "tcphostip" } = $$cfgjson{ "messaging" }{ "tcphostip" } || die "$0 tcphostip not defined in $cfgjsonf. $cfgjsonnotes";
     209    $$json{ "messaging" }{ "tcpport" }   = $$cfgjson{ "messaging" }{ "tcpport" } || die "$0 tcpport not defined in $cfgjsonf. $cfgjsonnotes";
     210
     211    $$json{ "restricted" }{ "admin" } = ( $admin ) if $admin;
     212
     213    $$json{ "resources" }{ "local" } = "";
     214
     215    $$json{ "resourcedefault" } = "local";
     216    $$json{ "submitpolicy" } = "login";
     217
     218    $$json{ "lockdir" } = "$gb/etc";
     219
     220    $f = "$app/appconfig.json";
     221    open  $fh, ">$f" || die "$0: could not open $f for writing\n";
     222    print $fh to_json( $json, { utf8 => 1, pretty => 1 } );
     223    close $fh;
     224    print "created $f\n";
     225}
     226
     227setappconfig( $app, $admin );
     228
     229# setup directives.json
     230
     231sub setdirectives {
     232    my $app     = $_[0];
     233    my $webroot = $_[1];
     234
     235    my $f      = "directives.json.template";
     236    my $fo     = "directives.json";
     237   
     238    die "$0: $app/$f does not exist for this application. 
     239This is an error of the application developer and they should be informed.\n" if !-e "$app/$f";
     240
     241    die "$0: $app/$fo already exists for this application.
     242This file must be manually removed before continuing. 
     243If this error recurrs after removing,
     244This is an error of the application developer and they should be informed.\n" if -e "$app/$fo";
     245
     246    my $djson  = get_file_json( "$app/$f" );
     247
     248    open my $fh, "$app/$f" || die "$0: file open error on $app/$f\n";
     249    my @l = <$fh>;
     250    close $fh;
     251
     252    my $dir = `pwd`;
     253    chomp $dir;
     254
     255    die "$0: $app/$f error, missing __app_parent_directory__ tags.
     256This is an error of the application developer and they should be informed.\n" if !( grep /__app_parent_directory__/, @l );
     257
     258    die "$0: $app/$f error, missing __webroot__ tags.
     259This is an error of the application developer and they should be informed.\n" if !( grep /__webroot__/, @l );
     260
     261#    die "$0: $app/$f error, missing __application__ tags.
     262# This is an error of the application developer and they should be informed.\n" if !( grep /__application__/, @l );
     263
     264    grep s/__app_parent_directory__/$dir/g, @l;
     265
     266    grep s/__webroot__/$dir/g, @l;
     267
     268#    grep s/__application__/$app/g, @l;
     269
     270    if ( $$djson{ 'usewss' } && !$$cfgjson{ 'https' } ) {
     271        @l = grep !/"usewss"/, @l;
     272    }       
     273
     274    if ( $$djson{ 'usews' } && $$cfgjson{ 'https' } ) {
     275        @l = grep !/"usews"/, @l;
     276    }       
     277
     278    # strip white space and comments from end of array
     279    while ( $l[ -1 ] =~ /^(#.*|\s*)$/ ) {
     280        pop @l;
     281    }
     282
     283    die "$0 : $app/$f error: can not locate json closure.
     284This is an error of the application developer and they should be informed.\n" if $l[ -1 ] !~ /^\s*}\s*$/;
     285
     286    pop @l;
     287    push @l, ( $$cfgjson{ 'https' } ? "   ,\"usewss\" : \"true\"\n" : "   ,\"usews\" : \"true\"\n" );
     288    push @l, "}\n";
     289
     290    open  $fh, ">$app/$fo" || die "$0: could not open $app/$fo for writing\n";
     291    print $fh ( join '', @l );
     292    close $fh;
     293    print "created $app/$fo\n";
     294}
     295
     296setdirectives( $app, $$cfgjson{'webroot'} );
     297
     298sub runcmd {
     299    my $cmd = $_[0];
     300    my $out;
     301    print "running shell command:\n--------\n$cmd\n--------\n" if $debug;
     302    open my $fh, "$cmd |";
     303    while ( <$fh> ) {
     304        $out .= $_;
     305        print;
     306    }
     307    close $fh;
     308    die "$0: command $cmd failed\n" if $?;
     309    $out;
     310}
     311
     312sub runcmdsb {
     313    my $cmd = $_[0];
     314    $cmd =~ s/"/\\\"/g;
     315    $cmd = "sudo bash -c \"$cmd\"";
     316    print "sd cmd is <$cmd>\n" if $debug;
     317    runcmd( $cmd );
     318}
     319
     320if ( $gen ) {
     321    runcmd( "cd $app; env GENAPP=$gb genapp.pl" );
     322    if ( !$nolinks ) {
     323        my $dir = `pwd`;
     324        chomp $dir;
     325        my $cmds =
     326"cd $app
     327ln -sf $dir/$app/output/html5 $$cfgjson{'webroot'}/$app
     328mkdir -p output/html5/results output/html5/deleted 2> /dev/null
     329rm ajax results util 2> /dev/null
     330ln -sf output/html5/ajax ajax && ln -sf output/html5/results results && ln -sf output/html5/util util
     331chgrp -R genapp . && chmod -R g+rw . && find . -type d | xargs chmod g+xs
     332";
     333       print "Setting up via these commands:
     334$cmds";
     335       runcmdsb( $cmds );
     336    }
     337}
     338
  • sbin/htmlsetuppaths.pl

    r849 r869  
    142142        print;
    143143    }
     144    close $fh;
     145    die "$0: command $cmd failed\n" if $?;
    144146    $out;
    145147}
  • sbin/install.pl

    r866 r869  
    4646        print;
    4747    }
     48    close $fh;
     49    die "$0: command $cmd failed\n" if $?;
    4850    $out;
    4951}
     
    130132}
    131133
     134die "$0: no webroot defined in $cfgjson
     135please verify and correct before proceeding
     136
     137$cfgjsonnotes
     138" if !$$cfgjson{ 'webroot' };
     139
    132140# screen os / os_release
    133141
     
    149157if ( $os eq 'slackware' ) {
    150158    die "slackware install not currently supported\n";
    151 }
    152 
    153 sub setappconfig() {
    154     my $json = {};
    155     $$json{ "hostip"   } = $$cfgjson{ 'hostip' }   || die "$0 hostip not defined in $cfgjsonf. $cfgjsonnotes";
    156     $$json{ "hostname" } = $$cfgjson{ 'hostname' } || die "$0 hostname not defined in $cfgjsonf. $cfgjsonnotes";
    157 
    158     $$json{ "messaging" }{ "wsport" }    = $$cfgjson{ "messaging" }{ "wsport" } || die "$0 wsport not defined in $cfgjsonf. $cfgjsonnotes";
    159     $$json{ "messaging" }{ "wssport" }   = $$cfgjson{ "messaging" }{ "wssport" } || die "$0 wssport not defined in $cfgjsonf. $cfgjsonnotes";
    160     $$json{ "messaging" }{ "zmqhostip" } = $$cfgjson{ "messaging" }{ "zmqhostip" } || die "$0 zmqhostip not defined in $cfgjsonf. $cfgjsonnotes";
    161     $$json{ "messaging" }{ "zmqport" }   = $$cfgjson{ "messaging" }{ "zmqport" } || die "$0 zmqport not defined in $cfgjsonf. $cfgjsonnotes";
    162     $$json{ "messaging" }{ "udphostip" } = $$cfgjson{ "messaging" }{ "udphostip" } || die "$0 udphostip not defined in $cfgjsonf. $cfgjsonnotes";
    163     $$json{ "messaging" }{ "udpport" }   = $$cfgjson{ "messaging" }{ "udpport" } || die "$0 udpport not defined in $cfgjsonf. $cfgjsonnotes";
    164     $$json{ "messaging" }{ "tcphostip" } = $$cfgjson{ "messaging" }{ "tcphostip" } || die "$0 tcphostip not defined in $cfgjsonf. $cfgjsonnotes";
    165     $$json{ "messaging" }{ "tcpport" }   = $$cfgjson{ "messaging" }{ "tcpport" } || die "$0 tcpport not defined in $cfgjsonf. $cfgjsonnotes";
    166 
    167     $$json{ "restricted" }{ "admin" } = ( $whoami );
    168 
    169     $$json{ "resources" }{ "local" } = "";
    170 
    171     $$json{ "resourcedefault" } = "local";
    172     $$json{ "submitpolicy" } = "login";
    173 
    174     $$json{ "lockdir" } = "$appbase/etc";
    175 
    176     $f = "appconfig.json";
    177     open  $fh, ">$f" || die "$0: could not open $f for writing\n";
    178     print $fh to_json( $json, { utf8 => 1, pretty => 1 } );
    179     close $fh;
    180159}
    181160
     
    263242chown $whoami:genapp $appbase
    264243chmod g+s $appbase
    265 mkdir $appbase/etc
    266 chown genapp:genapp $appbase/etc
    267 chmod g+rwx $appbase/etc
     244mkdir $$cfgjson{'lockdir'}
     245chown genapp:genapp $$cfgjson{'lockdir'}
     246chmod g+rwx $$cfgjson{'lockdir'}
    268247usermod -g users -G genapp $whoami
    269248usermod -G genapp \'www-data\'" );
     
    277256" );
    278257
    279     runcmd( "cd $appbase; svn --force export svn://gw105.iu.xsede.org/svn/base/genapptest genapptest" );
     258    # php info for debugging
    280259   
    281     runcmdsb( "cat <<_EOF > /var/www/html/php_info.php
     260    runcmdsb( "cat <<_EOF > $$cfgjson{'webroot'}/php_info.php
    282261<?php
    283262phpinfo();
     
    288267    # setup genapptest instance
    289268
    290     chdir "$appbase/genapptest" || die "$0: could not change to directory $appbase/genapptest\n";
    291 
    292     {
    293         my $f = "directives.json.template";
    294         open my $fh, "$f" || die "$0: could not open $f\n";
    295         my @l = <$fh>;
    296         close $fh;
    297         grep s/\/REPLACE_WITH_YOUR_HOME_DIRECTORY/$appbase/, @l;
    298         grep s/REPLACE_WITH_YOUR_WEBROOT/var\/www\/html/, @l;
    299 
    300         $f = "directives.json";
    301         open  $fh, ">$f" || die "$0: could not open $f for writing\n";
    302         print $fh ( join '', @l );
    303         close $fh;
    304     }
    305 
    306     setappconfig();
    307 
    308     runcmd ( " . /etc/profile && genapp.pl" );
    309 
    310     runcmd ( "sudo ln -fs $appbase/genapptest/output/html5 /var/www/html/genapptest");
     269    runcmd( "$gb/sbin/getapp.pl -force -gen -admin $whoami svn genapptest" );
     270
     271    # apache2 security needed ?
    311272
    312273    runcmdsb( "cat <<_EOF >> /etc/apache2/conf-enabled/security.conf
    313 # add Alias /genapptest /var/www/html/genapptest
    314 <Directory /var/www/html/genapptest>
     274# add Alias /genapptest $$cfgjson{'webroot'}/genapptest
     275<Directory $$cfgjson{'webroot'}/genapptest>
    315276 Options Indexes FollowSymLinks
    316277 AllowOverride None
     
    408369chown $whoami:genapp $appbase
    409370chmod g+s $appbase
    410 mkdir $appbase/etc
    411 chown genapp:genapp $appbase/etc
    412 chmod g+rwx $appbase/etc
     371mkdir $$cfgjson{'lockdir'}
     372chown genapp:genapp $$cfgjson{'lockdir'}
     373chmod g+rwx $$cfgjson{'lockdir'}
    413374usermod -g users -G genapp $whoami
    414375usermod -G genapp \'apache\'" );
     
    427388" );
    428389
    429     runcmd( "cd $appbase; svn --force export svn://gw105.iu.xsede.org/svn/base/genapptest genapptest" );
    430    
    431     runcmdsb( "cat <<_EOF > /var/www/html/php_info.php
     390    runcmdsb( "cat <<_EOF > $$cfgjson{'webroot'}/php_info.php
    432391<?php
    433392phpinfo();
     
    437396
    438397    # setup genapptest instance
    439 
    440     chdir "$appbase/genapptest" || die "$0: could not change to directory $appbase/genapptest\n";
    441 
    442     {
    443         my $f = "directives.json.template";
    444         open my $fh, "$f" || die "$0: could not open $f\n";
    445         my @l = <$fh>;
    446         close $fh;
    447         grep s/\/REPLACE_WITH_YOUR_HOME_DIRECTORY/$appbase/, @l;
    448         grep s/REPLACE_WITH_YOUR_WEBROOT/var\/www\/html/, @l;
    449 
    450         $f = "directives.json";
    451         open  $fh, ">$f" || die "$0: could not open $f for writing\n";
    452         print $fh ( join '', @l );
    453         close $fh;
    454     }
    455 
    456     setappconfig();
    457 
    458     runcmd ( " . /etc/profile && genapp.pl" );
    459 
    460     runcmd ( "sudo ln -fs $appbase/genapptest/output/html5 /var/www/html/genapptest");
     398    runcmd( "$gb/sbin/getapp.pl -force -gen -admin $whoami svn genapptest" );
     399
     400    # add ws servers to startup
    461401
    462402    runcmdsb( "cp $appbase/genapptest/output/html5/util/rc.genapp /etc/init.d" );
    463403    runcmd( "sg genapp -c '/etc/init.d/rc.genapp start'" );
     404
     405    # open ports
     406    {
     407        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:80`;
     408        chomp $iptab;
     409        if ( $iptab !~ /tcp/ ) {
     410            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
     411service iptables save" );
     412    }
     413    if ( $$cfgjson{ 'https' } ) {
     414        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:443`;
     415        chomp $iptab;
     416        if ( $iptab !~ /tcp/ ) {
     417            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
     418service iptables save" );
     419        }
     420    }
    464421
    465422    runcmdsb( "semanage permissive -a httpd_t; service httpd24-httpd restart && chkconfig httpd24-httpd on" );
     
    591548chown $whoami:genapp $appbase
    592549chmod g+s $appbase
    593 mkdir $appbase/etc
    594 chown genapp:genapp $appbase/etc
    595 chmod g+rwx $appbase/etc
     550mkdir $$cfgjson{'lockdir'}
     551chown genapp:genapp $$cfgjson{'lockdir'}
     552chmod g+rwx $$cfgjson{'lockdir'}
    596553usermod -g users -G genapp $whoami
    597554usermod -G genapp \'apache\'" );
     
    610567" );
    611568
    612     runcmd( "cd $appbase; svn --force export svn://gw105.iu.xsede.org/svn/base/genapptest genapptest" );
    613    
    614     runcmdsb( "cat <<_EOF > /var/www/html/php_info.php
     569    runcmdsb( "cat <<_EOF > $$cfgjson{'webroot'}/php_info.php
    615570<?php
    616571phpinfo();
     
    620575
    621576    # setup genapptest instance
    622 
    623     chdir "$appbase/genapptest" || die "$0: could not change to directory $appbase/genapptest\n";
    624 
    625     {
    626         my $f = "directives.json.template";
    627         open my $fh, "$f" || die "$0: could not open $f\n";
    628         my @l = <$fh>;
    629         close $fh;
    630         grep s/\/REPLACE_WITH_YOUR_HOME_DIRECTORY/$appbase/, @l;
    631         grep s/REPLACE_WITH_YOUR_WEBROOT/var\/www\/html/, @l;
    632 
    633         $f = "directives.json";
    634         open  $fh, ">$f" || die "$0: could not open $f for writing\n";
    635         print $fh ( join '', @l );
    636         close $fh;
    637     }
    638 
    639     setappconfig();
    640 
    641     runcmd ( " . /etc/profile && genapp.pl" );
    642 
    643     runcmd ( "sudo ln -fs $appbase/genapptest/output/html5 /var/www/html/genapptest");
     577    runcmd( "$gb/sbin/getapp.pl -force -gen -admin $whoami svn genapptest" );
     578
     579    # add ws servers to startup
    644580
    645581    runcmdsb( "cp $appbase/genapptest/output/html5/util/rc.genapp /etc/init.d" );
     
    647583
    648584    runcmdsb( "semanage permissive -a httpd_t; service httpd24-httpd restart && chkconfig httpd24-httpd on" );
    649     my $iptab = `service iptables status | grep ACCEPT | grep dpt:80`;
    650     chomp $iptab;
    651     if ( $iptab !~ /tcp/ ) {
    652         runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
     585
     586    {
     587        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:80`;
     588        chomp $iptab;
     589        if ( $iptab !~ /tcp/ ) {
     590            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
    653591service iptables save" );
    654592    }
     593    if ( $$cfgjson{ 'https' } ) {
     594        my $iptab = `service iptables status | grep ACCEPT | grep INPUT | grep dpt:443`;
     595        chomp $iptab;
     596        if ( $iptab !~ /tcp/ ) {
     597            runcmdsb( "iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
     598service iptables save" );
     599        }
     600    }
     601
    655602#    runcmdsb( "service httpd restart && chkconfig httpd on" );
    656603}
    657 
  • sbin/setconfig.pl

    r861 r869  
    4040 -if network-interface-id      find and set hostip from that of specified interface (e.g. eth0, eth1, lo, etc)
    4141 -pj                           print resulting config.json
     42 -https                        use https and wss
     43 -webroot webroot              specifiy the webroot directory
    4244";
    4345
     
    4648my $hostip;
    4749my $hostname;
     50my $https = 0;
     51my $webroot;
    4852
    4953while ( @ARGV ) {
     
    7276        next;
    7377    }
     78    if ( $option =~ /^-webroot$/ ) {
     79        die "$0: option $option requries an argument\n" . $notes if !@ARGV;
     80        $webroot = shift @ARGV;;
     81        next;
     82    }
    7483    if ( $option =~ /^-h$/ ) {
    7584        print $notes;
     
    7887    if ( $option =~ /^-pj$/ ) {
    7988        $pj++;
     89        next;
     90    }
     91    if ( $option =~ /^-https$/ ) {
     92        $https++;
    8093        next;
    8194    }
     
    127140}
    128141
    129 print "hostip is currently $hostip\n";
    130 
    131142# determine os
    132143
     
    234245}
    235246
    236 my $wssport   = 80;
     247my $wssport   = $https ? 443 : 80;
    237248my $wsport    = 37777;
    238249my $zmqport   = 37778;
     
    331342}
    332343
     344if ( $$json{ "https" } ) {
     345    if ( $$json{'https'} != $https ) {
     346        $notice .= "The identified https flag for this server [$https] is different than that stored [$$json{'https'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n";
     347    }
     348    if ( $fo ) {
     349        $$json{'https'}         = int($https);
     350    }
     351} else {
     352    $$json{'https'}         = int($https);
     353}
     354
     355if ( !$webroot ) {
     356    $webroot = "/var/www/html" if $os =~ /^(ubuntu|centos|redhat)$/;
     357}
     358
     359if ( $$json{ "webroot" } ) {
     360    if ( $$json{'webroot'} != $webroot ) {
     361        $notice .= "The identified webroot for this server [$webroot] is different than that stored [$$json{'webroot'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n";
     362    }
     363    if ( $fo ) {
     364        $$json{'webroot'}         = $webroot;
     365    }
     366} else {
     367    $$json{'webroot'}         = $webroot;
     368}
     369
    333370open my $fh, ">$f" || die "$0: can not open $f for writing, check permissions\n";
    334371print $fh to_json( $json, { utf8 => 1, pretty => 1 } );
     
    344381
    345382print "-"x80 . "\n" . "Notices:\n" . "-"x80 . "\n" . $notice . "-"x80 . "\n" if $notice;
    346 ;
  • sbin/tutorial-user.pl

    r839 r869  
    6363        print;
    6464    }
     65    close $fh;
     66    die "$0: command $cmd failed\n" if $?;
    6567    $out;
    6668}
Note: See TracChangeset for help on using the changeset viewer.