systemd-sysv-install 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. # This script is called by "systemctl enable/disable" when the given unit is a
  3. # SysV init.d script. It needs to call the distribution's mechanism for
  4. # enabling/disabling those, such as chkconfig, update-rc.d, or similar. This
  5. # can optionally take a --root argument for enabling a SysV init script
  6. # in a chroot or similar.
  7. set -e
  8. usage() {
  9. echo "Usage: $0 [--root=path] enable|disable|is-enabled <sysv script name>" >&2
  10. exit 1
  11. }
  12. # parse options
  13. eval set -- "$(getopt -o r: --long root: -- "$@")"
  14. while true; do
  15. case "$1" in
  16. -r|--root)
  17. ROOT="$2"
  18. shift 2 ;;
  19. --) shift ; break ;;
  20. *) usage ;;
  21. esac
  22. done
  23. NAME="$2"
  24. [ -n "$NAME" ] || usage
  25. case "$1" in
  26. enable)
  27. # call the command to enable SysV init script $NAME here
  28. # (consider optional $ROOT)
  29. update-rc.d -f $NAME defaults
  30. ;;
  31. disable)
  32. # call the command to disable SysV init script $NAME here
  33. # (consider optional $ROOT)
  34. update-rc.d -f $NAME remove
  35. ;;
  36. is-enabled)
  37. # exit with 0 if $NAME is enabled, non-zero if it is disabled
  38. # (consider optional $ROOT)
  39. /etc/init.d/$NAME status
  40. ;;
  41. *)
  42. usage ;;
  43. esac