add deploy.
All checks were successful
Deploy / PullDocker (push) Successful in 4s
Deploy / Build (push) Successful in 2m25s

This commit is contained in:
amass 2024-10-07 13:57:55 +08:00
parent 08340ad5c8
commit c7d97f1b95
3 changed files with 124 additions and 0 deletions

80
resource/deploy.sh Executable file
View File

@ -0,0 +1,80 @@
#!/bin/bash
set -e
SERVER_ADDRESS=47.107.32.69
USER=root
function update() {
echo "start update packages"
ssh "$USER@$SERVER_ADDRESS" <<EOF
apt update
apt upgrade -y
EOF
echo "update packages finished."
}
function init() {
echo "start deploy server"
scp resource/openresty.service $USER@$SERVER_ADDRESS:/lib/systemd/system/openresty.service
scp resource/frps.service $USER@$SERVER_ADDRESS:/etc/systemd/system/frps.service
ssh "$USER@$SERVER_ADDRESS" <<EOF
if command -v openresty > /dev/null 2>&1; then
echo "OpenResty has installed."
else
apt -y install --no-install-recommends wget gnupg ca-certificates lsb-release
wget -O - https://openresty.org/package/pubkey.gpg | gpg --dearmor -o /usr/share/keyrings/openresty.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/openresty.gpg] http://openresty.org/package/ubuntu $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/openresty.list > /dev/null
apt update
apt -y install openresty
opm get bungle/lua-resty-session
fi
if [ ! -f /root/Server/frp_0.60.0_linux_amd64/frps ]; then
# wget https://github.com/fatedier/frp/releases/download/v0.60.0/frp_0.60.0_linux_amd64.tar.gz
wget https://frp-by1.wwvvww.cn:44048/s/frps/download -O frp_0.60.0_linux_amd64.tar.gz
tar xvf ./frp_0.60.0_linux_amd64.tar.gz
fi
if command -v docker &> /dev/null; then
echo "docker has installed."
else
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
fi
if [ ! -d /root/Server ]; then
mkdir -p /root/Server /root/Server/logs
fi
EOF
echo "update packages finished."
}
function main() {
local cmd=$1
shift 1
case $cmd in
update)
update
;;
init)
init
;;
*)
build
;;
esac
}
main $@

14
resource/frps.service Normal file
View File

@ -0,0 +1,14 @@
[Unit]
Description=FRP Server Daemon
After = network.target syslog.target
Wants = network.target
[Service]
Type=simple
ExecStart=/root/Server/frp_0.60.0_linux_amd64/frps -c /root/Server/frp_0.60.0_linux_amd64/frps.toml
Restart=always
RestartSec=2s
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,30 @@
# Stop dance for OpenResty
# =========================
#
# ExecStop sends SIGSTOP (graceful stop) to OpenResty's nginx process.
# If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control
# and sends SIGTERM (fast shutdown) to the main process.
# After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
# SIGKILL to all the remaining processes in the process group (KillMode=mixed).
#
# nginx signals reference doc:
# http://nginx.org/en/docs/control.html
#
[Unit]
Description=The OpenResty Application Platform
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/root/Server/logs/nginx.pid
WorkingDirectory=/root/Server
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t -q -g 'daemon on; master_process on;' -c /root/Server/conf/nginx.conf -p /root/Server
ExecStart=/usr/local/openresty/nginx/sbin/nginx -g 'daemon on; master_process on;' -c /root/Server/conf/nginx.conf -p /root/Server
ExecReload=/usr/local/openresty/nginx/sbin/nginx -g 'daemon on; master_process on;' -s reload -c /root/Server/conf/nginx.conf -p /root/Server
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /usr/local/openresty/nginx/logs/nginx.pid
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target