Operations 4 min read

Automated Deployment Script: Build, Transfer, and Restart with Eureka and Nginx

This guide walks through a complete automated deployment workflow—including Maven build, rsync transfer, graceful shutdown of Nginx and Eureka services, service restart, health checks, and final bring‑up of both Eureka and Nginx—using shell commands and parameterized variables.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Automated Deployment Script: Build, Transfer, and Restart with Eureka and Nginx

Configuration Variables

Define the necessary variables for the deployment process, such as app_name=SERVICE_NAME, instance_id=serviceIP:9796, port=9796, remote_ip=172.19.38.133, Nginx IPs ( nginx_biz_1_ip=172.19.38.93, nginx_biz_2_ip=172.19.38.124), the project path ( project_path=service), the jar package name ( package=servicename-web.jar), and the release directory ( release_path=/usr/local/servicename/).

Build and Package

Compile and package the application without running tests:

mvn clean package -DskipTests=true

Transfer Package to Remote Server

Synchronize the built jar file to the target server using rsync:

rsync -av --progress ${project_path}/target/${package} root@${remote_ip}:/data/jenkins/package/

Take Nginx Services Offline

Log the shutdown and execute the Nginx service‑down scripts for both business instances:

echo "nginx_biz_1服务下线"
/data/script/nginx/nginx-service-down.sh ${nginx_biz_1_ip} ${remote_ip} ${port}
/data/script/nginx/nginx-remote-nginx-reload.sh ${nginx_biz_1_ip}
echo "nginx_biz_2服务下线"
/data/script/nginx/nginx-service-down.sh ${nginx_biz_2_ip} ${remote_ip} ${port}
/data/script/nginx/nginx-remote-nginx-reload.sh ${nginx_biz_2_ip}

Take Eureka Service Offline

Log the action and invoke the Python script to deregister the instance from Eureka:

echo "eureka服务下线"
python3 /data/script/eureka_biz_out_of_service-eureka.py ${app_name} ${instance_id}
sleep 35s

Restart Service on Remote Host

Copy the new jar to the release directory and restart the service via SSH:

ssh root@${remote_ip} "source /etc/profile && /usr/bin/cp -p /data/jenkins/package/${package} ${release_path} && ${release_path}web.sh restart"
echo "正在重启服务,等待40s"
sleep 40s

Health Check

Run a Python HTTP‑code check to verify the service is reachable:

python3 /usr/local/script/check_http_code.py ${remote_ip} ${port} ${app_name}

Bring Eureka Service Back Online

Log the action and re‑register the instance with Eureka:

echo "eureka服务上线"
python3 /usr/local/script/eureka_biz_up-eureka.py ${app_name} ${instance_id}

Bring Nginx Services Back Online

Log and start each Nginx business instance, then reload the remote Nginx configuration:

echo "nginx_biz_1服务上线"
/data/script/nginx/xlm-service-up.sh ${nginx_biz_1_ip} ${remote_ip} ${port}
/data/script/nginx/xlm-remote-nginx-reload.sh ${nginx_biz_1_ip}
echo "nginx_biz_2服务上线"
/data/script/nginx/xlm-service-up.sh ${nginx_biz_2_ip} ${remote_ip} ${port}
/data/script/nginx/xlm-remote-nginx-reload.sh ${nginx_biz_2_ip}
deploymentcontinuous integrationEurekashell script
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.