每天 Shaarli

一天内的所有链接,汇聚在一个页面上。

December 13, 2024

Note: AlpineLinux中的alist服务配置
#!/sbin/openrc-run

command="/service/alist/alist"
command_args="server"
name="alist"
description="AList file server"
directory="/service/alist"  

depend() {
    need net
}

start() {
    ebegin "Starting AList"

    # 检查 AList 是否已经在运行,如果运行则不启动
    if pgrep -f "$command $command_args" > /dev/null; then
        ebegin "AList is already running"
        eend 0
    else
        # 确保在正确的目录下启动 AList
        cd "$directory" && $command $command_args &

        # 等待进程启动并确认是否启动成功
        sleep 2
        if pgrep -f "$command $command_args" > /dev/null; then
            ebegin "AList is running"
            eend 0
        else
            ebegin "AList failed to start"
            tail -n 10 /var/log/messages
            eend 1
        fi
    fi
}

stop() {
    ebegin "Stopping AList"

    # 使用 pkill 来终止 AList 进程
    pkill -f "$command $command_args"
    eend $?
}

restart() {
    stop
    start
}
Note: AlpineLinux使用Alist

首先,安装git和pnpm:
https://git-scm.com/downloads/win

https://github.com/git-for-windows/git/releases/download/v2.47.1.windows.1/Git-2.47.1-64-bit.exe

npm install -g pnpm

然后编译Alist的前端:

git clone --recurse-submodules https://github.com/alist-org/alist-web.git

pnpm install && pnpm build

或者直接下载编译好的前端:

https://github.com/AlistGo/alist-web
https://github.com/AlistGo/alist-web/releases/tag/3.41.0

然后下载Alist的源码放进AlpineLinux中编译(记得把前端放入./alist-3.41.0/public/dist/):

https://github.com/AlistGo/alist/releases

https://github.com/AlistGo/alist/archive/refs/tags/v3.41.0.tar.gz

tar -zxvf v3.41.0.tar.gz

cd ./alist-3.41.0/

正常编译命令:

appName="alist"
builtAt="$(date +'%F %T %z')"
goVersion=$(go version | sed 's/go version //')
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
gitCommit=$(git log --pretty=format:"%h" -1)
version=$(git describe --long --tags --dirty --always)
webVersion=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/alist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
ldflags="\
-w -s \
-X 'github.com/alist-org/alist/v3/internal/conf.BuiltAt=$builtAt' \
-X 'github.com/alist-org/alist/v3/internal/conf.GoVersion=$goVersion' \
-X 'github.com/alist-org/alist/v3/internal/conf.GitAuthor=$gitAuthor' \
-X 'github.com/alist-org/alist/v3/internal/conf.GitCommit=$gitCommit' \
-X 'github.com/alist-org/alist/v3/internal/conf.Version=$version' \
-X 'github.com/alist-org/alist/v3/internal/conf.WebVersion=$webVersion' \
"
go build -ldflags="$ldflags" .

精简编译命令:

CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -trimpath
upx alist