summarylogtreecommitdiffstats
path: root/anythingllm.install
blob: 6e49f21ed51d56c14606b8c03e522104340681cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
post_install() {
    # Create system user / group via sysusers
    systemd-sysusers anythingllm.conf 2>/dev/null || true

    # Initialise tmpfiles (directories + permissions)
    systemd-tmpfiles --create anythingllm.conf 2>/dev/null || true

    # Fix app permissions
    chown -R anythingllm:anythingllm /srv/anythingllm
    chmod -R 0750 /srv/anythingllm

    echo ""
    echo "╔══════════════════════════════════════════════════════════════╗"
    echo "║              AnythingLLM has been installed                  ║"
    echo "╚══════════════════════════════════════════════════════════════╝"
    echo ""
    echo ">> 1. Review (and optionally pre-configure) the environment file:"
    echo ">>    /etc/anythingllm/server.env"
    echo ""
    echo ">> 2. Enable and start both services (migrations run automatically):"
    echo ">>    $ systemctl enable --now anythingllm-server anythingllm-collector"
    echo ""
    echo ">> 3. Open http://localhost:3001 and complete the setup wizard."
    echo ""
    echo ">> Logs:"
    echo ">>   /var/log/anythingllm/server.log"
    echo ">>   /var/log/anythingllm/collector.log"
    echo ""
}

pre_upgrade() {
    # Stop services so no files are held open during the upgrade
    systemctl stop anythingllm-collector.service 2>/dev/null || true
    systemctl stop anythingllm-server.service    2>/dev/null || true

    # ── Wipe the application directories ─────────────────────────────────────
    # node_modules trees accumulate stale packages across upgrades because
    # pacman only adds/replaces tracked files — it never removes files that
    # were present in the old package but absent from the new one.
    # Deleting these dirs here guarantees a clean slate before pacman
    # extracts the freshly-built package contents on top.
    #
    # /var/lib/anythingllm (user data) and /etc/anythingllm (config) are
    # intentionally NOT touched here.
    rm -rf /srv/anythingllm/server
    rm -rf /srv/anythingllm/collector
}

post_upgrade() {
    # Fix app permissions
    chown -R anythingllm:anythingllm /srv/anythingllm
    chmod -R 0750 /srv/anythingllm

    echo ""
    echo ">> AnythingLLM has been upgraded."
    echo ""
    echo ">> Restart the services (migrations run automatically on server start):"
    echo ">> $ systemctl restart anythingllm-server anythingllm-collector"
    echo ""
}

pre_remove() {
    # Stop and disable services before files are removed
    systemctl stop  anythingllm-collector.service 2>/dev/null || true
    systemctl stop  anythingllm-server.service    2>/dev/null || true
    systemctl disable anythingllm-server.service \
                      anythingllm-collector.service 2>/dev/null || true
}

post_remove() {
    echo ">> Removing service account..."
    userdel anythingllm

    echo ""
    echo ">> AnythingLLM has been removed."
    echo ""
    echo ">> Your data and configuration have been preserved:"
    echo ">>   /etc/anythingllm      – environment configuration"
    echo ">>   /var/lib/anythingllm  – storage, database, vectors"
    echo ">>   /var/log/anythingllm  – log files"
    echo ""
    echo ">> Remove them manually if you no longer need them:"
    echo ">> $ rm -rf /var/lib/anythingllm /etc/anythingllm /var/log/anythingllm"
}