文章目录
- 说明
- 使用脚本一键部署本项目
- 开启/停止服务
- 开启/关闭开机自动运行
- 更新项目
参考地址:https://github.com/Evil0ctal/Douyin_TikTok_Download_API?tab=readme-ov-file
说明
后续相关项目可以使用这种方式创建脚本,脚本均放置在项目根目录下的bash目录下
使用脚本一键部署本项目
- 脚本是在Ubuntu 20.04 LTS上测试的,其他系统可能会有问题,如果有问题请自行解决。
- 使用wget命令下载install.sh至服务器并运行
wget -O install.sh https://raw.githubusercontent.com/Evil0ctal/Douyin_TikTok_Download_API/main/bash/install.sh && sudo bash install.sh
install.sh 内容如下:
#!/bin/bash
# Set script to exit on any errors.
set -e
echo 'Updating package lists... | 正在更新软件包列表...'
sudo apt-get update
echo 'Installing Git... | 正在安装Git...'
sudo apt-get install -y git
echo 'Installing Python3... | 正在安装Python3...'
sudo apt install -y python3
echo 'Installing PIP3... | 正在安装PIP3...'
sudo apt install -y python3-pip
echo 'Installing python3-venv... | 正在安装python3-venv...'
sudo apt install -y python3-venv
echo 'Creating path: /www/wwwroot | 正在创建路径: /www/wwwroot'
sudo mkdir -p /www/wwwroot
cd /www/wwwroot || { echo "Failed to change directory to /www/wwwroot | 无法切换到目录 /www/wwwroot"; exit 1; }
echo 'Cloning Douyin_TikTok_Download_API.git from Github! | 正在从Github克隆Douyin_TikTok_Download_API.git!'
sudo git clone https://github.com/Evil0ctal/Douyin_TikTok_Download_API.git
cd Douyin_TikTok_Download_API/ || { echo "Failed to change directory to Douyin_TikTok_Download_API | 无法切换到目录 Douyin_TikTok_Download_API"; exit 1; }
echo 'Creating a virtual environment | 正在创建虚拟环境'
python3 -m venv venv
echo 'Activating the virtual environment | 正在激活虚拟环境'
source venv/bin/activate
echo 'Setting pip to use the default PyPI index | 设置pip使用默认PyPI索引'
pip config set global.index-url https://pypi.org/simple/
echo 'Installing pip setuptools | 安装pip setuptools'
pip install setuptools
echo 'Installing dependencies from requirements.txt | 从requirements.txt安装依赖'
pip install -r requirements.txt
echo 'Deactivating the virtual environment | 正在停用虚拟环境'
deactivate
echo 'Adding Douyin_TikTok_Download_API to system service | 将Douyin_TikTok_Download_API添加到系统服务'
sudo cp daemon/* /etc/systemd/system/
echo 'Enabling Douyin_TikTok_Download_API service | 启用Douyin_TikTok_Download_API服务'
sudo systemctl enable Douyin_TikTok_Download_API.service
echo 'Starting Douyin_TikTok_Download_API service | 启动Douyin_TikTok_Download_API服务'
sudo systemctl start Douyin_TikTok_Download_API.service
echo 'Douyin_TikTok_Download_API installation complete! | Douyin_TikTok_Download_API安装完成!'
echo 'You can access the API at http://localhost:80 | 您可以在http://localhost:80访问API'
echo 'You can change the port in config.yaml under the /www/wwwroot/Douyin_TikTok_Download_API directory | 您可以在/www/wwwroot/Douyin_TikTok_Download_API目录下的config.yaml中更改端口'
echo 'If the API is not working, please change the cookie in config.yaml under the /www/wwwroot/Douyin_TikTok_Download_API/crawler/[Douyin/TikTok]/[APP/Web]/config.yaml directory | 如果API无法工作,请更改/www/wwwroot/Douyin_TikTok_Download_API/crawler/[Douyin/TikTok]/[APP/Web]/config.yaml目录下的cookie'
开启/停止服务
- 使用以下命令来控制服务的运行或停止:
sudo systemctl start Douyin_TikTok_Download_API.service
sudo systemctl stop Douyin_TikTok_Download_API.service
开启/关闭开机自动运行
- 使用以下命令来设置服务开机自动运行或取消开机自动运行:
sudo systemctl enable Douyin_TikTok_Download_API.service
sudo systemctl disable Douyin_TikTok_Download_API.service
更新项目
- 项目更新时,确保更新脚本在虚拟环境中执行,更新所有依赖。进入项目bash目录并运行update.sh:
- cd /www/wwwroot/Douyin_TikTok_Download_API/bash && sudo bash update.sh
update.sh 内容
#!/bin/bash
# Ask for confirmation to proceed with the update
read -r -p "Do you want to update Douyin_TikTok_Download_API? [y/n] " input
case $input in
[yY])
# Navigate to the project directory or exit if it fails
cd /www/wwwroot/Douyin_TikTok_Download_API || { echo "The directory does not exist."; exit 1; }
# Pull the latest changes from the repository
git pull
# Activate the virtual environment
source venv/bin/activate
# Optionally, update Python dependencies
pip install -r requirements.txt
# Deactivate the virtual environment
deactivate
# Restart the service to apply changes
echo "Restarting Douyin_TikTok_Download_API service"
sudo systemctl restart Douyin_TikTok_Download_API.service
echo "Successfully restarted all services!"
;;
[nN]|*)
echo "Exiting..."
exit 1
;;
esac