service.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. from comar.service import *
  3. serviceType="server"
  4. serviceDesc = _({"en": "PostgreSQL Database Server",
  5. "tr": "PostgreSQL Veritabanı Sunucusu"})
  6. serviceConf = "postgresql"
  7. MSG_ERR_PGSQLNOTINST = _({"en": "PostgreSQL is not configured properly, please re-install the package.",
  8. "tr": "PostgreSQL düzgün yapılandırılmamış, lütfen paketi tekrar yükleyin.",
  9. })
  10. def check_postgresql():
  11. import os
  12. if not os.path.exists(config.get("PGDATA", "/var/lib/postgresql/data")):
  13. fail(MSG_ERR_PGSQLNOTINST)
  14. PIDFILE = "%s/postmaster.pid" % config.get("PGDATA", "/var/lib/postgresql/data")
  15. #pg_ctl
  16. @synchronized
  17. def start():
  18. check_postgresql()
  19. startService(command="/usr/bin/pg_ctl",
  20. args=["start", "-D", config.get("PGDATA", "/var/lib/postgresql/data"), "-l", config.get("PGLOG", "/var/lib/postgresql/data/postgresql.log"), "-o", config.get("PGOPTS", "")],
  21. pidfile=PIDFILE,
  22. chuid=config.get("PGUSER", "postgres"),
  23. donotify=True)
  24. @synchronized
  25. def stop():
  26. stopService(command="/usr/bin/pg_ctl",
  27. args=["stop", "-D", config.get("PGDATA", "/var/lib/postgresql/data"), "-s", "-m", "fast"],
  28. chuid=config.get("PGUSER", "postgres"),
  29. donotify=True)
  30. def reload():
  31. stopService(command="/usr/bin/pg_ctl",
  32. args=["reload", "-D", config.get("PGDATA", "/var/lib/postgresql/data"), "-s"],
  33. donotify=True)
  34. def status():
  35. return isServiceRunning(PIDFILE)