service.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from comar.service import *
  2. import os
  3. serviceType = "server"
  4. serviceDefault = "on"
  5. serviceDesc = _({"en": "CUPS Printer Server",
  6. "tr": "CUPS Yazıcı Sunucusu"})
  7. serviceConf = "cups"
  8. PIDFILE = "/run/cups/cupsd.pid"
  9. @synchronized
  10. def start():
  11. # FIXME: After avahi before hal
  12. # startDependencies("avahi")
  13. # Load ppdev and lp drivers if wanted
  14. if config.get("LOAD_LP_MODULE") == "yes":
  15. os.system("/sbin/modprobe -q lp")
  16. os.system("/sbin/modprobe -q ppdev")
  17. startService(command="/usr/sbin/cupsd",
  18. donotify=True)
  19. os.system("pidof -o %PPID /usr/sbin/cupsd > " + PIDFILE)
  20. # Tell udevd to replay printer events
  21. # One for low-level usb
  22. os.system("udevadm trigger --subsystem-match=usb \
  23. --attr-match=bInterfaceClass=07 \
  24. --attr-match=bInterfaceSubClass=01 \
  25. --action=add")
  26. # One for usblp backend
  27. os.system("udevadm trigger --subsystem-match=usb \
  28. --property-match=DEVNAME=\"/dev/usb/lp*\" \
  29. --action=add")
  30. @synchronized
  31. def reload():
  32. if os.path.exists(PIDFILE):
  33. # 1 is SIGHUP
  34. os.kill(int(open(PIDFILE, "r").read().strip()), 1)
  35. @synchronized
  36. def stop():
  37. stopService(pidfile=PIDFILE, donotify=True)
  38. if os.path.isfile(PIDFILE): os.unlink(PIDFILE)
  39. def status():
  40. return isServiceRunning(pidfile=PIDFILE)