This commit is contained in:
2026-02-13 15:56:01 +03:00
parent 03d6c61587
commit 5a249ab510
7 changed files with 209 additions and 8 deletions

View File

@@ -2,4 +2,10 @@
rsync -azP /opt/baggib2b/ root@46.224.33.150:/opt/b2b --delete
cd /tmp && sudo -u postgres pg_dump baggib2b -Fc > /tmp/baggib2b.backup
scp /tmp/baggib2b.backup root@46.224.33.150:/tmp/
scp /tmp/baggib2b.backup root@46.224.33.150:/tmp/
# öbür makinada
export PGPASSWORD=tayitkan
dropdb baggib2b -U postgres -h 127.0.0.1
createdb -h 127.0.0.1 -U postgres baggib2b --encoding=UTF8 --locale=tr_TR.utf8 -T template0
pg_restore -h 127.0.0.1 -U postgres -d baggib2b /tmp/baggib2b.backup

49
scripts/publish.sh Normal file → Executable file
View File

@@ -0,0 +1,49 @@
#!/bin/bash
APP=bssapp
PRJ_ROOT=../
SVC_ROOT=${PRJ_ROOT}/svc
UI_ROOT=${PRJ_ROOT}/ui
DEST_IP=46.224.33.150
echo "Building ${APP} executable"
cd ${SVC_ROOT}
if [[ $OSTYPE == 'darwin'* ]]; then
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o ./$APP ./main.go
else
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o ./$APP ./main.go
fi
echo "Building SPA"
cd ${UI_ROOT}
quasar build
echo "Copying executables"
scp ${SVC_ROOT}/${APP} root@${DEST_IP}:/opt/${APP}/${APP}.new
scp ${SVC_ROOT}/.env root@${DEST_IP}:/opt/${APP}/.env
scp ${SVC_ROOT}/mail.env root@${DEST_IP}:/opt/${APP}/mail.env
# scp ${SVC_ROOT}/upgrader/upgrader root@${DEST_IP}:/opt/${APP}/upgrader
echo "Transferring additional files"
#rsync -azP ${PRJ_ROOT}/templates/ root@${DEST_IP}:/opt/${APP}/templates --delete
#rsync -azP ${PRJ_ROOT}/db/sqls root@${DEST_IP}:/opt/${APP} --delete
#rsync -azP ${SVC_ROOT}/fonts/ root@${DEST_IP}:/opt/${APP}/fonts --delete
#rsync -azP ${PRJ_ROOT}/db/migration/base root@${DEST_IP}:/opt/${APP}/migrate --delete
rsync -azP ${UI_ROOT}/dist/spa/ root@${DEST_IP}:/opt/${APP}/ui --delete
#echo "Migrating database"
#ssh root@${DEST_IP} "/opt/migrater -folder /opt/${APP}/migrate/base -db ${APP} -host 10.0.0.2 -tracker base -migrate-table symigrate -password tesnos.+ed"
echo "Updating system"
ssh root@${DEST_IP} "sudo systemctl stop ${APP}.service"
ssh root@${DEST_IP} "sudo rm /opt/${APP}/${APP}"
ssh root@${DEST_IP} "sudo mv /opt/${APP}/${APP}.new /opt/${APP}/${APP}"
ssh root@${DEST_IP} "chown -R ${APP}:${APP} /opt/${APP}"
ssh root@${DEST_IP} "sudo systemctl start ${APP}.service"
# remove compiled binary
cd ${SVC_ROOT}
rm -rf ./$APP

93
scripts/svc_install.sh Normal file
View File

@@ -0,0 +1,93 @@
#!/bin/bash
APP=bssapp
PORT=43201
DOMAIN=ss.baggi.com.tr
apt update && apt upgrade
apt -y install mc rsync curl nginx
apt install certbot python3-certbot-nginx
dpkg-reconfigure tzdata
useradd --system --shell=/usr/sbin/nologin ${APP}
mkdir -p /opt/${APP}/sqls
mkdir -p /opt/${APP}/migrate
mkdir -p /opt/${APP}/ui
mkdir -p /opt/${APP}/files
echo "Creating application service"
read -d '' sservice << EOF
[Unit]
Description=${APP}
After=syslog.target
After=network.target
#Requires=postgresql.service
#Requires=memcached.service
#Requires=redis.service
[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
LimitMEMLOCK=infinity
LimitNOFILE=1048576
RestartSec=2s
Type=simple
User=${APP}
Group=${APP}
WorkingDirectory=/opt/${APP}/
ExecStart=/opt/${APP}/nerp
Restart=always
Environment=HTTPPORT=${PORT} SQLSDIR=./sqls DBHOST=10.0.0.2 DBNAME=${APP} DBPASS=tesnos.+ed
# enable to bind to a port below 1024 uncomment
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
# Prevent writes to /usr, /boot, and /etc
ProtectSystem=full
# Prevent accessing /home, /root and /run/user
ProtectHome=true
# Execute pre and post scripts as root, otherwise it does it as User=
PermissionsStartOnly=true
[Install]
WantedBy=multi-user.target
EOF
echo "$sservice" > /etc/systemd/system/${APP}.service
echo "Creating nginx conf"
read -d '' ngconf << EOF
server {
server_name ${DOMAIN}
listen 80;
client_max_body_size 100M;
location / {
proxy_pass http://localhost:${PORT};
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}
EOF
echo "$ngconf" > /etc/nginx/sites-available/${DOMAIN}
ln -s /etc/nginx/sites-available/${DOMAIN} /etc/nginx/sites-enabled
systemctl restart nginx
certbot --nginx -d ${DOMAIN}
systemctl daemon-reload
systemctl enable ${APP}