apparmor.systemd 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/sh
  2. # ----------------------------------------------------------------------
  3. # Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of version 2 of the GNU General Public
  7. # License published by the Free Software Foundation.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, contact Novell, Inc.
  16. # ----------------------------------------------------------------------
  17. APPARMOR_FUNCTIONS=/lib/apparmor/rc.apparmor.functions
  18. aa_action()
  19. {
  20. echo "$1"
  21. shift
  22. "$@"
  23. return $?
  24. }
  25. aa_log_warning_msg()
  26. {
  27. echo "Warning: $*"
  28. }
  29. aa_log_failure_msg()
  30. {
  31. echo "Error: $*"
  32. }
  33. aa_log_action_start()
  34. {
  35. echo "$@"
  36. }
  37. aa_log_action_end()
  38. {
  39. printf ""
  40. }
  41. aa_log_daemon_msg()
  42. {
  43. echo "$@"
  44. }
  45. aa_log_skipped_msg()
  46. {
  47. echo "Skipped: $*"
  48. }
  49. aa_log_end_msg()
  50. {
  51. printf ""
  52. }
  53. # source apparmor function library
  54. if [ -f "${APPARMOR_FUNCTIONS}" ]; then
  55. # shellcheck source=rc.apparmor.functions
  56. . "${APPARMOR_FUNCTIONS}"
  57. else
  58. aa_log_failure_msg "Unable to find AppArmor initscript functions"
  59. exit 1
  60. fi
  61. case "$1" in
  62. start)
  63. if [ -x /usr/bin/systemd-detect-virt ] && \
  64. systemd-detect-virt --quiet --container && \
  65. ! is_container_with_internal_policy; then
  66. aa_log_daemon_msg "Not starting AppArmor in container"
  67. aa_log_end_msg 0
  68. exit 0
  69. fi
  70. apparmor_start
  71. rc=$?
  72. ;;
  73. stop)
  74. apparmor_stop
  75. rc=$?
  76. ;;
  77. restart|reload|force-reload)
  78. if [ -x /usr/bin/systemd-detect-virt ] && \
  79. systemd-detect-virt --quiet --container && \
  80. ! is_container_with_internal_policy; then
  81. aa_log_daemon_msg "Not starting AppArmor in container"
  82. aa_log_end_msg 0
  83. exit 0
  84. fi
  85. apparmor_restart
  86. rc=$?
  87. ;;
  88. try-restart)
  89. apparmor_try_restart
  90. rc=$?
  91. ;;
  92. kill)
  93. apparmor_kill
  94. rc=$?
  95. ;;
  96. status)
  97. apparmor_status
  98. rc=$?
  99. ;;
  100. *)
  101. exit 1
  102. ;;
  103. esac
  104. exit "$rc"