sage/build.sh

133 lines
3.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# clone from git@git.opencomputing.cn/yumoqing/sage
# git clone https://git.opencomputing.cn/yumoqing/sage
cdir=$(pwd)
uname=$(id -un)
gname=$(id -gn)
sudo apt install redis-server
python3 -m venv py3
source py3/bin/activate
pip install -r requirements.txt
mkdir pkgs
cd pkgs
git clone https://git.opencomputing.cn/charles/smssend.git
cd smssend
pip install .
git clone https://git.opencomputing.cn/yumoqing/bricks
cd bricks/bricks
./build.sh
cd $cdir/wwwroot
ln -s $cdir/pkgs/bricks/dist $dir/wwwroot/bricks
for m in apppublic sqlor ahserver bricks-for-python xls2ddl checklang
do
echo "install $m module..."
cd $cdir/pkgs
git clone https://git.opencomputing.cn/yumoqing/$m
cd $m
$cdir/py3/bin/pip install .
done
do
echo "install $m module..."
cd $cdir/pkgs
if [ ! -d "$cdir/pkgs/$m" ];then
git clone https://git.opencomputing.cn/yumoqing/$m
cd $cdir/pkgs/$m
if [ -d $cdir/pkgs/$m/models ];then
cd $cdir/pkgs/$m/models
xls2ddl mysql . > mysql.ddl.sql
mysql -h db -utest -ptest123 sage < mysql.ddl.sql
fi
fi
cd $cdir/pkgs/$m
$cdir/py3/bin/pip install .
if [ -d $cdir/pkgs/$m/json ];then
cd $cdir/pkgs/$m/json
./build.sh
fi
if [ -d $cdir/pkgs/$m/data ]; then
cd $cdir/pkgs/$m/data
dbloader $cdir sage data.xlsx
fi
rm $cdir/wwwroot/$m
ln -s $cdir/pkgs/$m/wwwroot $cdir/wwwroot/$m
done
mkdir $cdir/logs
cd $cdir
cat > $cdir/sage.service <<EOF
[Unit]
Wants=systemd-networkd.service
[Service]
User=$uname
Group=$gname
Type=forking
WorkingDirectory=$cdir
ExecStart=$cdir/start.sh
ExecStop=$cdir/stop.sh
StandardOutput=append:/var/log/sage/sage.log
StandardError=append:/var/log/sage/sage.log
SyslogIdentifier=sage
[Install]
WantedBy=multi-user.target
EOF
cat > $cdir/start.sh <<EOF
#!/usr/bin/bash
cd $cdir
$cdir/py3/bin/python $cdir/app/sage.py -p 9180 -w $cdir &
exit 0
EOF
cat > $cdir/stop.sh <<EOF
PID=\$(lsof -t -i:9180)
kill -9 \$PID
EOF
chmod +x $cdir/start.sh stop.sh
sudo mkdir /var/log/sage
sudo cp sage.service /etc/systemd/system
sudo systemctl enable sage
sudo systemctl restart sage
new_cron="1 0 * * * curl http://localhost:9180/appbase/cron/switch_bizdate.dspy"
cc=$(crontab -l 2>/dev/null)
if ! echo "$cc"|grep -Fq "$new_cron"; then
(echo "$cc";echo "$new_cron") | crontab -
else
echo "任务已存在,未重复添加。"
fi
# 每日 8:00 抓取外汇牌价
forex_cron="0 8 * * * curl -s http://localhost:9180/accounting/api/fetch_forex_rates.dspy"
if ! echo "$cc"|grep -Fq "fetch_forex_rates"; then
(echo "$cc";echo "$forex_cron") | crontab -
else
echo "汇率任务已存在,未重复添加。"
fi
# sage_datamart ETL crontab
cc=$(crontab -l 2>/dev/null)
# 每5分钟增量同步 llmusage → dm_model_call_fact
dm_sync_cron="*/5 * * * * curl -s http://localhost:9180/sage_datamart/cron/etl_sync.dspy"
if ! echo "$cc"|grep -Fq "etl_sync"; then
(echo "$cc";echo "$dm_sync_cron") | crontab -
cc=$(crontab -l 2>/dev/null)
else
echo "datamart sync任务已存在未重复添加。"
fi
# 每小时聚合 dm_model_perf_daily
dm_agg_cron="15 * * * * curl -s http://localhost:9180/sage_datamart/cron/etl_aggregate.dspy"
if ! echo "$cc"|grep -Fq "etl_aggregate"; then
(echo "$cc";echo "$dm_agg_cron") | crontab -
cc=$(crontab -l 2>/dev/null)
else
echo "datamart aggregate任务已存在未重复添加。"
fi
# 每天 02:00 聚合供应商性价比
dm_prov_cron="0 2 * * * curl -s http://localhost:9180/sage_datamart/cron/etl_provider_cost.dspy"
if ! echo "$cc"|grep -Fq "etl_provider_cost"; then
(echo "$cc";echo "$dm_prov_cron") | crontab -
else
echo "datamart provider_cost任务已存在未重复添加。"
fi