Skip to content

Instantly share code, notes, and snippets.

@tissak
Last active August 17, 2023 14:36
Show Gist options
  • Select an option

  • Save tissak/afb5ca401129049c0f3f1272d69a1e47 to your computer and use it in GitHub Desktop.

Select an option

Save tissak/afb5ca401129049c0f3f1272d69a1e47 to your computer and use it in GitHub Desktop.
runpod_start.sh
#!/bin/bash
set -e # Exit the script if any statement returns a non-true return value
# ---------------------------------------------------------------------------- #
# Function Definitions #
# ---------------------------------------------------------------------------- #
# Start nginx service
start_nginx() {
echo "Starting Nginx service..."
service nginx start
}
# Execute script if exists
execute_script() {
local script_path=$1
local script_msg=$2
if [[ -f ${script_path} ]]; then
echo "${script_msg}"
bash ${script_path}
fi
}
# Setup ssh
setup_ssh() {
if [[ $PUBLIC_KEY ]]; then
echo "Setting up SSH..."
mkdir -p ~/.ssh
echo "$PUBLIC_KEY" >> ~/.ssh/authorized_keys
chmod 700 -R ~/.ssh
service ssh start
fi
}
# Export env vars
export_env_vars() {
echo "Exporting environment variables..."
printenv | grep -E '^RUNPOD_|^PATH=|^_=' | awk -F = '{ print "export " $1 "=\"" $2 "\"" }' >> /etc/rp_environment
echo 'source /etc/rp_environment' >> ~/.bashrc
}
# ---------------------------------------------------------------------------- #
# Main Program #
# ---------------------------------------------------------------------------- #
start_nginx
execute_script "/pre_start.sh" "Running pre-start script..."
echo "Pod Started"
setup_ssh
export_env_vars
execute_script "/post_start.sh" "Running post-start script..."
sleep infinity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment