Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 修改小雅alist的状态检查逻辑 #108

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion alist/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ADD --chmod=755 https://raw.githubusercontent.com/monlor/docker-xiaoya/main/bin/

COPY --chmod=755 ./*.sh /

RUN /data.sh download
RUN /service.sh download

ENTRYPOINT [ "/dumb-init", "--", "/start.sh" ]

Expand Down
35 changes: 32 additions & 3 deletions alist/data.sh → alist/service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,35 @@ download_files() {
fi
}

restart_service() {
start() {
/entrypoint.sh /opt/alist/alist server --no-prefix &
}

stop() {
kill -15 $(pgrep -f 'nginx|httpd|alist')
}

restart() {
stop
sleep 10
/entrypoint.sh /opt/alist/alist server --no-prefix &
start
}

update() {
if ! download_files; then
echo "Failed to download files or no need to update"
return 1
fi
restart_service
restart
}

# 进程守护函数
daemon() {

if [ -z "$(pgrep alist)" ]; then
start
fi

}

case "$1" in
Expand All @@ -84,6 +101,18 @@ case "$1" in
download)
download_files
;;
start)
start
;;
stop)
stop
;;
restart)
restart
;;
daemon)
daemon
;;
*)
echo "Usage: $0 {update|download}"
exit 1
Expand Down
5 changes: 4 additions & 1 deletion alist/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,17 @@ if [ "${AUTO_UPDATE_ENABLED:=false}" = "true" ]; then
# 随机生成一个时间,避免给服务器造成压力
random_min=$(shuf -i 0-59 -n 1)
random_hour=$(shuf -i 2-6 -n 1)
crontabs="${random_min} ${random_hour} * * * /data.sh update"
crontabs="${random_min} ${random_hour} * * * /service.sh update"
fi

if [ "${AUTO_CLEAR_ENABLED:=false}" = "true" ]; then
echo "启动定时清理定时任务..."
crontabs="${crontabs}\n*/${AUTO_CLEAR_INTERVAL:=10} * * * * /clear.sh"
fi

# 添加后台守护
crontabs="${crontabs}\n* * * * * /service.sh daemon"

if [ -n "${crontabs}" ]; then
echo -e "$crontabs" | crontab -
fi
Expand Down
12 changes: 7 additions & 5 deletions emby/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/sh

echo "等待alist启动完成..."
while ! wget -q -T 1 -O /dev/null "${ALIST_ADDR:=http://alist:5678}" > /dev/null 2>&1; do
ALIST_ADDR=${ALIST_ADDR:-http://alist:5678}

echo "检查alist连通性..."
while ! wget -q -T 1 -O - "${ALIST_ADDR}/api/public/settings" | grep -q 200; do
sleep 2
done

Expand All @@ -24,10 +26,10 @@ echo "开始自动更新alist地址..."
/update_alist_addr.sh > /dev/null 2>&1 &

echo "启动emby服务..."
/emby.sh start
/service.sh start
sleep 2

echo "启动进程守护..."
/emby.sh daemon &
/service.sh daemon &

exec shell2http -port 8080 /stop "/emby.sh stop" /start "/emby.sh start"
exec shell2http -port 8080 /stop "/service.sh stop" /start "/service.sh start"
File renamed without changes.
6 changes: 4 additions & 2 deletions jellyfin/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/sh

echo "等待alist启动完成..."
while ! curl -s -f -m 1 "${ALIST_ADDR:=http://alist:5678}" > /dev/null 2>&1; do
ALIST_ADDR=${ALIST_ADDR:-http://alist:5678}

echo "检查alist连通性..."
while ! curl --silent --show-error --fail "${ALIST_ADDR}/api/public/settings" | grep -q 200; do
sleep 2
done

Expand Down
6 changes: 4 additions & 2 deletions metadata/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

set -e

echo "等待alist启动完成..."
while ! curl -s -f -m 1 "${ALIST_ADDR:=http://alist:5678}" > /dev/null; do
ALIST_ADDR=${ALIST_ADDR:-http://alist:5678}

echo "检查alist连通性..."
while ! curl --silent --show-error --fail "${ALIST_ADDR}/api/public/settings" | grep -q 200; do
sleep 2
done

Expand Down
Loading