java fat包掉linux腳本

 

server1open.shjavascript

#!/bin/bash

nohup /usr/local/jdk/jdk1.8.0_151/bin/java -classpath /usr/local/xwhgames/server/server-1.0-SNAPSHOT-jar-with-dependencies.jar com.server.xwh.run.RunGameShit common_47.xxx.xxx.171_1 ./program >/dev/null 2>/dev/null &

echo success

server1shut.shhtml

#!/bin/bash

#tcp deal
eval pid17788=$(netstat -tlunp | awk '{if($4 == "0.0.0.0:17788") print $7} ' | cut -d "/" -f 1)
kill -9 $pid17788

#tcp6 deal
eval pid1778817788=$(netstat -tlunp | awk '{if($4 == ":::17788") print $7} ' | cut -d "/" -f 1)
kill -9 $pid1778817788

echo success
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head>
    <title>遊戲啓動</title>
    <script type="text/javascript" th:src="@{./static/js/jquery-3.3.1.min.js}"></script>
</head>
<body>
<div>
    <div onclick="order('r0')" style="width:200px;height:200px;float: left;background-image: url('static/images/orange.jpg')"></div>
    <div onclick="order('d0')" style="width:200px;height:200px;float: left;background-image: url('static/images/red.jpg')"></div>
    <div onclick="order('s_1_0')" style="width:200px;height:200px;float: left;background-image: url('static/images/yellow.jpg')"></div>
</div>
<p/>
<div>
    <div onclick="order('r1')" style="width:200px;height:200px;float: left;background-image: url('static/images/head_icon_1.jpg')"></div>
    <div onclick="order('d1')" style="width:200px;height:200px;float: left;background-image: url('static/images/head_icon_2.jpg')"></div>
    <div onclick="order('s_1_1')" style="width:200px;height:200px;float: left;background-image: url('static/images/head_icon_3.jpg')"></div>
</div>

</body>


<script type="text/javascript" th:inline="javascript">
    /*<![CDATA[*/

    function order(id){
        $.ajax({
            type: "GET",
            url: 'http://' + window.location.host + '/order?id='+id,
            dataType: "text",
            success: function (data) {
                alert(data);
            }
        });
    }

    /*]]>*/
</script>
</html>
package com.xwhb.http.verticles;

import io.vertx.core.AbstractVerticle;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.StaticHandler;
import io.vertx.ext.web.templ.ThymeleafTemplateEngine;

import java.io.BufferedReader;
import java.io.InputStreamReader;


public class GameShellVerticle extends AbstractVerticle {


    @Override
    public void start() throws Exception {
        super.start();
        final ThymeleafTemplateEngine engine = ThymeleafTemplateEngine.create();

        final Router router = Router.router(vertx);
        router.route("/static/*").handler(StaticHandler.create("webStatic/static"));

        router.get("/").handler(ctx -> {
            engine.render(ctx, "webStatic/", "gamer.html", res -> {
                if (res.succeeded()) {
                    ctx.response().end(res.result());
                } else {
                    ctx.fail(res.cause());
                }
            });
        });

        router.get("/order").handler(ctx -> {
            String id = ctx.request().getParam("id");
            vertx.executeBlocking(f -> {
                try {
                    String shpath="";

                    if(id.equals("r0")){
                        shpath="/usr/local/xwhgames/shell/routopen.sh";
                    }else if(id.equals("r1")){
                        shpath="/usr/local/xwhgames/shell/routshut.sh";
                    }else if(id.equals("d0")){
                        shpath="/usr/local/xwhgames/shell/dbopen.sh";
                    }else if(id.equals("d1")){
                        shpath="/usr/local/xwhgames/shell/dbshut.sh";
                    }else if(id.equals("s_1_0")){
                        shpath="/usr/local/xwhgames/shell/server1open.sh";
                    }else if(id.equals("s_1_1")){
                        shpath="/usr/local/xwhgames/shell/server1shut.sh";
                    }

                    Process ps = Runtime.getRuntime().exec(shpath);
                    ps.waitFor();

                    BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
                    StringBuffer sb = new StringBuffer();
                    String line;
                    while ((line = br.readLine()) != null) {
                        sb.append(line).append("\n");
                    }
                    String result = sb.toString();
                    System.out.println(result);
                    ctx.response().putHeader("content-type", "text/html; charset=utf-8");
                    ctx.response().end(result);
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
            },false,res -> {});

            System.out.println("here");
        });


        vertx.createHttpServer().requestHandler(router::accept).listen(9788);

        System.out.println("GameShellVerticle 啓動完成");
    }

}
相關文章
相關標籤/搜索