Last active
March 15, 2024 21:37
-
-
Save HiceS/40092447e1dc81ec87e470fd8c4314de to your computer and use it in GitHub Desktop.
redis / docker setup quickly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# first make sure curl is installed with sudo apt install curl | |
# Exit immediately if a command exits with a non-zero status. | |
set -e | |
set +x | |
is_package_installed() { | |
local package=$1 | |
if dpkg -l "$package" &> /dev/null; then | |
return 0 | |
else | |
echo "$package not found installing now..." | |
return 1 | |
fi | |
} | |
# is the command existing on the linux server and available to be executed. | |
is_command_installed() { | |
local command=$1 | |
if command -v "$command" &> /dev/null; then | |
return 0 | |
else | |
echo "$command not found installing now..." | |
return 1 | |
fi | |
} | |
# is this service running ? | |
is_service_running() { | |
local service=$1 | |
if systemctl is-active --quiet "$service"; then | |
echo "$service is running." | |
return 0 | |
else | |
echo "$service is not running." | |
return 1 | |
fi | |
} | |
# will this service run on boot successfully ? | |
is_service_enabled() { | |
local service=$1 | |
if systemctl is-enabled --quiet "$service"; then | |
echo "$service is enabled." | |
return 0 # Service is enabled | |
else | |
echo "$service is not enabled." | |
return 1 # Service is not enabled | |
fi | |
} | |
configure_redis_for_external_access() { | |
local config_file="/etc/redis/redis.conf" | |
if [[ -e "$config_file" ]]; then | |
# Disable protected mode | |
sudo sed -i 's/^protected-mode yes/protected-mode no/' "$config_file" | |
# Set bind address to 0.0.0.0 | |
sudo sed -i 's/^bind 127.0.0.1/bind 0.0.0.0/' "$config_file" | |
echo "Redis configuration updated for external access." | |
else | |
echo "Redis config file not found." | |
return 1 | |
fi | |
} | |
# Update all package sources | |
# sudo apt-get update | |
# installing docker section | |
# if is_command_installed "docker"; then | |
# echo "Docker is installed skipping..." | |
# else | |
# sudo apt-get install ca-certificates curl gnupg | |
# sudo install -m 0755 -d /etc/apt/keyrings | |
# sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc | |
# echo \ | |
# "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ | |
# $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ | |
# sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
# sudo apt-get update | |
# sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | |
# echo "Docker is installed now." | |
# fi | |
# Start and enable Docker service | |
# if is_service_running "docker"; then | |
# echo "Docker service is already running" | |
# else | |
# echo "Starting docker service and enabling" | |
# sudo systemctl start docker | |
# sudo systemctl enable docker | |
# fi | |
# redis server install if necessary | |
if is_command_installed "redis-server"; then | |
echo "redis is installed, skipping..." | |
sudo ufw allow 6379 | |
configure_redis_for_external_access | |
else | |
# Install Redis | |
sudo apt install -y redis-server | |
sudo ufw allow 6379 | |
configure_redis_for_external_access | |
# Redis configuration (optional) | |
# Example: sudo sed -i 's/supervised no/supervised systemd/' /etc/redis/redis.conf | |
fi | |
if is_service_running "redis-server"; then | |
echo "redis service is already running skipping setup - restarting just in case..." | |
sudo systemctl restart redis-server | |
else | |
sudo systemctl enable redis-server | |
sudo systemctl start redis-server | |
echo "redis service is enabled and started" | |
fi | |
echo "Installation and configuration of YAMS completed successfully!" |
This will only really work for specific versions of ubuntu that this script was made for, seek elsewhere for a setup that includes osx and windows and debian.
It would be cool to do this for linertruck as well. At least for the public easy things.
Removed some of the docker stuff because it was no longer useful.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Execute :
curl -sSL https://gist.githubusercontent.com/HiceS/40092447e1dc81ec87e470fd8c4314de/raw/yams_setup.sh | sudo bash