service.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. from comar.service import *
  3. serviceType = "server"
  4. serviceDesc = _({"en": "Secure Shell Server",
  5. "tr": "Güvenli Kabuk Sunucusu"
  6. })
  7. MSG_ERR_NEEDCONF = _({"en": "You need /etc/ssh/sshd_config to run sshd.",
  8. "tr": "Sshd'yi çalıştırabilmek için /etc/ssh/sshd_config'e ihtiyaç var.",
  9. })
  10. PID_FILE = "/run/sshd.pid"
  11. RSA1_KEY = "/etc/ssh/ssh_host_key"
  12. RSA_KEY = "/etc/ssh/ssh_host_rsa_key"
  13. DSA_KEY = "/etc/ssh/ssh_host_dsa_key"
  14. def check_config():
  15. import os
  16. if not os.path.exists("/etc/ssh/sshd_config"):
  17. fail(MSG_ERR_NEEDCONF)
  18. if not os.path.exists(RSA1_KEY):
  19. # Default is 2048 bits, and is considered sufficient.
  20. run("/usr/bin/ssh-keygen", "-t", "rsa1",
  21. "-f", "/etc/ssh/ssh_host_key", "-N", "")
  22. if not os.path.exists(DSA_KEY):
  23. run("/usr/bin/ssh-keygen", "-t", "dsa",
  24. "-f", "/etc/ssh/ssh_host_dsa_key", "-N", "")
  25. if not os.path.exists(RSA_KEY):
  26. run("/usr/bin/ssh-keygen", "-t", "rsa",
  27. "-f", "/etc/ssh/ssh_host_rsa_key", "-N", "")
  28. @synchronized
  29. def start():
  30. check_config()
  31. startService(command="/usr/sbin/sshd",
  32. pidfile=PID_FILE,
  33. donotify=True)
  34. @synchronized
  35. def stop():
  36. stopService(pidfile=PID_FILE,
  37. donotify=True)
  38. def status():
  39. return isServiceRunning(PID_FILE)