Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Ansible remote Service Management-Java application startup script

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

* * 1. Background; * *

(1)。 In the actual operation and maintenance process, it is inevitable that large-scale operation and maintenance batch tools are similar to ansible for remote management services, similar to starting java environment applications.

Abnormal termination occurred and could not be run

* * warm-up of knowledge related to 2.ansible; * *

(1). Ansible automatic operation and maintenance tools belong to non-interactive login mode for machine management-(bash and system env environment variables are not loaded by default)

(2). Ansible command execution process-- > ansible master execution-- > temporary home directory path of client machine, such as / home/ops/.ansible/tmp/

(3)。 Add a temporary py file to the directory / home/ops/.ansible/tmp/AnsiballZ_command.py above, and then execute the py file-> Clean up to generate a temporary script

(4). Ansible-vvv to view the execution process

* 3. Application scenarios; * *

(1)。 The third party outsourcing project provides shell scripts for release through our release system-release deployment phase using ansible-playbook. The scripts provided by the third party are as follows

#! / bin/bashAPP_NAME= "apie-0.0.1-SNAPSHOT.jar" case $1 in start) nohup java-Dfile.encoding=UTF-8-jar ${APP_NAME}-spring.config.location=application-apicenter.yml-- spring.profiles.active=none & echo ${APP_NAME} start! Stop) ps-ef | grep ${APP_NAME} | grep-v grep | awk'{print $2}'| sed-e "s / ^ / kill-9 / g" | sh-echo ${APP_NAME} stop!;; restart) "$0" stop sleep 3 "$0" start;; status) ps-aux | grep ${APP_NAME} | grep-v 'grep' Log) case $2 indebug) tail-f-n ${3400} logs/debug.log;;error) tail-f-n ${3400} logs/error.log;;*) echo "Example: services.sh log {debug | error}";; esac;; *) echo "Example: services.sh [start | stop | restart | status]"; esac

(2)。 Remote execution script appears

[ops@op] $ansible-I 192.168.1.53, all-m shell-a "su-work-c'/ chj/app/web_app/apiCenter/services-api.sh restart'"-b

172.21.204.53 | CHANGED | rc=0 > >

ApiCenter-0.0.1-SNAPSHOT.jar stop!

ApiCenter-0.0.1-SNAPSHOT.jar start!Error: Unable to access jarfile api-0.0.1-SNAPSHOT.jar

Cause analysis:

The 1.ansible script execution process will look for apiCenter-0.0.1-SNAPSHOT.jar in the / home/ops/.ansible/tmp/ directory and find that there is no such file and an error has been reported; Unable to access jarfile api-0.0.1-SNAPSHOT.jar

(3)。 Perform script modification

#! / bin/bashCURDIR=$ (cd $(dirname ${BASH_SOURCE [0]}) Pwd) # if the first statement executes smoothly, execute pwd to display the current directory And assign the result to the variable "DIR" cd $CURDIR APP_NAME= "apiCenter-0.0.1-SNAPSHOT.jar" case $1 in start) nohup / usr/local/jdk/bin/java-Dfile.encoding=UTF-8-jar ${APP_NAME}-- spring.config.location=application-apicenter.yml-- spring.profiles.active=none > > console.`date "+% FT%TZ" `.log 2 > & 1 & echo ${APP_NAME} start! ; stop) ps-ef | grep ${APP_NAME} | grep-v grep | awk'{print $2}'| sed-e "s / ^ / kill-9 / g" | sh-echo ${APP_NAME} stop!;; restart) "$0" stop sleep 3 "$0" start;; status) ps-aux | grep ${APP_NAME} | grep-v 'grep' Log) case $2 in debug) tail-f-n ${3400} logs/debug.log;; error) tail-f-n ${3400} logs/error.log; *) echo "Example: services.sh log {debug | error}";; esac *) echo "Example: services.sh [start | stop | restart | status]";; esac

(4)。 Test after modification

[ops@op-opsbmc-2-prod] $ansible-I 192.168.1.53, all-m shell-a "su-work-c'/ chj/app/web_app/apiCenter/services-apicenter.sh restart'"-b

192.168.1.53, | CHANGED | rc=0 > >

ApiCenter-0.0.1-SNAPSHOT.jar stop!

ApiCenter-0.0.1-SNAPSHOT.jar start!

(5)。 Log in to the machine to view the process

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 211

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report