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脚本内容:
    

  • 相关阅读:
    [0] 需求管理工具CaliberRM
    [0] 自动化测试工具QTP
    [0] UML建模工具(StarUML)
    [0] C# 扩展方法(Extension Method)
    [0] 统一软件过程(RUP)
    [0] XP敏捷开发
    关于ES6的let,const与var之间的三生三世
    lumen手记:自定义Validate表单验证
    window下python安装pip,切换为国内阿里云镜像
    Lumen开发:简单实现auth用户认证
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6200097.html
Copyright © 2011-2022 走看看