V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
tudoutiaoya
V2EX  ›  问与答

github actions 部署 jar 包到自己服务器,出现问题

  •  
  •   tudoutiaoya · 2023-05-08 20:20:50 +08:00 · 1162 次点击
    这是一个创建于 556 天前的主题,其中的信息可能已经有所发展或是发生改变。
    目的:想要使用 github actions 实现构建 jar 包,并且把 jar 包发送到自己服务器,停止掉原先的 java 进程,并重新运行这个 java 进程


    执行 ci/cd 过程中一直出现这个问题


    出现问题:
    Run appleboy/ssh-action@master
    /usr/bin/docker run --name ed866e20cb3a0f8f0c404b93e830be27cb68ca_4ed969 --label ed866e --workdir /github/workspace --rm -e "JAVA_HOME" -e "INPUT_HOST" -e "INPUT_USERNAME" -e "INPUT_KEY" -e "INPUT_SCRIPT" -e "INPUT_PORT" -e "INPUT_PASSPHRASE" -e "INPUT_PASSWORD" -e "INPUT_SYNC" -e "INPUT_USE_INSECURE_CIPHER" -e "INPUT_CIPHER" -e "INPUT_TIMEOUT" -e "INPUT_COMMAND_TIMEOUT" -e "INPUT_KEY_PATH" -e "INPUT_FINGERPRINT" -e "INPUT_PROXY_HOST" -e "INPUT_PROXY_PORT" -e "INPUT_PROXY_USERNAME" -e "INPUT_PROXY_PASSWORD" -e "INPUT_PROXY_PASSPHRASE" -e "INPUT_PROXY_TIMEOUT" -e "INPUT_PROXY_KEY" -e "INPUT_PROXY_KEY_PATH" -e "INPUT_PROXY_FINGERPRINT" -e "INPUT_PROXY_CIPHER" -e "INPUT_PROXY_USE_INSECURE_CIPHER" -e "INPUT_SCRIPT_STOP" -e "INPUT_ENVS" -e "INPUT_ENVS_FORMAT" -e "INPUT_DEBUG" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/dousheng/dousheng":"/github/workspace" ed866e:20cb3a0f8f0c404b93e830be27cb68ca
    ======CMD======
    cd /home/springboot/dousheng/test/target/
    pgrep -f dousheng-0.0.1-SNAPSHOT.jar | xargs -r kill -9
    nohup java -jar dousheng-0.0.1-SNAPSHOT.jar >/dev/null 2>&1 &

    ======END======
    2023/05/08 12:02:54 Process exited with status 137 from signal KILL






    我的 actions 文件:
    name: Deploy to Server

    on:
    push:
    branches:
    - main

    jobs:
    build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
    uses: actions/checkout@v2

    - name: Set up JDK
    uses: actions/setup-java@v2
    with:
    distribution: 'zulu'
    java-version: '8'

    - name: Build with Maven
    run: mvn clean package

    - name: Copy Jar to Server
    uses: appleboy/scp-action@master
    with:
    host: ${{ secrets.SERVER_HOST }}
    username: ${{ secrets.SERVER_USERNAME }}
    key: ${{ secrets.SERVER_KEY }}
    source: target/dousheng-0.0.1-SNAPSHOT.jar #默认为 artifactId-version
    target: /home/springboot/dousheng/test/

    - name: SSH into Server and start the application
    uses: appleboy/ssh-action@master
    with:
    host: ${{ secrets.SERVER_HOST }}
    username: ${{ secrets.SERVER_USERNAME }}
    key: ${{ secrets.SERVER_KEY }}
    script: |
    cd /home/springboot/dousheng/test/target/
    pgrep -f dousheng-0.0.1-SNAPSHOT.jar | xargs -r kill -9
    nohup java -jar dousheng-0.0.1-SNAPSHOT.jar >/dev/null 2>&1 &
    7 条回复    2023-05-12 10:08:10 +08:00
    t133
        1
    t133  
       2023-05-08 20:24:34 +08:00 via iPhone
    你把错误那个语句的输出全部重定向了 盲猜一个环境变量
    defunct9
        2
    defunct9  
       2023-05-08 20:40:01 +08:00
    开 ssh ,让我上去看看
    Sharuru
        3
    Sharuru  
       2023-05-08 20:50:22 +08:00 via iPhone
    137 没毛病,因为你是用 SIGKILL 把服务停的。
    直接或一下 exit 0 让 action 不检测到错误就行。
    比较好的方法是直接把 jar 写成服务,用 systemctl start ,stop 也比较好管理。
    tudoutiaoya
        4
    tudoutiaoya  
    OP
       2023-05-09 09:14:47 +08:00
    我的想法是把 jar 包部署到服务器,先停掉原先的 java 进程,之后重新-jar 运行一下
    tudoutiaoya
        5
    tudoutiaoya  
    OP
       2023-05-09 09:26:38 +08:00
    这样吗
    pgrep -f dousheng-0.0.1-SNAPSHOT.jar | xargs -r kill -9 | exit 0
    tudoutiaoya
        6
    tudoutiaoya  
    OP
       2023-05-11 16:45:39 +08:00
    总是在这里出现问题:137 信号是进程被强制终止是由于什么原因


    Run appleboy/ssh-action@master
    /usr/bin/docker run --name ed866e57e73017a1ca41e08688d89a3502c97e_3817af --label ed866e --workdir /github/workspace --rm -e "JAVA_HOME" -e "INPUT_HOST" -e "INPUT_USERNAME" -e "INPUT_KEY" -e "INPUT_SCRIPT" -e "INPUT_PORT" -e "INPUT_PASSPHRASE" -e "INPUT_PASSWORD" -e "INPUT_SYNC" -e "INPUT_USE_INSECURE_CIPHER" -e "INPUT_CIPHER" -e "INPUT_TIMEOUT" -e "INPUT_COMMAND_TIMEOUT" -e "INPUT_KEY_PATH" -e "INPUT_FINGERPRINT" -e "INPUT_PROXY_HOST" -e "INPUT_PROXY_PORT" -e "INPUT_PROXY_USERNAME" -e "INPUT_PROXY_PASSWORD" -e "INPUT_PROXY_PASSPHRASE" -e "INPUT_PROXY_TIMEOUT" -e "INPUT_PROXY_KEY" -e "INPUT_PROXY_KEY_PATH" -e "INPUT_PROXY_FINGERPRINT" -e "INPUT_PROXY_CIPHER" -e "INPUT_PROXY_USE_INSECURE_CIPHER" -e "INPUT_SCRIPT_STOP" -e "INPUT_ENVS" -e "INPUT_ENVS_FORMAT" -e "INPUT_DEBUG" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/dousheng/dousheng":"/github/workspace" ed866e:57e73017a1ca41e08688d89a3502c97e
    ======CMD======
    cd /home/springboot/dousheng/test/target/
    pgrep -f dousheng-0.0.1-SNAPSHOT.jar | xargs -r kill -9 || true
    nohup java -jar dousheng-0.0.1-SNAPSHOT.jar >/dev/null 2>&1 &
    ======END======
    2023/05/11 08:41:54 Process exited with status 137 from signal KILL
    tudoutiaoya
        7
    tudoutiaoya  
    OP
       2023-05-12 10:08:10 +08:00
    搞定了,想学习的可以看我的文章: https://juejin.cn/post/7231920813217316901
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4578 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 10:00 · PVG 18:00 · LAX 02:00 · JFK 05:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.