blob: ad2dd3d59c4e6050a88ad8ecac4c634bfb643e04 (
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#!/usr/bin/env bash
playbook_add() {
local dl_arch
local dl_baseurl
local dl_binary
local dl_version
local buffer
# Install seaweedfs
case "${BASHTARD_PLATFORM[arch]}" in
x86_64) dl_arch=amd64 ;;
*) die "NYI" ;;
esac
dl_baseurl="https://github.com/seaweedfs/seaweedfs/releases/download"
dl_binary="$(printf "%s_%s.tar.gz" "${BASHTARD_PLATFORM[os]}" "$dl_arch")"
dl_version="3.50"
buffer="$(tmpdir)"
chgdir "$buffer"
info "$BASHTARD_PLAYBOOK/add" "Fetching $dl_baseurl/$dl_version/$dl_binary"
curl -L "$dl_baseurl/$dl_version/$dl_binary" \
> "$dl_binary"
tar xzf "$dl_binary"
mv -v -- "weed" "$(config "fs.bindir")/weed"
# Create mount.weed symlink
ln -fsv "$(config "fs.bindir")/weed" "$(config "fs.bindir")/mount.weed"
# Generate systemd unit file
case "${BASHTARD_PLATFORM[init]}" in
systemd)
cat <<-EOF > "$(config "fs.etcdir")/systemd/system/seaweedfs.service"
[Unit]
Description=SeaweedFS
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=$(config "fs.bindir")/weed server -options="$(config "fs.etcdir")/seaweedfs/server.conf"
WorkingDirectory=/var/lib/seaweedfs
SyslogIdentifier=seaweedfs
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
;;
*) die "NYI"
esac
# Create directories
mkdir -pv -- "/var/lib/seaweedfs"
mkdir -pv -- "$(config "fs.etcdir")/seaweedfs"
# Perform initial configuration
playbook_sync
# Start the service
svc enable seaweedfs
svc start seaweedfs
}
playbook_sync() {
local buffer
local conf
buffer="$(tmpfile)"
conf="$(config "fs.etcdir")/seaweedfs/server.conf"
# Generate config file
file_template "server.conf" \
"datadir=/var/lib/seaweedfs" \
"ip=$(config "vpn-tinc.ipv4")" \
"volume_size=1024" \
"reserved_space=10GiB" \
> "$buffer"
if diff -q "$buffer" "$conf"
then
return
fi
mv -- "$buffer" "$conf"
[[ "$BASHTARD_ACTION" == "add" ]] && return
# Reload service
svc restart seaweedfs
}
playbook_del() {
# Stop service
svc stop seaweedfs
svc disable seaweedfs
# Remove systemd unit file
rm -fr -- "$(config "fs.etcdir")/systemd/system/seaweedfs.service"
# Remove configuration files
rm -fr -- "$(config "fs.etcdir")/seaweedfs"
# Remove downloaded binary and symlinks
rm -fr -- "$(config "fs.bindir")/weed"
rm -fr -- "$(config "fs.bindir")/mount.weed"
}
|