mysql.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. from lib.compose.object import ServiceDataVolume
  2. from lib.compose.services import ClusterService
  3. class MysqlService(ClusterService):
  4. def __init__(self,
  5. root_pwd="your-sql-password",
  6. port="3306",
  7. version="10.5.19",
  8. repo="${MARIADB_REPO:-registry.cn-beijing.aliyuncs.com/yunionio}"):
  9. super(MysqlService, self).__init__("mysql", version, repo=repo, image_name="mariadb")
  10. self.password = root_pwd
  11. self.port = port
  12. self.add_environment({
  13. "MYSQL_ROOT_PASSWORD": self.password,
  14. "MYSQL_TCP_PORT": self.port,
  15. "MYSQL_ROOT_HOST": "%",
  16. "MARIADB_AUTO_UPGRADE": "true",
  17. "MARIADB_DISABLE_UPGRADE_BACKUP": "true",
  18. })
  19. self.add_volume(ServiceDataVolume("/var/lib/mysql"))
  20. # self.set_healthcheck("/usr/local/bin/healthcheck.sh")
  21. self.set_healthcheck("mysqladmin ping -h mysql -P 3306 -p$$MYSQL_ROOT_PASSWORD")
  22. def get_port(self):
  23. return self.port
  24. def get_password(self):
  25. return self.password