批處理命令一鍵啓動多個服務

新的項目用的微服務架構。服務啓動前要啓動Etcd,Redis等前置條件。然後還要啓動微服務下各個模塊。一個一個的點擊exe,或者敲命令太費時間。然後想到用批處理命令,把各個環節的啓動放到一個bat文件裏一鍵啓動。

經過反覆試驗測試,成功達到預期效果。寫個文章做備份。

最開始把命令都寫在一起,部分能啓動,部分閃退,應該是不在同一目錄下一些環境或者配置拿不到導致的。

然後換個思路,每個服務目錄下都新建一個bat文件,分別測試能啓動。然後一個總的bat文件去分別調用每個服務的bat文件。

總的bat文件代碼如下:

@echo off 

rem start "" cmd /k call b.bat 
rem ""是一段字符串,代表新打開的cmd窗口的名字,可以隨便起名。 
rem /k是表示新打開的cmd窗口在執行完命令後保存打開狀態,如果希望執行完就關閉窗口就使用/c 
rem call b.bat表示call命令,即調用b.bat文件;該命令可以用""括起來,即:"call b.bat"

echo now run the Etcd
cd /d C:\Etcd
start "Etcd" cmd /k call Etcd.bat

echo now run the Redis
cd /d C:\Redis
start "Redis" cmd /k call Redis.bat

echo now run the PhiliAuthority
cd /d D:\PhiliCube\Application\PhiliAuthority
start "PhiliAuthority" cmd /c call phili-auth-server.bat

echo now run the PhiliConfig
cd /d D:\PhiliCube\Application\PhiliConfig\ConfigServerV2
start "PhiliConfig" cmd /c call PhiliConfigStart.bat

echo now run the PhiliGateway
cd /d D:\PhiliCube\Application\PhiliGateway
start "PhiliGateway" cmd /c call phili-gateway.bat

echo now run the PhiliRealTime
cd /d D:\PhiliCube\Application\PhiliRealTime
start "PhiliRealTime" cmd /c call runPhiliRealTime.bat

echo now run the PhiliView
cd /d D:\PhiliCube\Application\PhiliView\philiview\server
start "PhiliView" cmd /c call philiview.bat

Etcd的bat代碼如下:

@echo off
echo start Etcd ...
title Etcd
etcd --config-file=./etcd.conf.yml

Redis(exe類型)的bat代碼如下:

@echo off
echo start redis ...
title Redis
redis-server.exe

Auth(jar類型)代碼如下:

@echo off   
title phili-auth-server
java -jar phili-auth-server.jar

 Config(NodeJs類型)代碼如下:

@echo off
echo start PhiliConfig ...
cd D:\PhiliCube\Application\PhiliConfig\ConfigServerV2
title PhiliConfig
cfgnode.exe server.js

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章