From 0970ba130017021f63191056d9206d6f427c3957 Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 7 Aug 2022 23:53:21 +0800 Subject: [PATCH 01/11] Update postgresql.tpl --- plugins/postgresql/init.d/postgresql.tpl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/postgresql/init.d/postgresql.tpl b/plugins/postgresql/init.d/postgresql.tpl index a0c5cf3db..00d096fe3 100644 --- a/plugins/postgresql/init.d/postgresql.tpl +++ b/plugins/postgresql/init.d/postgresql.tpl @@ -50,8 +50,7 @@ pg_status() pg_reload() { - pg_stop - pg_start + {$APP_PATH}/bin/pg_ctl -D {$APP_PATH}/data -l {$APP_PATH}/logs/server.log reload } From 5fee9c6a334e608afa23240c7236a423ce6469b2 Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 7 Aug 2022 23:56:19 +0800 Subject: [PATCH 02/11] Update postgresql.service.tpl --- plugins/postgresql/init.d/postgresql.service.tpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/postgresql/init.d/postgresql.service.tpl b/plugins/postgresql/init.d/postgresql.service.tpl index fd856395a..ab2da2e52 100644 --- a/plugins/postgresql/init.d/postgresql.service.tpl +++ b/plugins/postgresql/init.d/postgresql.service.tpl @@ -7,9 +7,9 @@ Type=forking User=postgres Group=postgres WorkingDirectory={$APP_PATH} -ExecStart={$APP_PATH}/pg_ctl start -D {$APP_PATH}/data -ExecReload={$APP_PATH}/pg_ctl restart -D {$APP_PATH}/data -ExecStop={$APP_PATH}/pg_ctl stop -D {$APP_PATH}/data +ExecStart={$APP_PATH}/bin/pg_ctl start -D {$APP_PATH}/data +ExecReload={$APP_PATH}/bin/pg_ctl restart -D {$APP_PATH}/data +ExecStop={$APP_PATH}/bin/pg_ctl stop -D {$APP_PATH}/data PrivateTmp=false [Install] From 060fc535a946484a5373e055ebd1679ac6c4c465 Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 7 Aug 2022 23:56:43 +0800 Subject: [PATCH 03/11] Update postgresql.service.tpl --- plugins/postgresql/init.d/postgresql.service.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/postgresql/init.d/postgresql.service.tpl b/plugins/postgresql/init.d/postgresql.service.tpl index ab2da2e52..0eedaa417 100644 --- a/plugins/postgresql/init.d/postgresql.service.tpl +++ b/plugins/postgresql/init.d/postgresql.service.tpl @@ -4,8 +4,8 @@ After=network.target [Service] Type=forking -User=postgres -Group=postgres +User=postgresql +Group=postgresql WorkingDirectory={$APP_PATH} ExecStart={$APP_PATH}/bin/pg_ctl start -D {$APP_PATH}/data ExecReload={$APP_PATH}/bin/pg_ctl restart -D {$APP_PATH}/data From 66669071550117e694dddd266495c15c2a359bc2 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 8 Aug 2022 01:01:29 +0800 Subject: [PATCH 04/11] Update install.sh --- plugins/postgresql/install.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/postgresql/install.sh b/plugins/postgresql/install.sh index 741fc3540..0e64845db 100755 --- a/plugins/postgresql/install.sh +++ b/plugins/postgresql/install.sh @@ -23,15 +23,15 @@ if [ ! -d $curPath/versions/$2 ];then exit 0 fi -# if [ "${action}" == "uninstall" ];then -# if [ -f /usr/lib/systemd/system/postgresql.service ] || [ -f /lib/systemd/system/postgresql.service ];then -# systemctl stop postgresql -# systemctl disable postgresql -# rm -rf /usr/lib/systemd/system/postgresql.service -# rm -rf /lib/systemd/system/postgresql.service -# systemctl daemon-reload -# fi -# fi +if [ "${action}" == "uninstall" ];then + if [ -f /usr/lib/systemd/system/postgresql.service ] || [ -f /lib/systemd/system/postgresql.service ];then + systemctl stop postgresql + systemctl disable postgresql + rm -rf /usr/lib/systemd/system/postgresql.service + rm -rf /lib/systemd/system/postgresql.service + systemctl daemon-reload + fi +fi sh -x $curPath/versions/$2/install.sh $1 From a42f15dae4630fcf9fd1fd2960d110f2769a0aa5 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 8 Aug 2022 01:32:04 +0800 Subject: [PATCH 05/11] Update index.py --- plugins/postgresql/index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/postgresql/index.py b/plugins/postgresql/index.py index 0a834c1fb..5475f5b49 100755 --- a/plugins/postgresql/index.py +++ b/plugins/postgresql/index.py @@ -249,7 +249,7 @@ def pGetDbUser(): def initPgData(): serverdir = getServerDir() - if not os.path.exists(serverdir + '/postgresql'): + if not os.path.exists(serverdir + '/data'): cmd = 'cd ' + serverdir + ' && ./bin/initdb -D ' + serverdir + "/data" mw.execShell(cmd) return False From 5b441d5cb48262f528599aad5fe81da8346cf701 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 8 Aug 2022 14:52:45 +0800 Subject: [PATCH 06/11] pg up xx2 --- plugins/postgresql/class/pg.py | 88 +++++++++++++++ plugins/postgresql/conf/pgsql.sql | 4 +- plugins/postgresql/conf/postgresql.conf | 11 ++ plugins/postgresql/index.html | 2 +- plugins/postgresql/index.py | 131 ++++++++++++++++++----- plugins/postgresql/init.d/postgresql.tpl | 6 +- plugins/postgresql/install.sh | 17 ++- 7 files changed, 221 insertions(+), 38 deletions(-) create mode 100755 plugins/postgresql/class/pg.py create mode 100644 plugins/postgresql/conf/postgresql.conf diff --git a/plugins/postgresql/class/pg.py b/plugins/postgresql/class/pg.py new file mode 100755 index 000000000..74aae0f52 --- /dev/null +++ b/plugins/postgresql/class/pg.py @@ -0,0 +1,88 @@ +# coding: utf-8 + +import re +import os +import sys + +import psycopg2 + + +class ORM: + __DB_PASS = None + __DB_USER = 'root' + __DB_PORT = 5432 + __DB_HOST = 'localhost' + __DB_CONN = None + __DB_CUR = None + __DB_ERR = None + __DB_CNF = '/etc/my.cnf' + __DB_SOCKET = '/www/server/postgresql/mysql.sock' + __DB_CHARSET = "utf8" + + def __Conn(self): + '''连接数据库''' + try: + + try: + self.__DB_CONN = psycopg2.connect(database='postgres', user=self.__DB_USER, password=self.__DB_PASS, + host=self.__DB_HOST, port=int(self.__DB_PORT)) + except Exception as e: + self.__DB_HOST = '127.0.0.1' + self.__DB_CONN = psycopg2.connect(database='postgres', user=self.__DB_USER, password=self.__DB_PASS, + host=self.__DB_HOST, port=int(self.__DB_PORT)) + + self.__DB_CUR = self.__DB_CONN.cursor() + return True + except Exception as e: + self.__DB_ERR = e + return False + + def setDbConf(self, conf): + self.__DB_CNF = conf + + def setSocket(self, sock): + self.__DB_SOCKET = sock + + def setCharset(self, charset): + self.__DB_CHARSET = charset + + def setPort(self, port): + self.__DB_PORT = port + + def setPwd(self, pwd): + self.__DB_PASS = pwd + + def getPwd(self): + return self.__DB_PASS + + def execute(self, sql): + # 执行SQL语句返回受影响行 + if not self.__Conn(): + return self.__DB_ERR + try: + result = self.__DB_CUR.execute(sql) + self.__DB_CONN.commit() + self.__Close() + return result + except Exception as ex: + return ex + + def query(self, sql): + # 执行SQL语句返回数据集 + if not self.__Conn(): + return self.__DB_ERR + try: + self.__DB_CUR.execute(sql) + result = self.__DB_CUR.fetchall() + # print(result) + # 将元组转换成列表 + # data = map(list, result) + self.__Close() + return result + except Exception as ex: + return ex + + def __Close(self): + # 关闭连接 + self.__DB_CUR.close() + self.__DB_CONN.close() diff --git a/plugins/postgresql/conf/pgsql.sql b/plugins/postgresql/conf/pgsql.sql index f6df3e957..14ef6fb2d 100755 --- a/plugins/postgresql/conf/pgsql.sql +++ b/plugins/postgresql/conf/pgsql.sql @@ -1,9 +1,9 @@ CREATE TABLE IF NOT EXISTS `config` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, - `mysql_root` TEXT + `pg_root` TEXT ); -INSERT INTO `config` (`id`, `mysql_root`) VALUES (1, 'admin'); +INSERT INTO `config` (`id`, `pg_root`) VALUES (1, 'admin'); CREATE TABLE IF NOT EXISTS `databases` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, diff --git a/plugins/postgresql/conf/postgresql.conf b/plugins/postgresql/conf/postgresql.conf new file mode 100644 index 000000000..00e9606fe --- /dev/null +++ b/plugins/postgresql/conf/postgresql.conf @@ -0,0 +1,11 @@ +port = 5432 +listen_addresses='*' +unix_socket_directories='{$APP_PATH}/tmp' + +max_wal_size = 1GB +min_wal_size = 80MB + +log_timezone = 'Asia/Shanghai' +datestyle = 'iso, ymd' +timezone = 'Asia/Shanghai' +default_text_search_config = 'pg_catalog.simple' diff --git a/plugins/postgresql/index.html b/plugins/postgresql/index.html index 66a7ca866..e231893b3 100755 --- a/plugins/postgresql/index.html +++ b/plugins/postgresql/index.html @@ -5,7 +5,7 @@

服务

自启动

-

配置文件

+

配置文件

端口