This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
forked from spinnaker/halyard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- version-1.23.2
- version-1.23.1
- version-1.23.0
- version-1.22.2
- version-1.22.1
- version-1.22.0
- version-1.21.2
- version-1.21.1
- version-1.21.0
- version-1.20.2
- version-1.20.1
- version-1.20.0
- version-1.19.2
- version-1.19.1
- version-1.19.0
- version-1.18.0
- version-1.17.0
- version-1.16.0
- version-1.15.0
- version-1.14.0
- version-1.13.1
- version-1.13.0
- version-1.12.0
- version-1.11.0
- version-1.10.1
- version-1.10.0
- version-1.9.1
- version-1.9.0
- version-1.8.0
- version-1.7.0
- version-1.6.0
- version-1.5.0
- version-1.4.0
- version-1.3.0
- version-1.2.0
- version-1.1.0
- version-1.0.0
- version-0.49.0
- version-0.48.0
- version-0.47.0
- version-0.46.0
- version-0.45.0
- version-0.44.0
- version-0.43.1
- version-0.43.0
- version-0.42.0
- version-0.41.0
- version-0.40.0
- version-0.39.0
- version-0.38.0
- version-0.37.0
- version-0.35.0
- version-0.34.0
- v0.36.0
- v0.35.0
- v0.34.0
- v0.33.0
- v0.32.0
- v0.31.0
- v0.30.0
- 0.37.0
Showing
4 changed files
with
263 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
function process_args() { | ||
while [ "$#" -gt "0" ] | ||
do | ||
local key="$1" | ||
shift | ||
case $key in | ||
--user) | ||
echo "user" | ||
HAL_USER="$1" | ||
shift | ||
;; | ||
--version) | ||
echo "version" | ||
HALYARD_VERSION="$1" | ||
shift | ||
;; | ||
-y) | ||
echo "non-interactive" | ||
YES=true | ||
;; | ||
--help|-help|-h) | ||
print_usage | ||
exit 13 | ||
;; | ||
*) | ||
echo "ERROR: Unknown argument '$key'" | ||
exit -1 | ||
esac | ||
done | ||
} | ||
|
||
function get_user() { | ||
local user | ||
|
||
user=$(who -m | awk '{print $1;}') | ||
if [ -z "$YES" ]; then | ||
if [ "$user" = "root" ] || [ -z "$user" ]; then | ||
read -p "Please supply a non-root user to run Halyard as: " user | ||
fi | ||
fi | ||
|
||
echo $user | ||
} | ||
|
||
function configure_defaults() { | ||
if [ -z "$HAL_USER" ]; then | ||
HAL_USER=$(get_user) | ||
fi | ||
|
||
if [ -z "$HAL_USER" ]; then | ||
>&2 echo "You have not supplied a user to run Halyard as." | ||
exit 1 | ||
fi | ||
|
||
if [ "$HAL_USER" = "root" ]; then | ||
>&2 echo "Halyard may not be run as root. Supply a user to run Halyard as: " | ||
>&2 echo " sudo bash $0 --user <user>" | ||
exit 1 | ||
fi | ||
|
||
set +e | ||
getent passwd $HAL_USER &> /dev/null | ||
|
||
if [ "$?" != "0" ]; then | ||
>&2 echo "Supplied user $HAL_USER does not exist" | ||
exit 1 | ||
fi | ||
set -e | ||
|
||
if [ -z "$HALYARD_VERSION" ]; then | ||
HALYARD_VERSION="stable" | ||
fi | ||
|
||
echo "$(tput bold)Halyard version will be $HALYARD_VERSION $(tput sgr0)" | ||
|
||
home=$(getent passwd $HAL_USER | cut -d: -f6) | ||
local halconfig_dir="$home/.hal" | ||
|
||
echo "$(tput bold)Halconfig will be stored at $halconfig_dir/config$(tput sgr0)" | ||
|
||
mkdir -p $halconfig_dir | ||
chown $HAL_USER $halconfig_dir | ||
|
||
mkdir -p /opt/spinnaker/config | ||
chmod +rx /opt/spinnaker/config | ||
|
||
cat > /opt/spinnaker/config/halyard.yml <<EOL | ||
halyard: | ||
halconfig: | ||
directory: $halconfig_dir | ||
spinnaker: | ||
artifacts: | ||
debianRepository: $SPINNAKER_REPOSITORY_URL | ||
dockerRegistry: $SPINNAKER_DOCKER_REGISTRY | ||
googleImageProject: $SPINNAKER_GCE_PROJECT | ||
EOL | ||
|
||
echo $HAL_USER > /opt/spinnaker/config/halyard-user | ||
|
||
cat > $halconfig_dir/uninstall.sh <<EOL | ||
#!/usr/bin/env bash | ||
if [[ `/usr/bin/id -u` -ne 0 ]]; then | ||
echo "$0 must be executed with root permissions; exiting" | ||
exit 1 | ||
fi | ||
read -p "This script uninstalls Halyard and deletes all of its artifacts, are you sure you want to continue? (Y/n): " yes | ||
if [ "\$yes" != "y" ] && [ "\$yes" != "Y" ]; then | ||
echo "Aborted" | ||
exit 0 | ||
fi | ||
rm /opt/halyard -rf | ||
rm /var/log/spinnaker/halyard -rf | ||
echo "Deleting halconfig and artifacts" | ||
rm $staging -rf | ||
rm /opt/spinnaker/config/halyard* -rf | ||
rm $halconfig_dir -rf | ||
EOL | ||
|
||
chmod +x $halconfig_dir/uninstall.sh | ||
echo "$(tput bold)Uninstall script is located at $halconfig_dir/uninstall.sh$(tput sgr0)" | ||
} | ||
|
||
|
||
function print_usage() { | ||
cat <<EOF | ||
usage: $0 [-y] [--version=<version>] [--user=<user>] | ||
-y Accept all default options during install | ||
(non-interactive mode). | ||
--version <version> Specify the exact verison of Halyard to | ||
install. | ||
--user <user> Specify the user to run Halyard as. This | ||
user must exist. | ||
EOF | ||
} | ||
|
||
function install_java() { | ||
set +e | ||
local java_version=$(java -version 2>&1 head -1) | ||
set -e | ||
|
||
if [[ "$java_version" == "*1.8*" ]]; then | ||
echo "Java is already installed & at the right version" | ||
return 0; | ||
fi | ||
|
||
>&2 echo "Java 8 not yet installed - please install java 8." | ||
>&2 echo " Try using brew or jenv" | ||
exit 1 | ||
} | ||
|
||
function install_halyard() { | ||
TEMPDIR=$(mktemp -d installhalyard.XXXX) | ||
pushd $TEMPDIR | ||
|
||
curl -O https://storage.googleapis.com/spinnaker-artifacts/halyard/$HALYARD_VERSION/osx/halyard.tar.gz | ||
tar -xvf halyard.tar.gz -C /opt | ||
|
||
groupadd halyard | ||
usermod -G halyard $HAL_USER | ||
chown $HAL_USER:halyard /opt/halyard | ||
|
||
mv /opt/hal /usr/local/bin | ||
chmod +x /usr/local/bin/hal | ||
|
||
mkdir -p /var/log/spinnaker/halyard | ||
chown $HAL_USER /var/log/spinnaker/halyard | ||
chmod 755 /var/log/spinnaker/halyard | ||
|
||
popd | ||
rm -rf $TEMPDIR | ||
} | ||
|
||
process_args $@ | ||
configure_defaults | ||
|
||
install_java | ||
install_halyard | ||
|
||
su -c "hal -v" -s /bin/bash $HAL_USER |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
tar -cvf halyard.tar.gz -C halyard-web/build/install halyard/ -C ../../../startup/osx hal |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
HALYARD_DAEMON_PID_FILE=/opt/halyard/pid | ||
HALYARD_DAEMON_PID="" | ||
HALYARD_STARTUP_TIMEOUT_SECONDS=120 | ||
|
||
HAL=/opt/halyard/bin/hal | ||
|
||
function start_daemon() { | ||
printf "The halyard daemon isn't running yet... starting it manually" | ||
|
||
/opt/halyard/bin/halyard \ | ||
2> /var/log/spinnaker/halyard/halyard.err \ | ||
> /var/log/spinnaker/halyard/halyard.log & | ||
|
||
echo $! > $HALYARD_DAEMON_PID_FILE | ||
|
||
local wait_start=$(date +%s) | ||
|
||
set +e | ||
$HAL --ready &> /dev/null | ||
while [ "$?" != "0" ]; do | ||
local wait_now=$(date +%s) | ||
local wait_time=$(( $wait_now - $wait_start )) | ||
|
||
if [ "$wait_time" -gt "$HALYARD_STARTUP_TIMEOUT_SECONDS" ]; then | ||
>&2 echo "" | ||
>&2 echo "Waiting for halyard to start timed out after $wait_time seconds" | ||
exit 1 | ||
fi | ||
|
||
printf '.' | ||
sleep 2 | ||
$HAL --ready &> /dev/null | ||
done | ||
set -e | ||
|
||
echo "" | ||
} | ||
|
||
function kill_daemon() { | ||
pkill -f '/opt/halyard/lib/halyard-web' || true | ||
} | ||
|
||
if [ -f "$HALYARD_DAEMON_PID_FILE" ]; then | ||
HALYARD_DAEMON_PID=$(cat $HALYARD_DAEMON_PID_FILE) | ||
fi | ||
|
||
if [ -z "$HALYARD_DAEMON_PID" ]; then | ||
kill_daemon | ||
start_daemon | ||
else | ||
set +e | ||
ps $HALYARD_DAEMON_PID &> /dev/null | ||
exit_code=$? | ||
set -e | ||
|
||
if [ "$exit_code" != "0" ]; then | ||
kill_daemon | ||
start_daemon | ||
fi | ||
fi | ||
|
||
$HAL $@ |