rc.single 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #! /bin/sh -
  2. #
  3. # Single-user mode script
  4. #
  5. # Copyright (c) 2018, 2020 Matias Fonzo, <selk@dragora.org>.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. RC="[${0##*/}]" # To reflect the name of the script between [].
  19. IFS='
  20. '
  21. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
  22. LC_ALL=C
  23. echo ""
  24. echo "Entering to single-user mode ..."
  25. # Stop any quota file system (if needed)
  26. if grep -E -q -m 1 '(usr|grp)quota' /etc/fstab
  27. then
  28. echo "${RC}: Setting any quota file system to OFF"
  29. quotaoff -va
  30. fi
  31. # Be immune to the following signals
  32. trap "" HUP INT QUIT ABRT TERM
  33. echo "${RC}: Sending the HUP signal to all the processes"
  34. killall5 -1 -o $$
  35. sleep 7
  36. echo "${RC}: Sending the TERM signal to all the processes"
  37. killall5 -15 -o $$
  38. sleep 9
  39. exec telinit 1