mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
9ad362fbde
Conflicts: - salt/states/kapacitor.py
115 lines
4.2 KiB
Bash
Executable File
115 lines
4.2 KiB
Bash
Executable File
#!/bin/bash
|
|
###############################################################################
|
|
#
|
|
# Title: Post Script for Salt Installation
|
|
# Authors: Shane Lee
|
|
# Date: December 2015
|
|
#
|
|
# Description: This script copies the minion config file and starts the salt
|
|
# service
|
|
#
|
|
# Requirements:
|
|
# - None
|
|
#
|
|
# Usage:
|
|
# This script is run as a part of the macOS Salt Installation
|
|
#
|
|
###############################################################################
|
|
echo "Post install started on:" > /tmp/postinstall.txt
|
|
date >> /tmp/postinstall.txt
|
|
trap 'quit_on_error $LINENO $BASH_COMMAND' ERR
|
|
|
|
quit_on_error() {
|
|
echo "$(basename $0) caught error on line : $1 command was: $2" >> /tmp/postinstall.txt
|
|
exit -1
|
|
}
|
|
|
|
###############################################################################
|
|
# Check for existing minion config, copy if it doesn't exist
|
|
###############################################################################
|
|
if [ ! -f /etc/salt/minion ]; then
|
|
echo "Config copy: Started..." >> /tmp/postinstall.txt
|
|
cp /etc/salt/minion.dist /etc/salt/minion
|
|
echo "Config copy: Successful" >> /tmp/postinstall.txt
|
|
fi
|
|
|
|
###############################################################################
|
|
# Create symlink to salt-config.sh
|
|
###############################################################################
|
|
# echo "Symlink: Creating symlink for salt-config..." >> /tmp/postinstall.txt
|
|
if [ ! -d "/usr/local/sbin" ]; then
|
|
mkdir /usr/local/sbin
|
|
fi
|
|
ln -sf /opt/salt/bin/salt-config.sh /usr/local/sbin/salt-config
|
|
|
|
###############################################################################
|
|
# Add salt to paths.d
|
|
###############################################################################
|
|
# echo "Path: Adding salt to the path..." >> /tmp/postinstall.txt
|
|
if [ ! -d "/etc/paths.d" ]; then
|
|
mkdir /etc/paths.d
|
|
fi
|
|
sh -c 'echo "/opt/salt/bin" > /etc/paths.d/salt'
|
|
sh -c 'echo "/usr/local/sbin" >> /etc/paths.d/salt'
|
|
|
|
###############################################################################
|
|
# Register Salt as a service
|
|
###############################################################################
|
|
setup_services_maverick() {
|
|
echo "Using old (< 10.10) launchctl interface" >> /tmp/postinstall.txt
|
|
if /bin/launchctl list "com.saltstack.salt.minion" &> /dev/null; then
|
|
echo "Stop running service..." >> /tmp/postinstall.txt
|
|
launchctl unload -w /Library/LaunchDaemons/com.saltstack.salt.minion.plist
|
|
fi;
|
|
launchctl load -w /Library/LaunchDaemons/com.saltstack.salt.minion.plist || return 1
|
|
|
|
echo "Service start: Successful" >> /tmp/postinstall.txt
|
|
|
|
echo "Service disable: Disabling Master, Syndic, and API" >> /tmp/postinstall.txt
|
|
|
|
launchctl unload -w /Library/LaunchDaemons/com.saltstack.salt.api.plist
|
|
launchctl unload -w /Library/LaunchDaemons/com.saltstack.salt.master.plist
|
|
launchctl unload -w /Library/LaunchDaemons/com.saltstack.salt.syndic.plist
|
|
|
|
return 0
|
|
}
|
|
|
|
setup_services_yosemite_and_later() {
|
|
echo "Using new (>= 10.10) launchctl interface" >> /tmp/postinstall.txt
|
|
launchctl enable system/com.saltstack.salt.minion
|
|
echo "Service start: Bootstrapping service..." >> /tmp/postinstall.txt
|
|
launchctl bootstrap system /Library/LaunchDaemons/com.saltstack.salt.minion.plist
|
|
|
|
if /bin/launchctl list "com.saltstack.salt.minion" &> /dev/null; then
|
|
echo "Service is running" >> /tmp/postinstall.txt
|
|
else
|
|
echo "Service start: Kickstarting service..." >> /tmp/postinstall.txt
|
|
launchctl kickstart -kp system/com.saltstack.salt.minion
|
|
fi
|
|
|
|
echo "Service start: Successful" >> /tmp/postinstall.txt
|
|
|
|
echo "Service disable: Disabling Master, Syndic, and API" >> /tmp/postinstall.txt
|
|
|
|
launchctl disable system/com.saltstack.salt.master
|
|
launchctl disable system/com.saltstack.salt.syndic
|
|
launchctl disable system/com.saltstack.salt.api
|
|
}
|
|
|
|
OSX_VERSION=$(sw_vers | grep ProductVersion | cut -f 2 -d: | tr -d '[:space:]')
|
|
MINOR=$(echo ${OSX_VERSION} | cut -f 2 -d.)
|
|
|
|
echo "Service start: Enabling service..." >> /tmp/postinstall.txt
|
|
case $MINOR in
|
|
9 )
|
|
setup_services_maverick;
|
|
;;
|
|
* )
|
|
setup_services_yosemite_and_later;
|
|
;;
|
|
esac
|
|
|
|
echo "Post install completed successfully" >> /tmp/postinstall.txt
|
|
|
|
exit 0
|