在远程服务器上通过SSH启动和停止Tomcat

问题描述 投票:0回答:1

我有一个在Ubuntu机器上运行的Tomcat webserver。如何从gitlab-ci通过SSH重启服务器?

我正在通过gitlab-ci上的ssh将各种war和jar文件部署到服务器,并且在某些情况下需要重启Tomcat服务器。

我尝试使用tomcatctl命令:

> ssh user@remote_ip tomcatctl stop
> bash: tomcatctl: command not found

> ssh user@remote_ip bash "tomcatctl stop"
> bash: tomcatctl: No such file or directory

我也尝试编写一个shell脚本并通过ssh调用它:

#!/bin/bash
tomcatctl stop
> ssh user@remote_ip './stopTomcat.sh'
> ./stopTomcat.sh: line 2: tomcatctl: command not found

它看起来像是在客户端而不是远程服务器上执行远程脚本。当我在服务器上打开终端时,所有命令和脚本都正常工作。

ubuntu ssh gitlab-ci tomcat9
1个回答
-1
投票

这主要取决于你的tomcat的安装方式以及它的版本。

在此page之后,您可以安装tomcat 9并使用systemd配置服务。

在gitlab-ci.yml上,只需使用以下命令远程停止服务:

stop_tomcat_job:
  script:
    - ssh tomcat@${SERVER} "sudo systemctl stop tomcat" > /dev/null 2>&1
© www.soinside.com 2019 - 2024. All rights reserved.