본문 바로가기

(Dev)Ops

jenkins 에서 원격지 tomcat 재시작하기.

jenkins 를 이용하여 배포를 했는데, 원격지의 tomcat 을 수동으로 hostmanager 에 들어가서 stop, start 하는 것이 불편했습니다.

 

방법을 찾아보니, host-manager 를 rest 방식으로 액세스하는 인터페이스를 tomcat 에서 만들어두었더군요.

 

먼저 권한을 부여합니다.

설치디렉토리/conf/tomcat-users.xml 파일에 아래 항목을 넣습니다.

 

<user username="test" password="pass" roles="admin-script"/>

 

테스트해봅니다.

 

curl -u test:pass http://localhost:8080/host-manager/text/list

 

localhost 는 tomcat 이 설치된 곳입니다.

 

이제 jenkins 에서 커맨드라인 실행을 추가합니다.

 

 

 

먼저, 구성을 클릭해서 들어간 후,

 

가장 아래쪽에 Add build step 을 누른 후, Execute shell 을 2개 추가합니다.

stop 과 start 를 하나씩 추가해주면 됩니다.

 

curl -u test:pass http://localhost:8080/host-manager/text/stop?name=www.awesomeserver.com

curl -u test:pass http://localhost:8080/host-manager/text/start?name=www.awesomeserver.com

 

 

hostmanager CLI 참고 : https://tomcat.apache.org/tomcat-8.5-doc/host-manager-howto.html