我有一个运行在Ubuntu机器上的Tomcat have服务器。如何从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
它看起来像是在客户端而不是在远程服务器上执行远程脚本。当我在服务器上打开一个终端时,所有的命令和脚本都正常工作。
发布于 2019-03-29 23:42:28
这主要取决于您的tomcat是如何安装的,以及它的版本。
按照这个page,您可以安装Tomcat9并使用systemd配置服务。
在gitlab-ci.yml上,只需使用以下命令远程停止服务:
stop_tomcat_job:
script:
- ssh tomcat@${SERVER} "sudo systemctl stop tomcat" > /dev/null 2>&1
https://stackoverflow.com/questions/55413361
复制相似问题