Fix preinstall and postinstall scripts

stops the service if running
starts the service after install
service names follow apple naming convention (com.saltstack.salt...)
This commit is contained in:
twangboy 2016-02-03 18:01:13 -07:00
parent 7ef723d815
commit 23d47722b7
7 changed files with 37 additions and 9 deletions

View file

@ -151,8 +151,8 @@ cp $PKGRESOURCES/*.rtf $PKGDIR/resources
# I can't get this to work for some reason
mkdir -p $PKGDIR/scripts
cp $PKGRESOURCES/scripts/postflight.sh $PKGDIR/scripts
cp $PKGRESOURCES/scripts/preflight.sh $PKGDIR/scripts
cp $PKGRESOURCES/scripts/postinstall $PKGDIR/scripts
cp $PKGRESOURCES/scripts/preinstall $PKGDIR/scripts
############################################################################
# Copy Config Files from Salt Repo to the Package Directory
@ -183,6 +183,7 @@ sed -i '' $SEDSTR distribution.xml
echo -n -e "\033]0;Build_Pkg: Build Package\007"
pkgbuild --root $PKGDIR \
--scripts $PKGDIR/scripts \
--identifier=com.saltstack.salt \
--version=$VERSION \
--ownership=recommended salt-src-$VERSION.pkg
@ -190,6 +191,5 @@ pkgbuild --root $PKGDIR \
productbuild --resources=$PKGDIR/resources \
--distribution=distribution.xml \
--package-path=salt-src-$VERSION.pkg \
--scripts $PKGDIR/scripts \
--version=$VERSION salt-$VERSION.pkg

View file

@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>Label</key>
<string>salt-api</string>
<string>com.saltstack.salt.api</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>

View file

@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>Label</key>
<string>salt-master</string>
<string>com.saltstack.salt.master</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>

View file

@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>Label</key>
<string>salt-minion</string>
<string>com.saltstack.salt.minion</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>

View file

@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>Label</key>
<string>salt-syndic</string>
<string>com.saltstack.salt.syndic</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>

View file

@ -15,16 +15,31 @@
# This script is run as a part of the OSX 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
###############################################################################
# Register Salt as a service
###############################################################################
set -e
echo "Service start: Started..." >> /tmp/postinstall.txt
launchctl load "/Library/LaunchDaemons/com.saltstack.salt.minion.plist"
echo "Service start: Successful" >> /tmp/postinstall.txt
echo "Post install completed successfully" >> /tmp/postinstall.txt
exit 0

View file

@ -15,11 +15,24 @@
# This script is run as a part of the OSX Salt Installation
#
###############################################################################
echo "Preinstall started on:" > /tmp/preinstall.txt
date >> /tmp/preinstall.txt
trap 'quit_on_error $LINENO $BASH_COMMAND' ERR
quit_on_error() {
echo "$(basename $0) caught error on line : $1 command was: $2" >> /tmp/preinstall.txt
exit -1
}
###############################################################################
# Stop the service
###############################################################################
set -e
if /bin/launchctl list "com.saltstack.salt.minion" &> /dev/null; then
echo "Stop service: Started..." >> /tmp/preinstall.txt
/bin/launchctl unload "/Library/LaunchDaemons/com.saltstack.salt.minion.plist"
echo "Stop service: Successful" >> /tmp/preinstall.txt
fi
echo "Preinstall Completed Successfully" >> /tmp/preinstall.txt
exit 0