Showing
1 changed file
with
38 additions
and
25 deletions
@@ -10,6 +10,7 @@ import Model from './model'; | @@ -10,6 +10,7 @@ import Model from './model'; | ||
10 | import ssh from 'ssh2'; | 10 | import ssh from 'ssh2'; |
11 | import InfluxDB from '../logger/influxdb'; | 11 | import InfluxDB from '../logger/influxdb'; |
12 | import ws from '../../lib/ws'; | 12 | import ws from '../../lib/ws'; |
13 | +import md5 from 'md5'; | ||
13 | 14 | ||
14 | class PageCahe extends Model { | 15 | class PageCahe extends Model { |
15 | 16 | ||
@@ -36,20 +37,21 @@ class PageCahe extends Model { | @@ -36,20 +37,21 @@ class PageCahe extends Model { | ||
36 | let queryUri = queryUriList[i]; | 37 | let queryUri = queryUriList[i]; |
37 | 38 | ||
38 | self._broadcast(`规则${i+1}:${queryUri}`); | 39 | self._broadcast(`规则${i+1}:${queryUri}`); |
39 | - queryUri = self.replaceUrl(queryUri); | ||
40 | - let sql = `select FIRST(cache_status) from ${storeTableName} where full_path =~ /${queryUri}.*/ group by "key"`; | ||
41 | - let result = await InfluxDB.query(sql); | ||
42 | - if (!result.length) { | ||
43 | - self._broadcast(`未查询到匹配的缓存信息`); | ||
44 | - continue; | ||
45 | - } | 40 | + let keys = [md5(queryUri)]; |
41 | + // queryUri = self.replaceUrl(queryUri); | ||
42 | + // let sql = `select FIRST(cache_status) from ${storeTableName} where full_path =~ /${queryUri}.*/ group by "key"`; | ||
43 | + // let result = await InfluxDB.query(sql); | ||
44 | + // if (!result.length) { | ||
45 | + // self._broadcast(`未查询到匹配的缓存信息`); | ||
46 | + // continue; | ||
47 | + // } | ||
46 | let servers = await self.findAll(); | 48 | let servers = await self.findAll(); |
47 | 49 | ||
48 | self._broadcast(`共${servers.length}台nginx准备清理..`) | 50 | self._broadcast(`共${servers.length}台nginx准备清理..`) |
49 | for (let i = 0; i < servers.length; i++) { | 51 | for (let i = 0; i < servers.length; i++) { |
50 | try { | 52 | try { |
51 | self._broadcast(`第${i+1}台nginx准备清理:`) | 53 | self._broadcast(`第${i+1}台nginx准备清理:`) |
52 | - await self._removeCache(servers[i], result[0], storeTableName); | 54 | + await self._removeCache(servers[i], keys, storeTableName); |
53 | } catch (err) { | 55 | } catch (err) { |
54 | self._broadcast(`错误信息:${err}`) | 56 | self._broadcast(`错误信息:${err}`) |
55 | } | 57 | } |
@@ -103,7 +105,8 @@ class PageCahe extends Model { | @@ -103,7 +105,8 @@ class PageCahe extends Model { | ||
103 | for (var i = blockIndex; i < block; i++) { | 105 | for (var i = blockIndex; i < block; i++) { |
104 | self._broadcast(`正在执行清理,进度:${i+1}/${block}`); | 106 | self._broadcast(`正在执行清理,进度:${i+1}/${block}`); |
105 | blockIndex = i; | 107 | blockIndex = i; |
106 | - let items = keys.slice(i * limit, i * limit + 2); | 108 | + // let items = keys.slice(i * limit, i * limit + 2); |
109 | + let items = keys; | ||
107 | let script = self._joinRemoveScript(server, items, storeTableName); | 110 | let script = self._joinRemoveScript(server, items, storeTableName); |
108 | await self._evalScript(conn, script); | 111 | await self._evalScript(conn, script); |
109 | } | 112 | } |
@@ -163,14 +166,14 @@ class PageCahe extends Model { | @@ -163,14 +166,14 @@ class PageCahe extends Model { | ||
163 | return new Promise((resolve, reject) => { | 166 | return new Promise((resolve, reject) => { |
164 | //检查shell脚本的危险操作 | 167 | //检查shell脚本的危险操作 |
165 | if (self._checkDangerScript(script)) { | 168 | if (self._checkDangerScript(script)) { |
166 | - console.log(script) | ||
167 | - let result = conn.exec(script, (err, stream) => { | ||
168 | - if (!err) { | ||
169 | - resolve(); | ||
170 | - } else { | ||
171 | - self._broadcast('执行错误:${err}'); | ||
172 | - } | ||
173 | - }); | 169 | + self._broadcast(script); |
170 | + // let result = conn.exec(script, (err, stream) => { | ||
171 | + // if (!err) { | ||
172 | + // resolve(); | ||
173 | + // } else { | ||
174 | + // self._broadcast('执行错误:${err}'); | ||
175 | + // } | ||
176 | + // }); | ||
174 | } else { | 177 | } else { |
175 | self._broadcast('检测到危险操作'); | 178 | self._broadcast('检测到危险操作'); |
176 | reject('检测到危险操作'); | 179 | reject('检测到危险操作'); |
@@ -187,9 +190,11 @@ class PageCahe extends Model { | @@ -187,9 +190,11 @@ class PageCahe extends Model { | ||
187 | _joinRemoveScript(server, keys, storeTableName) { | 190 | _joinRemoveScript(server, keys, storeTableName) { |
188 | let script = 'rm'; | 191 | let script = 'rm'; |
189 | keys.forEach((key) => { | 192 | keys.forEach((key) => { |
190 | - let level1 = key.key.substr(key.key.length - 1, 1); | ||
191 | - let level2 = key.key.substr(key.key.length - 3, 2); | ||
192 | - script += ` ${server.cachepath}/${storeTableName}/${level1}/${level2}/${key.key}`; | 193 | + // let level1 = key.key.substr(key.key.length - 1, 1); |
194 | + // let level2 = key.key.substr(key.key.length - 3, 2); | ||
195 | + let level1 = key.substr(key.length - 1, 1); | ||
196 | + let level2 = key.substr(key.length - 3, 2); | ||
197 | + script += ` ${server.cachepath}/${storeTableName}/${level1}/${level2}/${key}`; | ||
193 | }); | 198 | }); |
194 | return script; | 199 | return script; |
195 | } | 200 | } |
@@ -202,13 +207,21 @@ class PageCahe extends Model { | @@ -202,13 +207,21 @@ class PageCahe extends Model { | ||
202 | async init() { | 207 | async init() { |
203 | let count = await this.count({}); | 208 | let count = await this.count({}); |
204 | if (count === 0) { | 209 | if (count === 0) { |
210 | + // await this.insert({ | ||
211 | + // host: '127.0.0.1', | ||
212 | + // username: 'chenfeng', | ||
213 | + // password: '1', | ||
214 | + // port: 22, | ||
215 | + // tag: 'nginx2', | ||
216 | + // cachepath: '/usr/local/nginx' | ||
217 | + // }); | ||
205 | await this.insert({ | 218 | await this.insert({ |
206 | host: '10.66.1.2', | 219 | host: '10.66.1.2', |
207 | username: 'node', | 220 | username: 'node', |
208 | password: 'yoho9646', | 221 | password: 'yoho9646', |
209 | port: 22, | 222 | port: 22, |
210 | tag: 'nginx2', | 223 | tag: 'nginx2', |
211 | - cachepath: '/usr/local/nginx' | 224 | + cachepath: '/usr/local/openresty/nginx' |
212 | }); | 225 | }); |
213 | await this.insert({ | 226 | await this.insert({ |
214 | host: '10.66.1.3', | 227 | host: '10.66.1.3', |
@@ -216,7 +229,7 @@ class PageCahe extends Model { | @@ -216,7 +229,7 @@ class PageCahe extends Model { | ||
216 | password: 'yoho9646', | 229 | password: 'yoho9646', |
217 | port: 22, | 230 | port: 22, |
218 | tag: 'nginx3', | 231 | tag: 'nginx3', |
219 | - cachepath: '/usr/local/nginx' | 232 | + cachepath: '/usr/local/openresty/nginx' |
220 | }); | 233 | }); |
221 | await this.insert({ | 234 | await this.insert({ |
222 | host: '10.66.1.15', | 235 | host: '10.66.1.15', |
@@ -224,7 +237,7 @@ class PageCahe extends Model { | @@ -224,7 +237,7 @@ class PageCahe extends Model { | ||
224 | password: 'yoho9646', | 237 | password: 'yoho9646', |
225 | port: 22, | 238 | port: 22, |
226 | tag: 'nginx15', | 239 | tag: 'nginx15', |
227 | - cachepath: '/usr/local/nginx' | 240 | + cachepath: '/usr/local/openresty/nginx' |
228 | }); | 241 | }); |
229 | await this.insert({ | 242 | await this.insert({ |
230 | host: '10.66.1.84', | 243 | host: '10.66.1.84', |
@@ -232,7 +245,7 @@ class PageCahe extends Model { | @@ -232,7 +245,7 @@ class PageCahe extends Model { | ||
232 | password: 'yoho9646', | 245 | password: 'yoho9646', |
233 | port: 22, | 246 | port: 22, |
234 | tag: 'nginx84', | 247 | tag: 'nginx84', |
235 | - cachepath: '/usr/local/nginx' | 248 | + cachepath: '/usr/local/openresty/nginx' |
236 | }); | 249 | }); |
237 | await this.insert({ | 250 | await this.insert({ |
238 | host: '10.66.1.97', | 251 | host: '10.66.1.97', |
@@ -240,7 +253,7 @@ class PageCahe extends Model { | @@ -240,7 +253,7 @@ class PageCahe extends Model { | ||
240 | password: 'yoho9646', | 253 | password: 'yoho9646', |
241 | port: 22, | 254 | port: 22, |
242 | tag: 'nginx97', | 255 | tag: 'nginx97', |
243 | - cachepath: '/usr/local/nginx' | 256 | + cachepath: '/usr/local/openresty/nginx' |
244 | }); | 257 | }); |
245 | } | 258 | } |
246 | } | 259 | } |
-
Please register or login to post a comment