Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wamy-Dev/fbbbad36d3ad3bfcc39589fb4ea88767 to your computer and use it in GitHub Desktop.
Save Wamy-Dev/fbbbad36d3ad3bfcc39589fb4ea88767 to your computer and use it in GitHub Desktop.
Install SeaweedFS on Ubuntu from source and run mount as service

This sucked.

Make sure to change the FILER variable, as well as the SAVE_DIR variable based on what you need.

This installs and runs the SeaweedFS binary from source on Ubuntu, then runs the mount as a service.

Make sure to use the updated Golang-go package, as it is down below. This will not compile on Ubuntu's current version of go which is outdated, and will give errors. (Ubuntu gives 1.13.8 by default).

#!/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."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment