前言
开端口添加域名等等一系列工作可以看我前面Serv00部署自己api站这期的操作
使用
首先,在 Releases · KiritoXDone/Veloera-freebsd · GitHub 下载 Veloera 的二进制文件,上传到根目录下。
在同目录下创建 start.sh
文件,内容如下:
#!/bin/sh
# 如果你有设置主题的需要,可以取消注释下一行,然后按照自己的需求设置。
# export THEME="berry"
export TIKTOKEN_CACHE_DIR="/home/你的Serv00用户名"
# 把下一行的 PORT 改为自己放行的端口
exec ./veloera --port PORT --log-dir ./logs
然后,给 start.sh
文件添加执行权限,chmod + x 或者右键 file permissions,改成 755。
接着创建 ‘restart.sh’ 文件,内容如下:
#!/bin/sh# 将xxx端口替换为你实际使用的端口# 例如,如果你使用的是 8080 端口,则将 PORT=XXX
PORT=XXX
# Check if the port is in usecheck_port() {
sockstat -4l | grep ":${PORT}" >/dev/null 2>&1
return $?
}
# Main logicif check_port; then
echo "Port ${PORT} is already in use. Exiting."
exit 0
else
echo "Port ${PORT} is not in use. Starting service..."
nohup ./start.sh > "./startup.log" 2>&1 &
echo "Started service using start.sh"
fi
然后同样给 restart.sh
文件添加执行权限。
保活方式任意,我使用的是 CF Worker 那版,定时检查 restart.sh 的 Cron 即可。
更新
同时贴一份 ‘update.sh’ ,用于更新 Veloera 的二进制文件:
#!/bin/sh# --- Configuration ---
USERNAME='LINUXDO'# 更改此处为你的用户名
WORK_DIR="/home/${USERNAME}"
LOG_FILE="${WORK_DIR}/update.log"
GITHUB_PROJECT='KiritoXDone/Veloera-freebsd'
BINARY_NAME="veloera"# The name of the binary file to manage# --- End Configuration ---# --- File Paths ---
CURRENT_BINARY_PATH="${WORK_DIR}/${BINARY_NAME}"
VERSION_FILE="${WORK_DIR}/current_version.txt"# File to store the current version tag
DOWNLOAD_PATH="${WORK_DIR}/${BINARY_NAME}_new"# Temporary download location
RESTART_SCRIPT_PATH="${WORK_DIR}/restart.sh"# Path to the restart script# --- Logging Function ---log_message() {
level=$1
message=$2
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "${timestamp} ${level}: ${message}" >> "${LOG_FILE}"
}
# --- Check for jq ---if ! command -v jq > /dev/null 2>&1; then
log_message "ERROR" "jq is not installed. Please run 'pkg install jq'."
echo "ERROR: jq is not installed. Please run 'pkg install jq'." >&2
exit 1
fi
# --- Read Local Version ---
LOCAL_VERSION=""
if [ -f "${VERSION_FILE}" ]; then
LOCAL_VERSION=$(cat "${VERSION_FILE}")
else
log_message "INFO" "Local version file (${VERSION_FILE}) not found. Will attempt to download the latest version."
fi
log_message "INFO" "Current local version: ${LOCAL_VERSION:-'None'}"
# --- Fetch Latest GitHub Release Info ---
API_URL="<https://api.github.com/repos/${GITHUB_PROJECT}/releases/latest>"
TEMP_JSON=$(mktemp)
log_message "INFO" "Fetching latest release info from ${API_URL}"
curl -s -L "${API_URL}" -o "${TEMP_JSON}"
CURL_EXIT_CODE=$?
if [ ${CURL_EXIT_CODE} -ne 0 ]; then
log_message "ERROR" "Failed to fetch release info from GitHub API (curl exit code: ${CURL_EXIT_CODE})."
rm -f "${TEMP_JSON}"
exit 1
fi
# Check for API errorsif jq -e '.message' "${TEMP_JSON}" > /dev/null; then
ERROR_MSG=$(jq -r '.message' "${TEMP_JSON}")
log_message "ERROR" "GitHub API returned an error: ${ERROR_MSG}"
rm -f "${TEMP_JSON}"
exit 1
fi
# Extract tag name and asset download URL
LATEST_TAG=$(jq -r '.tag_name' "${TEMP_JSON}")
ASSET_URL=$(jq -r '.assets[] | select(.name != "source code") | .browser_download_url' "${TEMP_JSON}" | head -n 1)
rm -f "${TEMP_JSON}"# Clean up temp file# Validate extracted dataif [ -z "${LATEST_TAG}" ] || [ "${LATEST_TAG}" = "null" ]; then
log_message "ERROR" "Could not extract tag_name from API response."
exit 1
fi
if [ -z "${ASSET_URL}" ] || [ "${ASSET_URL}" = "null" ]; then
log_message "ERROR" "Could not find a suitable asset download URL in release ${LATEST_TAG}."
exit 1
fi
log_message "INFO" "Latest GitHub version found: ${LATEST_TAG}"
# --- Compare Versions and Update if Necessary ---if [ "${LATEST_TAG}" = "${LOCAL_VERSION}" ]; then
log_message "INFO" "Local version (${LOCAL_VERSION}) is already up-to-date."
exit 0
else
log_message "INFO" "New version (${LATEST_TAG}) detected (local: ${LOCAL_VERSION:-'None'}). Proceeding with update."
# --- Stop existing processes ---
log_message "INFO" "Stopping processes for user ${USERNAME} using pkill -kill..."
pkill -kill -u "${USERNAME}"
PKILL_EXIT_CODE=$?
# pkill returns 1 if no processes were matched, 0 if successful, >1 for errors.if [ ${PKILL_EXIT_CODE} -gt 1 ]; then
log_message "ERROR" "pkill command failed with exit code ${PKILL_EXIT_CODE}."
# Decide if this is fatal. Maybe continue anyway? For now, we'll log and continue.elif [ ${PKILL_EXIT_CODE} -eq 1 ]; then
log_message "INFO" "pkill: No processes found running for user ${USERNAME}."
else
log_message "INFO" "pkill command sent SIGKILL signal successfully."
# Optional: Add a short sleep to allow processes to fully terminatesleep 2
fi
# --- End Stop Processes ---# Download the new version
log_message "INFO" "Downloading ${ASSET_URL} to ${DOWNLOAD_PATH}..."
curl -L -o "${DOWNLOAD_PATH}" "${ASSET_URL}"
CURL_DOWNLOAD_EXIT_CODE=$?
if [ ${CURL_DOWNLOAD_EXIT_CODE} -ne 0 ]; then
log_message "ERROR" "Failed to download asset (curl exit code: ${CURL_DOWNLOAD_EXIT_CODE}). Update aborted."
rm -f "${DOWNLOAD_PATH}"# Clean up partial download# Consider attempting to restart old processes here if needed, or leave stopped.exit 1
fi
# Make the downloaded file executable
log_message "INFO" "Setting execute permissions on ${DOWNLOAD_PATH}..."
chmod +x "${DOWNLOAD_PATH}"
CHMOD_EXIT_CODE=$?
if [ ${CHMOD_EXIT_CODE} -ne 0 ]; then
log_message "ERROR" "Failed to set execute permissions (chmod exit code: ${CHMOD_EXIT_CODE}). Update aborted."
rm -f "${DOWNLOAD_PATH}"
exit 1
fi
# Replace the old binary with the new one
log_message "INFO" "Replacing ${CURRENT_BINARY_PATH} with ${DOWNLOAD_PATH}..."
mv "${DOWNLOAD_PATH}" "${CURRENT_BINARY_PATH}"
MV_EXIT_CODE=$?
if [ ${MV_EXIT_CODE} -ne 0 ]; then
log_message "ERROR" "Failed to replace binary (mv exit code: ${MV_EXIT_CODE}). The downloaded file might still be at ${DOWNLOAD_PATH}. Update aborted."
exit 1
fi
# Update the local version file *after* successful replacement
log_message "INFO" "Updating local version file ${VERSION_FILE} to ${LATEST_TAG}..."
echo "${LATEST_TAG}" > "${VERSION_FILE}"
# --- Execute Restart Script ---
log_message "INFO" "Executing restart script: ${RESTART_SCRIPT_PATH}"
if [ -x "${RESTART_SCRIPT_PATH}" ]; then
# Execute the restart script"${RESTART_SCRIPT_PATH}"
RESTART_EXIT_CODE=$?
if [ ${RESTART_EXIT_CODE} -ne 0 ]; then
log_message "ERROR" "Restart script (${RESTART_SCRIPT_PATH}) failed with exit code ${RESTART_EXIT_CODE}."
# Exit with error as restart failedexit 1
else
log_message "INFO" "Restart script executed successfully."
fi
else
log_message "ERROR" "Restart script (${RESTART_SCRIPT_PATH}) not found or not executable. Processes were stopped but not restarted."
# Exit with error as restart couldn't be performedexit 1
fi
# --- End Execute Restart Script ---
log_message "INFO" "Update process to version ${LATEST_TAG} completed successfully, including restart."
fi
exit 0
使用更新脚本时,记得先给 update.sh
添加执行权限。
其他
注:记得关闭 Serv00 的 WAF,不然对话 token 过大会被拦截!!!
WWW website → 你的域名 → Manage > Web Application Firewall → 设置 WAF 为 disabled。
Comments NOTHING