Here is a Bash script for installing Hawiyat on a Linux server. Make sure you run this as root on a Linux environment that is not a container, and ensure ports 80 and 443 are free.
#!/bin/bash# Ensure the script is run as rootif [ "$(id -u)" != "0" ]; then echo "This script must be run as root" >&2 exit 1fi# Check for Linux OS (not macOS or inside a Docker container)if [ "$(uname)" = "Darwin" ]; then echo "This script must be run on Linux" >&2 exit 1fiif [ -f /.dockerenv ]; then echo "This script must be run on a native Linux host" >&2 exit 1fi# Check for occupied portsif ss -tulnp | grep ':80 ' >/dev/null; then echo "Error: Port 80 is already in use" >&2 exit 1fiif ss -tulnp | grep ':443 ' >/dev/null; then echo "Error: Port 443 is already in use" >&2 exit 1fi# Function to check if a command existscommand_exists() { command -v "$@" > /dev/null 2>&1}# Install Docker if it is not installedif command_exists docker; then echo "Docker already installed"else curl -sSL https://get.docker.com | shfi# Initialize Docker Swarmdocker swarm leave --force 2>/dev/nulladvertise_addr=$(curl -s ifconfig.me)docker swarm init --advertise-addr $advertise_addrecho "Swarm initialized"# Create networkdocker network rm -f hawiyat-network 2>/dev/nulldocker network create --driver overlay --attachable hawiyat-networkecho "Network created"# Prepare configuration directorymkdir -p /etc/hawiyatchmod -R 777 /etc/hawiyat# Pull and deploy hawiyatdocker pull hawiyat/hawiyat:latestdocker service create \ --name hawiyat \ --replicas 1 \ --network hawiyat-network \ --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \ --mount type=bind,source=/etc/hawiyat,target=/etc/hawiyat \ --publish published=3000,target=3000,mode=host \ --update-parallelism 1 \ --update-order stop-first \ -e PORT=<Value For PORT eg(3000)> \ -e TRAEFIK_SSL_PORT=<Value For SSL PORT eg(444)> \ -e TRAEFIK_PORT=<VALUE FOR TRAEFIK HTTP PORT eg(81)> \ hawiyat/hawiyat:latest# Output success messageGREEN="\033[0;32m"YELLOW="\033[1;33m"BLUE="\033[0;34m"NC="\033[0m" # No Colorprintf "${GREEN}Congratulations, hawiyat is installed!${NC}\n"printf "${BLUE}Wait 15 seconds for the server to start${NC}\n"printf "${YELLOW}Please go to http://${advertise_addr}:3000${NC}\n\n"
This script includes checks for common pitfalls, installs Docker if it’s not already installed, initializes a Docker Swarm, creates a network, and then pulls and deploys hawiyat. After the script runs, it provides a success message and instructions for accessing hawiyat.
This structured format clearly lays out the prerequisites, steps, and post-installation information, making it user-friendly and accessible for those performing manual installations.
The --advertise-addr parameter in the docker swarm init command specifies the IP address or interface that the Docker Swarm manager node should advertise to other nodes in the Swarm. This address is used by other nodes to communicate with the manager.
By default, this script uses the external IP address of the server, obtained using the curl -s ifconfig.me command. However, you might need to customize this address based on your network configuration, especially if your server has multiple network interfaces or if you're setting up Swarm in a private network.
To customize the --advertise-addr parameter, replace the line: advertise_addr=$(curl -s ifconfig.me) with your desired IP address or interface, for example:
advertise_addr="192.168.1.100"
:warning: This IP address should be accessible to all nodes that will join the Swarm.