zoukankan      html  css  js  c++  java
  • Mojo 自动发布接口

     get '/api/auto_publish/publish' => sub{
     my $c = shift;
     my $env = $c->param('env');
     my $app = $c->param('app');
     my $ip = $c->param('ip');
     my $stderr="";
     my $stdout="";
     my $XDATE = strftime("%Y%m%d%H%M%S",localtime());
     
     #and info='$app' and ip='$ip'
     use DBI;
    my %hash=();
    my $dbUser='DEVOPS';
    my $user="root";
    my $passwd="1234567";
    my $dbh  = DBI->connect("dbi:mysql:database=$dbUser;host=192.168.32.161;port=3306",$user,$passwd) or die "can't connect to database ". DBI-errstr;
    my $hostSql = qq{select script  from publish_info where env='$env' and info='$app' and ip='$ip'};
    my $selStmt = $dbh->prepare($hostSql);
    print "$hostSql is $hostSql
    ";
    $selStmt->execute();
    my $script = $selStmt->fetchrow_array();
    
    print "$script is $script
    ";
    use Net::SSH::Perl;
    my $host="$ip";;
    my $user='root';
    my $passwd='xxxx';
    my $cmd="sh $script";
    my $ssh = Net::SSH::Perl->new($host,port=>22);
    $ssh->login($user,$passwd);
    my ($stdout,$stderr,$exit) = $ssh->cmd("$cmd");
    $ssh->cmd("exit");
    if($exit != 0){
    print "ErrorCode:$exit
    ";
    print "ErrorMsg:$stderr";
    
    open( F, ">>", "/home/scan/mojo/log/$app-$ip-$XDATE.log" );
    print F ("ErrorCode:$exit
    ");
    print F ("ErrorMsg:$stderr
    ");
    close F;
    
     $c->render(text =>  "ErrorCode:$exit;ErrorMsg:$stderr")
    } else {
    print $stdout;
    open( F, ">>", "/home/scan/mojo/log/$app-$ip-$XDATE.log" );
    print F ("ErrorCode:$exit
    ");
    print F ("ErrorMsg:$stderr
    ");
    print F ("$stdout
    ");
    close F;
    $c->render(text =>  'publish success')
    }
    
    
    };
    
    
    脚本名字存放在数据库中:
    
    mysql> select * from publish_info;
    +----+----------------+-----------------+------+---------------------------+
    | sn | ip             | info            | env  | script                    |
    +----+----------------+-----------------+------+---------------------------+
    |  1 | 121.xx.xx.9xx  | uat-frontend    | uat  | /root/auto_run/publish.sh |
    |  2 | 1.1.1.1        | aa              | test | /root/auto_run/publish.sh |
    |  3 | 121.xx.1xxx.1xx | zjzc-hy-pre-01  | uat  | /root/auto_run/publish.sh |
    |  6 | 121.0.1.8       | zjzc-hy-core-01 | uat  | /root/auto_run/publish.sh |
    +----+----------------+-----------------+------+---------------------------+
    4 rows in set (0.00 sec)
    
    
    
    
    
    调用的shell脚本内容:
    

  • 相关阅读:
    如何量化用户体验UE(How To Quantify The User Experience)[网摘]
    完美简单的loading外部文件.
    FLV播放器 源码二例
    让你的网站上实时更新各大网站的新闻
    我的第一次涂鸦
    Alan Cooper 的交互设计观 [网摘]
    把视频文件自动的在服务器端转换成FLV文件的FFMPEG的编译方法[网摘]
    ASP.NET 页面生命周期
    ASP.NET MVC Area操作
    浅谈DataAnnotations
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350820.html
Copyright © 2011-2022 走看看