diff options
author | Patrick Spek <p.spek@tyil.nl> | 2024-03-05 11:52:17 +0100 |
---|---|---|
committer | Patrick Spek <p.spek@tyil.nl> | 2024-03-05 11:53:14 +0100 |
commit | d9b0af54b153c87a9474f9b3517c96bd2d5d50b4 (patch) | |
tree | 6529ac3e2f99cccbec8daa5656468d5b68752b76 /playbooks.d/seaweedfs-volume | |
parent | fa4bb126f713e221696aedf2f2ba636577132772 (diff) |
Add seaweedfs playbooks
Diffstat (limited to 'playbooks.d/seaweedfs-volume')
-rw-r--r-- | playbooks.d/seaweedfs-volume/description.txt | 1 | ||||
-rw-r--r-- | playbooks.d/seaweedfs-volume/etc/defaults | 1 | ||||
-rw-r--r-- | playbooks.d/seaweedfs-volume/playbook.bash | 104 | ||||
-rw-r--r-- | playbooks.d/seaweedfs-volume/share/volume.conf | 11 |
4 files changed, 117 insertions, 0 deletions
diff --git a/playbooks.d/seaweedfs-volume/description.txt b/playbooks.d/seaweedfs-volume/description.txt new file mode 100644 index 0000000..d14afca --- /dev/null +++ b/playbooks.d/seaweedfs-volume/description.txt @@ -0,0 +1 @@ +Scalable object storage cluster diff --git a/playbooks.d/seaweedfs-volume/etc/defaults b/playbooks.d/seaweedfs-volume/etc/defaults new file mode 100644 index 0000000..2578831 --- /dev/null +++ b/playbooks.d/seaweedfs-volume/etc/defaults @@ -0,0 +1 @@ +svc.seaweedfs-master=seaweedfs-master diff --git a/playbooks.d/seaweedfs-volume/playbook.bash b/playbooks.d/seaweedfs-volume/playbook.bash new file mode 100644 index 0000000..55e9d52 --- /dev/null +++ b/playbooks.d/seaweedfs-volume/playbook.bash @@ -0,0 +1,104 @@ +#!/usr/bin/env bash + +BASHTARD_PLAYBOOK_VARS[$BASHTARD_PLAYBOOK.dc]="required" +BASHTARD_PLAYBOOK_VARS[$BASHTARD_PLAYBOOK.ip]="required" +BASHTARD_PLAYBOOK_VARS[$BASHTARD_PLAYBOOK.rack]="required" + +playbook_add() { + local buffer + + # Make sure seaweedfs is installed + "$BASHTARD_BIN" add seaweedfs || true + + # Generate systemd unit files + case "${BASHTARD_PLATFORM[init]}" in + systemd) + cat <<-EOF > "$(config "fs.etcdir")/systemd/system/seaweedfs-volume@.service" + [Unit] + Description=SeaweedFS Volume + After=network.target + + [Service] + Type=simple + User=root + Group=root + + ExecStart=$(config "fs.bindir")/weed volume -options="$(config "fs.etcdir")/seaweedfs/volume-%i.conf" + WorkingDirectory=/var/lib/seaweedfs/volume/%i + SyslogIdentifier=seaweedfs + + [Install] + WantedBy=multi-user.target + EOF + ;; + *) die "NYI" + esac + + # Perform initial configuration + playbook_sync + + # Start services + while read -r volume + do + systemctl enable --now "seaweedfs-volume@$volume" + done < <(config_subkeys "$BASHTARD_PLAYBOOK.volumes") +} + +playbook_sync() { + local buffer + local conf + local peers=() + local hash + + buffer="$(tmpfile)" + + # Add all registered seaweedfs-master nodes as peers + while read -r host + do + peers+=("[$(config_for "$(basename "$host")" "seaweedfs-master.ip")]:$(config_for "$(basename "$host")" "seaweedfs-master.port" "9333")") + done < <(grep -FHl "seaweedfs-master" "$BASHTARD_ETCDIR/registry.d"/*) + + while read -r volume + do + conf="$(config "fs.etcdir")/seaweedfs/volume-$volume.conf" + hash="$(file_hash "$conf")" + + info "$BASHTARD_PLAYBOOK/sync/$volume" "Updating $conf" + + # Generate config file + file_template "volume.conf" \ + dc="$(config "$BASHTARD_PLAYBOOK.dc")" \ + dir="/var/lib/seaweedfs/volume/$volume" \ + disk="$(config "$BASHTARD_PLAYBOOK.volume.$volume.disk" "hdd")" \ + filesize_limit="$(config "$BASHTARD_PLAYBOOK.filesize-limit" "256")" \ + free_space="$(config "$BASHTARD_PLAYBOOK.free-space" "10")" \ + ip="$(config "$BASHTARD_PLAYBOOK.ip")" \ + mserver="$(join_args "${peers[@]}")" \ + port="$(config "$BASHTARD_PLAYBOOK.volume.$volume.port" "8080")" \ + rack="$(config "$BASHTARD_PLAYBOOK.rack")" \ + > "$buffer" + + # Write config file + [[ "$(file_hash "$buffer")" == "$hash" ]] && continue + info "$BASHTARD_PLAYBOOK/sync/$volume" "Configuration file changed" + mv -- "$buffer" "$conf" + + # Restart volume server + info "$BASHTARD_PLAYBOOK/sync/$volume" "Restarting volume $volume" + [[ "$BASHTARD_ACTION" == "sync" ]] && systemctl restart "seaweedfs-volume@$volume" + done < <(config_subkeys "$BASHTARD_PLAYBOOK.volumes") +} + +playbook_del() { + # Stop services + while read -r volume + do + systemctl disable --now "seaweedfs-volume@$volume" + done < <(config_subkeys "$BASHTARD_PLAYBOOK.volumes") + + # Remove systemd unit file + rm -fr -- "$(config "fs.etcdir")/systemd/system/seaweedfs-volume@.service" + + # Remove configuration files + rm -fr -- "$(config "fs.etcdir")/seaweedfs/volume.conf" +} diff --git a/playbooks.d/seaweedfs-volume/share/volume.conf b/playbooks.d/seaweedfs-volume/share/volume.conf new file mode 100644 index 0000000..3b0c816 --- /dev/null +++ b/playbooks.d/seaweedfs-volume/share/volume.conf @@ -0,0 +1,11 @@ +ip=[${ip}] +port=${port} +mserver=${mserver} + +dir=${dir} + +dataCenter=${dc} +rack=${rack} +disk=${disk} +fileSizeLimitMB=${filesize_limit} +minFreeSpace=${free_space} |