Skip to main content

sursen-admin

sursen-admin 中各种配置文件和脚本

1.gitlab-ci.yml

image: alpine:latest

before_script:

stages:
- build
- scp
- deploy
- ftp

cache:
paths:
- build/

variables:
FTP_HOST: "ftp://150.138.84.36:21/ygy/hujiahuan/sursen-admin/"
SURSEN: "[email protected]"
SERVER_HOST: "10.0.27.45:/root/v2.2_arv/ARV_Install_Package/SurSecAdmin/"
FILEPATH: "/root/v2.2_arv/ARV_Install_Package/SurSecAdmin/"

build_job:
image: golang:1.18
stage: build
script:
- echo "This is the first build job"
- ls
- cd server
- go env -w GOPROXY=https://goproxy.cn,direct
- go mod tidy
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $SURSEN main.go
- echo "success"
artifacts:
name: $SURSEN
paths:
- build/$SURSEN
expire_in: 1 week
tags:
- sursen

scp_job:
stage: scp
script:
- echo "This is the second scp job"
- ls
- cd build
- ls

- apk add openssh-client
- chmod -R 600 id_rsa
- scp -o StrictHostKeyChecking=no -i id_rsa $SURSEN "$USERNAME"@$SERVER_HOST
- echo "scp success"
tags:
- sursen

deploy_job:
stage: deploy
script:
- echo "This is the third deploy job"
- ls
- cd build
- ls
# - chmod +x ssh.sh # 使脚本可执行
# - ./ssh.sh $SURSEN # 执行脚本
- apk add openssh-client
- chmod -R 600 id_rsa
- ssh -T -o StrictHostKeyChecking=no -i id_rsa [email protected] "cd $FILEPATH; ./deploy.sh $SURSEN"
- echo "deploy success"
tags:
- sursen

ftp_job:
stage: ftp
script:
- echo "This is the fourth deploy job"
- ls
- cd build
- ls

- apk add --no-cache curl
- curl -m 30 --retry 5 -T $SURSEN -u "$FTP_USERNAME":"$FTP_PASSWORD" $FTP_HOST
- echo "ftp success"
tags:
- sursen

2.deploy.sh

#!/bin/bash

# 定义远程服务器的用户名和主机名
PORT='9010'

echo "---$1"

SURSEN=$1

pid=$(netstat -tulnp | grep :$PORT | awk '{print $7}' | cut -d'/' -f1)

echo $pid

echo $(netstat -tulnp | grep :$PORT | awk '{print $7}' | cut -d'/' -f1)

kill -9 $pid

chmod -R 777 $SURSEN

echo $SURSEN

nohup ./$SURSEN &

echo "deploy success"