salt.install 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Salt: Installer: Arch
  2. # Maintainer: Niels Abspoel
  3. pre_install(){
  4. # create salt user
  5. getent passwd salt &>/dev/null || \
  6. echo "salt master user doesn't exist, creating..."; \
  7. useradd -r -d /srv/salt -s /sbin/nologin -c "Salt" salt &>/dev/null || :
  8. }
  9. pre_upgrade () {
  10. pre_install
  11. salthomedir=`getent passwd salt | cut -d: -f6`
  12. saltdir=/srv/salt/
  13. if [[ $salthomedir != $saltdir ]]; then
  14. echo "setting salt master user homedir to /srv/salt/"
  15. usermod -d /srv/salt/ salt &>/dev/null || :
  16. fi
  17. }
  18. post_install() {
  19. # set user permissions on directories needed for salt
  20. getent passwd salt &>/dev/null && chown -R salt /var/cache/salt
  21. getent passwd salt &>/dev/null && chown -R salt /var/log/salt
  22. getent passwd salt &>/dev/null && chown -R salt /etc/salt/pki
  23. getent passwd salt &>/dev/null && chown -R salt /srv/salt
  24. # set salt master user in config
  25. # and verify environment
  26. if [[ ! -f /etc/salt/master.d/salt-user.conf ]]; then
  27. if [[ ! -d /etc/salt/master.d ]]; then
  28. mkdir -p /etc/salt/master.d
  29. fi
  30. echo "configure salt-master to run as salt master user"
  31. cat << EOF1 > /etc/salt/master.d/salt-user.conf
  32. user: salt
  33. verify_env: True
  34. EOF1
  35. fi
  36. # set salt user limits
  37. if [[ ! -f /etc/security/limits.d/20-salt.conf ]]; then
  38. echo "raising file limits for salt master user"
  39. cat << EOF2 > /etc/security/limits.d/20-salt.conf
  40. salt soft nofile 100000
  41. salt hard nofile 100000
  42. EOF2
  43. fi
  44. }
  45. post_upgrade () {
  46. # if salt-master/salt-minion daemon is running reinitialise
  47. if [[ -f /var/run/salt-master.pid ]]; then
  48. if [ "`systemctl is-active salt-master`" == "active" ]; then
  49. echo "salt-master is running system daemons are reloaded"
  50. getent passwd salt &>/dev/null && systemctl daemon-reexec
  51. getent passwd salt &>/dev/null && systemctl daemon-reload
  52. fi
  53. fi
  54. if [[ -f /var/run/salt-minion.pid ]]; then
  55. if [ "`systemctl is-active salt-minion`" == "active" ]; then
  56. echo "salt-minion was running system daemons are reloaded"
  57. getent passwd salt &>/dev/null && systemctl daemon-reexec
  58. getent passwd salt &>/dev/null && systemctl daemon-reload
  59. fi
  60. fi
  61. }
  62. pre_remove (){
  63. # Stop salt-master daemon and remove it
  64. if [[ -f /var/run/salt-master.pid ]]; then
  65. if [ "`systemctl is-active salt-master`" == "active" ]; then
  66. echo "stopping salt-master and removing it"
  67. systemctl stop salt-master
  68. systemctl disable salt-master
  69. fi
  70. fi
  71. # Stop salt-minion daemon and remove it
  72. if [[ -f /var/run/salt-minion.pid ]]; then
  73. if [ "`systemctl is-active salt-minion`" == "active" ]; then
  74. echo "stopping salt-minion and removing it"
  75. systemctl stop salt-minion
  76. systemctl disable salt-minion
  77. fi
  78. fi
  79. }
  80. post_remove (){
  81. # remove shared job cache and other runtime directories
  82. rm -rf \
  83. /var/cache/salt \
  84. /var/log/salt \
  85. 2> /dev/null
  86. echo "shared job cache and runtime directories removed"
  87. # remove salt user and group but leave /srv/salt
  88. getent passwd salt &>/dev/null && userdel salt && echo "salt master user removed"
  89. echo "salt has been removed but /srv/salt is still available"
  90. }
  91. op=$1
  92. shift
  93. $op "$@"