madiator-docker-runpod/container-template/start.sh

82 lines
2.2 KiB
Bash
Raw Permalink Normal View History

2024-06-16 13:37:34 +02:00
#!/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
for key_type in rsa dsa ecdsa ed25519; do
key_path="/etc/ssh/ssh_host_${key_type}_key"
if [ ! -f ${key_path} ]; then
ssh-keygen -t ${key_type} -f ${key_path} -q -N ''
echo "${key_type^^} key fingerprint:"
ssh-keygen -lf ${key_path}.pub
fi
done
service ssh start
echo "SSH host keys:"
for key in /etc/ssh/*.pub; do
echo "Key: $key"
ssh-keygen -lf $key
done
fi
}
# Export environment variables
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
}
# Start code-server
start_code_server() {
echo "Starting code-server..."
nohup code-server --bind-addr 0.0.0.0:7777 --auth none --disable-telemetry /workspace &> /code-server.log &
echo "code-server started"
}
# ---------------------------------------------------------------------------- #
# Main Program #
# ---------------------------------------------------------------------------- #
start_nginx
2024-07-11 17:13:59 +02:00
setup_ssh
2024-07-11 13:28:16 +02:00
start_code_server
2024-07-11 17:13:59 +02:00
export_env_vars
2024-06-16 13:37:34 +02:00
echo "Pod Started"
2024-07-14 14:52:14 +02:00
execute_script "/pre_start.sh" "Running post-start script..."
2024-06-16 13:37:34 +02:00
echo "Start script(s) finished, pod is ready to use."
sleep infinity