셀프 업데이트 작업 추가 by script

This commit is contained in:
2024-11-12 11:53:18 +09:00
parent 92432fcd83
commit 592e00b98b
5 changed files with 44 additions and 86 deletions

View File

@ -414,7 +414,7 @@ func NewClient(standalone bool) (HoustonClient, error) {
op.ReportDeployingProgress(ctx, dp) op.ReportDeployingProgress(ctx, dp)
}); err == nil { }); err == nil {
if dr.Name == "houston" { if dr.Name == "houston" {
// houston.update 다운로드가 완료되었으므로 종료 // houston_update_dir 다운로드가 완료되었으므로 종료
// 종료되고나면 스크립트가 알아서 재 실행 // 종료되고나면 스크립트가 알아서 재 실행
hc.Shutdown() hc.Shutdown()
return return

View File

@ -25,6 +25,10 @@ import (
"golang.org/x/text/transform" "golang.org/x/text/transform"
) )
const (
houston_update_dir = "./houston.update"
)
func pof2(x int64, min int64) (out int64) { func pof2(x int64, min int64) (out int64) {
out = 1 out = 1
org := x org := x
@ -217,13 +221,7 @@ func (hc *houstonClient) prepareDeploy(name string, version string) (destPath st
}() }()
verpath := path.Join(hc.config.StorageRoot, name, version) verpath := path.Join(hc.config.StorageRoot, name, version)
if _, err := os.Stat(verpath); os.IsNotExist(err) { if _, err := os.Stat(verpath); !os.IsNotExist(err) {
// 없네? 만들면 된다.
err = os.MkdirAll(verpath, 0775)
if err != nil {
return "", err
}
} else {
// 있네? 재배포 가능한가? // 있네? 재배포 가능한가?
for _, child := range hc.childProcs { for _, child := range hc.childProcs {
if child.version == version && child.name == name { if child.version == version && child.name == name {
@ -287,8 +285,10 @@ func (hc *houstonClient) deploy(req *shared.DeployRequest, cb func(*protos.Deplo
var root string var root string
if req.Name == "houston" { if req.Name == "houston" {
// houston은 버전없이 houston.update폴더로 다운로드 // houston은 버전없이 houston_update_dir폴더로 다운로드
root = "./houston.update" root = houston_update_dir
// 이미 houston_update_dir가 있을 수도 있으므로 폴더채로 삭제
os.RemoveAll(houston_update_dir)
} else { } else {
root, err = hc.prepareDeploy(req.Name, req.Version) root, err = hc.prepareDeploy(req.Name, req.Version)
if err != nil { if err != nil {
@ -296,6 +296,11 @@ func (hc *houstonClient) deploy(req *shared.DeployRequest, cb func(*protos.Deplo
} }
} }
err = os.MkdirAll(root, 0775)
if err != nil {
return err
}
// verpath에 배포 시작 // verpath에 배포 시작
h := md5.New() h := md5.New()
h.Write([]byte(strings.Trim(req.Url, "/"))) h.Write([]byte(strings.Trim(req.Url, "/")))

View File

@ -3,49 +3,35 @@
HOUSTON_PATH="./houston" HOUSTON_PATH="./houston"
UPDATE_DIR="houston.update" UPDATE_DIR="houston.update"
while true; do run_houston() {
# houston 실행
if [ -f "$HOUSTON_PATH" ]; then if [ -f "$HOUSTON_PATH" ]; then
"$HOUSTON_PATH" "$HOUSTON_PATH" "$@"
EXIT_CODE=$? return $?
else else
echo "houston 실행 파일이 없습니다." echo "houston 실행 파일이 없습니다."
EXIT_CODE=1 return 1
fi fi
}
while true; do
echo "현재 버전의 houston을 실행합니다."
run_houston "$@"
# houston.update 폴더가 존재하는지 확인 # houston.update 폴더가 존재하는지 확인
if [ -d "$UPDATE_DIR" ]; then if [ -d "$UPDATE_DIR" ]; then
# houston 파일이 존재하는 경우에만 시간 비교 echo "새로운 업데이트 폴더 발견. 업데이트를 진행합니다."
if [ -f "$HOUSTON_PATH" ]; then # houston.update 폴더 내의 모든 파일을 현재 폴더로 복사
HOUSTON_TIME=$(stat -c %Y "$HOUSTON_PATH") cp -R "$UPDATE_DIR"/* .
UPDATE_TIME=$(stat -c %Y "$UPDATE_DIR") # 실행 권한 부여 (필요한 경우)
chmod +x "$HOUSTON_PATH"
if [ $UPDATE_TIME -gt $HOUSTON_TIME ]; then # 업데이트 폴더 삭제
echo "새로운 업데이트 폴더 발견. 업데이트를 진행합니다." rm -rf "$UPDATE_DIR"
# houston.update 폴더 내의 모든 파일을 현재 폴더로 복사 echo "업데이트 완료 및 업데이트 폴더 삭제. houston을 다시 시작합니다."
cp -R "$UPDATE_DIR"/* .
# 실행 권한 부여 (필요한 경우)
chmod +x "$HOUSTON_PATH"
# 업데이트 폴더 삭제
rm -rf "$UPDATE_DIR"
echo "업데이트 완료 및 업데이트 폴더 삭제. houston을 다시 시작합니다."
else
echo "업데이트 폴더가 최신이 아닙니다. 업데이트를 건너뜁니다."
break
fi
else
echo "houston 파일이 없습니다. houston.update 폴더의 내용을 복사합니다."
cp -R "$UPDATE_DIR"/* .
chmod +x "$HOUSTON_PATH"
# 업데이트 폴더 삭제
rm -rf "$UPDATE_DIR"
echo "houston을 시작합니다."
fi
else else
echo "업데이트 폴더가 없습니다. 스크립트 종료합니다." echo "업데이트 폴더가 없습니다. 스크립트 실행을 종료합니다."
break break
fi fi
done done
echo "houston 실행 및 업데이트 스크립트 종료" echo "houston 실행 및 업데이트 스크립트 종료"
exit $EXIT_CODE exit $?

View File

@ -276,11 +276,15 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
return return
} }
configPath, err := h.findLastestConfigFile(name) var configPath string
if err != nil { if name != "houston" {
logger.Println(err) // houston은 config를 포함하여 배포
w.WriteHeader(http.StatusBadRequest) configPath, err = h.findLastestConfigFile(name)
return if err != nil {
logger.Println(err)
w.WriteHeader(http.StatusBadRequest)
return
}
} }
h.Operation().Deploy(MakeDeployRequest( h.Operation().Deploy(MakeDeployRequest(

View File

@ -14,7 +14,6 @@ import (
"strings" "strings"
"repositories.action2quare.com/ayo/gocommon" "repositories.action2quare.com/ayo/gocommon"
"repositories.action2quare.com/ayo/gocommon/flagx"
"repositories.action2quare.com/ayo/gocommon/logger" "repositories.action2quare.com/ayo/gocommon/logger"
) )
@ -159,9 +158,6 @@ func (h *houstonHandler) RegisterHandlers(serveMux gocommon.ServerMuxInterface,
return nil return nil
} }
var noauth = flagx.Bool("noauth", false, "")
var authtype = flagx.String("auth", "on", "on|off|both")
func (h *houstonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *houstonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer func() { defer func() {
s := recover() s := recover()
@ -176,39 +172,6 @@ func (h *houstonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r.Body.Close() r.Body.Close()
}() }()
// TODO : 구글 인증까지 붙인 후에 주석 제거
// var userinfo map[string]any
// if !*noauth && (*authtype == "on" || *authtype == "both") {
// authheader := r.Header.Get("Authorization")
// if len(authheader) == 0 {
// logger.Println("Authorization header is not valid :", authheader)
// w.WriteHeader(http.StatusBadRequest)
// return
// }
// req, _ := http.NewRequest("GET", "https://graph.microsoft.com/oidc/userinfo", nil)
// req.Header.Add("Authorization", authheader)
// client := &http.Client{}
// resp, err := client.Do(req)
// if err != nil {
// logger.Println("graph microsoft api call failed :", err)
// w.WriteHeader(http.StatusBadRequest)
// return
// }
// defer resp.Body.Close()
// raw, _ := io.ReadAll(resp.Body)
// if err = json.Unmarshal(raw, &userinfo); err != nil {
// return
// }
// if _, expired := userinfo["error"]; expired {
// w.WriteHeader(http.StatusUnauthorized)
// return
// }
// }
var operation string var operation string
if r.Method == "POST" { if r.Method == "POST" {
operation = r.FormValue("operation") operation = r.FormValue("operation")