compat.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (C) 2017, Suleyman POYRAZ (AquilaNipalensis)
  5. #
  6. # This program is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by the
  8. # Free Software Foundation; either version 2 of the License, or (at your
  9. # option) any later version. Please read the COPYING file.
  10. #
  11. import subprocess
  12. import sys
  13. import os
  14. # This script populates the /etc/init.d directory by creating symlinks to the
  15. # compat.py. This way, when /etc/init.d/<service_name> <action> is called, the symlink
  16. # delegates this transparently to the /bin/service command.
  17. # Usage:
  18. # python compat.py
  19. # /etc/init.d/samba start
  20. def wrap_service(package, op):
  21. cmd = ["service", package, op]
  22. return subprocess.call(cmd)
  23. def populate_initd():
  24. for name in os.listdir("/var/db/scom3/scripts/System.Service"):
  25. if not os.path.exists("/etc/init.d/%s" % name[:-3]):
  26. os.symlink("compat.py", "/etc/init.d/%s" % name[:-3])
  27. if __name__ == "__main__":
  28. myname = os.path.basename(sys.argv[0])
  29. if len(sys.argv) == 2:
  30. sys.exit(wrap_service(myname, sys.argv[1]))
  31. elif myname == "compat.py" and os.getuid() == 0:
  32. populate_initd()