diff --git a/plugins/postgresql/class/pg.py b/plugins/postgresql/class/pg.py index 7f34c3c4b..c05f940a5 100755 --- a/plugins/postgresql/class/pg.py +++ b/plugins/postgresql/class/pg.py @@ -20,7 +20,7 @@ class ORM: __DB_CUR = None __DB_ERR = None __DB_CNF = '/etc/postgresql.cnf' - __DB_SOCKET = '/www/server/postgresql/mysql.sock' + __DB_SOCKET = '/tmp/mysql.sock' __DB_CHARSET = "utf8" __DB_TABLE = "" # 被操作的表名称 diff --git a/plugins/postgresql/conf/postgresql.conf b/plugins/postgresql/conf/postgresql.conf index 9adbde112..dd7c5bb76 100644 --- a/plugins/postgresql/conf/postgresql.conf +++ b/plugins/postgresql/conf/postgresql.conf @@ -1,6 +1,6 @@ port = 5432 listen_addresses='*' -unix_socket_directories='/tmp' +unix_socket_directories='/tmp,{$APP_PATH}' max_connections=200 max_wal_size = 1GB diff --git a/plugins/postgresql/index.py b/plugins/postgresql/index.py index d14ccdc35..62755a9c9 100755 --- a/plugins/postgresql/index.py +++ b/plugins/postgresql/index.py @@ -124,10 +124,14 @@ def getDbPort(): def getSocketFile(): - file = getConf() - content = mw.readFile(file) - rep = 'socket\s*=\s*(.*)' - tmp = re.search(rep, content) + sock_name = 's.PGSQL.' + getDbPort() + sock_tmp = '/tmp/' + sock_name + if os.path.exists(sock_tmp): + return sock_tmp + + sock_app = getServerDir() + "/" + sock_name + if os.path.exists(sock_app): + return sock_app return tmp.groups()[0].strip() @@ -174,8 +178,7 @@ def pgDb(): db.setPort(getDbPort()) db.setPwd(pSqliteDb('config').where('id=?', (1,)).getField('pg_root')) - - # db.setHostAddr(mw.getLocalIp()) + db.setHostAddr(getSocketFile()) return db @@ -255,6 +258,10 @@ def pgCmd(cmd): return "su - postgres -c \"" + cmd + "\"" +def execShellPg(cmd): + return mw.execShell(pgCmd(cmd)) + + def pGetDbUser(): if mw.isAppleSystem(): user = mw.execShell( @@ -268,8 +275,8 @@ def initPgData(): if not os.path.exists(serverdir + '/data'): cmd = serverdir + '/bin/initdb -D ' + serverdir + "/data" if not mw.isAppleSystem(): - cmd = pgCmd(cmd) - # print(cmd) + execShellPg(cmd) + return False mw.execShell(cmd) return False return True