This sucked.
This installs and runs the SeaweedFS binary from source on Ubuntu, then runs the mount as a service.
This sucked.
This installs and runs the SeaweedFS binary from source on Ubuntu, then runs the mount as a service.
| #!/bin/bash | |
| set -e | |
| echo "Starting SeaweedFS installation and update script..." | |
| # CHANGE SEAWEED FILER, ex: 0.0.0.0:8888 | |
| FILER="" | |
| # SAVE DIRECTORY, ex: /mnt/storage (data will be saved at /mnt/storage/data) | |
| SAVE_DIR="" | |
| REPO_URL="https://github.com/seaweedfs/seaweedfs.git" | |
| CLONE_PATH="/tmp/seaweedfs" | |
| EXTRACT_PATH="/usr/local/bin" | |
| SERVICE_FILE="/etc/systemd/system/seaweedfs-mount.service" | |
| GOPATH="$HOME/go/bin" | |
| echo "Installing necessary dependencies..." | |
| # Assuming you're using a Debian/Ubuntu based system | |
| sudo apt-get update | |
| sudo apt-get install -y git build-essential curl wget jq | |
| echo "Fetching the latest stable Go version from go.dev..." | |
| sudo add-apt-repository ppa:longsleep/golang-backports -y | |
| sudo apt update | |
| sudo apt install -y golang-go | |
| export PATH="/usr/bin/go:$PATH" | |
| export GO111MODULE=on | |
| echo "Clearing Go module cache..." | |
| go clean -modcache | |
| echo "Checking if SeaweedFS service is running..." | |
| if systemctl is-active --quiet seaweedfs-mount; then | |
| echo "Stopping existing SeaweedFS service..." | |
| systemctl stop seaweedfs-mount | |
| systemctl disable seaweedfs-mount | |
| fi | |
| echo "Checking for existing SeaweedFS mounts..." | |
| if mount | grep -q "/mnt/storage"; then | |
| echo "Unmounting existing SeaweedFS mount at /mnt/storage..." | |
| umount /mnt/storage | |
| fi | |
| echo "Removing existing SeaweedFS repository directory if it exists..." | |
| if [ -d "$CLONE_PATH" ]; then | |
| rm -rf "$CLONE_PATH" | |
| fi | |
| echo "Cloning SeaweedFS repository..." | |
| git clone "$REPO_URL" "$CLONE_PATH" || { echo "Failed to clone repository"; exit 1; } | |
| echo "Building SeaweedFS from source..." | |
| echo "$CLONE_PATH/weed" | |
| cd "$CLONE_PATH/weed" | |
| make install || { echo "Failed to install SeaweedFS"; } | |
| echo "$GOPATH" | |
| sleep 5 | |
| mv "$GOPATH/weed" "$EXTRACT_PATH/weed" | |
| echo "Setting executable permissions for weed binary..." | |
| chmod +x "$EXTRACT_PATH/weed" | |
| echo "Creating systemd service file for SeaweedFS..." | |
| cat << EOF > "$SERVICE_FILE" | |
| [Unit] | |
| Description=SeaweedFS Mount | |
| After=network.target | |
| [Service] | |
| Type=simple | |
| User=root | |
| Group=root | |
| ExecStart=/usr/local/bin/weed mount -filer="$FILER" -dir="$SAVE_DIR" -filer.path=/ | |
| WorkingDirectory=/usr/local/bin | |
| SyslogIdentifier=seaweedfs-mount | |
| [Install] | |
| WantedBy=multi-user.target | |
| EOF | |
| if [ $? -ne 0 ]; then | |
| echo "Failed to create systemd service file" | |
| exit 1 | |
| fi | |
| echo "Reloading systemd daemon..." | |
| systemctl daemon-reload | |
| echo "Enabling and starting SeaweedFS service..." | |
| systemctl enable seaweedfs-mount | |
| systemctl start seaweedfs-mount | |
| echo "SeaweedFS Mount service updated, installed, and started successfully." |