123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- # Salt: Installer: Arch
- # Maintainer: Niels Abspoel
- pre_install(){
- # create salt user
- getent passwd salt &>/dev/null || \
- echo "salt master user doesn't exist, creating..."; \
- useradd -r -d /srv/salt -s /sbin/nologin -c "Salt" salt &>/dev/null || :
- }
- pre_upgrade () {
- pre_install
- salthomedir=`getent passwd salt | cut -d: -f6`
- saltdir=/srv/salt/
- if [[ $salthomedir != $saltdir ]]; then
- echo "setting salt master user homedir to /srv/salt/"
- usermod -d /srv/salt/ salt &>/dev/null || :
- fi
- }
- post_install() {
- # set user permissions on directories needed for salt
- getent passwd salt &>/dev/null && chown -R salt /var/cache/salt
- getent passwd salt &>/dev/null && chown -R salt /var/log/salt
- getent passwd salt &>/dev/null && chown -R salt /etc/salt/pki
- getent passwd salt &>/dev/null && chown -R salt /srv/salt
- # set salt master user in config
- # and verify environment
- if [[ ! -f /etc/salt/master.d/salt-user.conf ]]; then
- if [[ ! -d /etc/salt/master.d ]]; then
- mkdir -p /etc/salt/master.d
- fi
- echo "configure salt-master to run as salt master user"
- cat << EOF1 > /etc/salt/master.d/salt-user.conf
- user: salt
- verify_env: True
- EOF1
- fi
- # set salt user limits
- if [[ ! -f /etc/security/limits.d/20-salt.conf ]]; then
- echo "raising file limits for salt master user"
- cat << EOF2 > /etc/security/limits.d/20-salt.conf
- salt soft nofile 100000
- salt hard nofile 100000
- EOF2
- fi
- }
- post_upgrade () {
- # if salt-master/salt-minion daemon is running reinitialise
- if [[ -f /var/run/salt-master.pid ]]; then
- if [ "`systemctl is-active salt-master`" == "active" ]; then
- echo "salt-master is running system daemons are reloaded"
- getent passwd salt &>/dev/null && systemctl daemon-reexec
- getent passwd salt &>/dev/null && systemctl daemon-reload
- fi
- fi
- if [[ -f /var/run/salt-minion.pid ]]; then
- if [ "`systemctl is-active salt-minion`" == "active" ]; then
- echo "salt-minion was running system daemons are reloaded"
- getent passwd salt &>/dev/null && systemctl daemon-reexec
- getent passwd salt &>/dev/null && systemctl daemon-reload
- fi
- fi
- }
- pre_remove (){
- # Stop salt-master daemon and remove it
- if [[ -f /var/run/salt-master.pid ]]; then
- if [ "`systemctl is-active salt-master`" == "active" ]; then
- echo "stopping salt-master and removing it"
- systemctl stop salt-master
- systemctl disable salt-master
- fi
- fi
- # Stop salt-minion daemon and remove it
- if [[ -f /var/run/salt-minion.pid ]]; then
- if [ "`systemctl is-active salt-minion`" == "active" ]; then
- echo "stopping salt-minion and removing it"
- systemctl stop salt-minion
- systemctl disable salt-minion
- fi
- fi
- }
- post_remove (){
- # remove shared job cache and other runtime directories
- rm -rf \
- /var/cache/salt \
- /var/log/salt \
- 2> /dev/null
- echo "shared job cache and runtime directories removed"
- # remove salt user and group but leave /srv/salt
- getent passwd salt &>/dev/null && userdel salt && echo "salt master user removed"
- echo "salt has been removed but /srv/salt is still available"
- }
- op=$1
- shift
- $op "$@"
|