Files
linux-bash/openlist/start_openlist.sh
2026-02-17 17:28:37 +08:00

47 lines
1.4 KiB
Bash
Raw Permalink 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
set -euo pipefail
# 恢复并启动 openlist 服务
# 该脚本用于在执行 stopkill 后恢复服务的正常运行和开机自启
# 用法curl -fsSL "https://pan.shumengya.top/d/scripts/openlist/start_openlist.sh" | sudo bash
SERVICE_NAME="smy-openlist"
log() { printf '[openlist-启动] %s\n' "$*" >&2; }
fail() { log "错误: $*" >&2; exit 1; }
# 检查 root 权限
if [ "${EUID:-$(id -u)}" -ne 0 ]; then
fail "请使用 root 权限运行"
fi
log "正在检查服务状态..."
# 检查服务文件是否存在
if [ ! -f "/etc/systemd/system/${SERVICE_NAME}.service" ]; then
fail "未找到服务文件 /etc/systemd/system/${SERVICE_NAME}.service请先运行安装脚本。"
fi
log "正在恢复服务设置..."
# 重置可能的失败状态
systemctl reset-failed "$SERVICE_NAME" 2>/dev/null || true
log "正在启用并启动服务..."
# --now 选项会同时启用(enable)并启动(start)服务
systemctl enable --now "$SERVICE_NAME"
# 等待服务启动
sleep 2
# 检查启动状态
if systemctl is-active --quiet "$SERVICE_NAME"; then
log "服务启动成功!"
log "状态: $(systemctl is-active "$SERVICE_NAME")"
log "您可以访问 http://IP:5244 使用服务"
else
log "警告: 服务启动似乎遇到了问题"
log "以下是最后 10 行日志:"
systemctl status "$SERVICE_NAME" --no-pager -n 10 || true
exit 1
fi