Last active
April 24, 2022 02:04
-
-
Save lancewf/584ca17c7b50cfc859e7cf544c1a67e8 to your computer and use it in GitHub Desktop.
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 | |
function start() { | |
install_if_missing core/busybox-static netstat; | |
netstat -an | grep $PORT | grep LISTEN >/dev/null 2>/dev/null | |
if [ $? == 0 ]; then | |
echo "$SERVICE_NAME is already running"; | |
return; | |
fi | |
build | |
if [ $? -ne 0 ]; then | |
return 1 | |
fi | |
start_binds | |
create_config | |
hab svc load $HAB_ORIGIN/$SERVICE_NAME $(get_binds) | |
wait_or_fail_for_port_to_listen $PORT | |
} | |
function start_binds() { | |
echo "no binds to start" | |
} | |
function get_binds() { | |
echo "" | |
} | |
function create_config_folders() { | |
if [ -z ${SERVICE_NAME+x} ]; then | |
echo "set the SERVICE_NAME" | |
return 1 | |
fi | |
mkdir -p /hab/user/$SERVICE_NAME/config/ | |
} | |
function write_config_file() { | |
if [ -z ${SERVICE_NAME+x} ]; then | |
echo "set the SERVICE_NAME" | |
return 1 | |
fi | |
printf "$@" > /hab/user/$SERVICE_NAME/config/user.toml | |
} | |
function append_config_file() { | |
if [ -z ${SERVICE_NAME+x} ]; then | |
echo "set the SERVICE_NAME" | |
return 1 | |
fi | |
printf "$@" >> /hab/user/$SERVICE_NAME/config/user.toml | |
} | |
function build_load() { | |
if [ -z ${SERVICE_NAME+x} ]; then | |
echo "set the SERVICE_NAME" | |
return 1 | |
fi | |
build | |
if [ $? -ne 0 ]; then | |
return 1 | |
fi | |
hab svc unload $HAB_ORIGIN/$SERVICE_NAME | |
sleep 3 | |
hab svc load $HAB_ORIGIN/$SERVICE_NAME $(get_binds) | |
} | |
document "kill_running_service" <<DOC | |
This kills the running service. Where hab sup should restart. | |
DOC | |
function kill_running_service() { | |
if [ -z ${SERVICE_NAME+x} ]; then | |
echo "set the SERVICE_NAME" | |
return 1 | |
fi | |
install_if_missing core/busybox-static pgrep >/dev/null | |
SERVICE_PID=$(pgrep $SERVICE_NAME) | |
if [[ -n ${SERVICE_PID} ]]; then | |
kill $SERVICE_PID | |
fi | |
} | |
# Saves the in memory bash history to a file | |
function save_history() { | |
history -a /src/.bash_history | |
} | |
# if .studiorc is being sourced from an already running studio, don't reset bash | |
# history -- this is achieved by saving the current history before it is re-read | |
save_history | |
# Load the bash history from a file | |
history -r /src/.bash_history | |
function cleanup() { | |
save_history | |
} | |
# When exiting the studio save the bash history to a file | |
trap cleanup EXIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment