dever 6 anos atrás
pai
commit
3b2a67c4ab
4 arquivos alterados com 30 adições e 21 exclusões
  1. 1 0
      container/conf/db/redis/redis.conf
  2. 2 2
      install
  3. 19 18
      src/daemon.py
  4. 8 1
      src/docker/conf/daemon.conf

+ 1 - 0
container/conf/db/redis/redis.conf

@@ -478,6 +478,7 @@ slave-priority 100
 # use a very strong password otherwise it will be very easy to break.
 #
 # requirepass foobared
+requirepass dm_redis_123
 
 # Command renaming.
 #

+ 2 - 2
install

@@ -36,9 +36,9 @@ pipstatus=`check pip`
 if [ "$pipstatus" = 0 ]; then
 	wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py && rm -rf get-pip.py
 fi
-# python-daemon
+# python-daemon 用不到了
 #pip install python-daemon
-pip install redis
+#pip install redis
 
 yumstatus=`check yum`
 if [ "$yumstatus" = 0 ]; then

+ 19 - 18
src/daemon.py

@@ -1,54 +1,55 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
-# 用于定时运行容器
+# dm_process为key,value为具体指令 如:dm call office-convert_call id=1
 import time
-import subprocess
 import os
-import pprint
+#import pprint
+#import subprocess
 from gevent import monkey; monkey.patch_socket()
 import gevent
 timeSleep = 15
+password = 'dm_redis_123'
 
 def redis():
         import redis
         host = '0.0.0.0'
         port = 6379
-        pool = redis.ConnectionPool(host=host, port=int(port))
+        pool = redis.ConnectionPool(host=host, port=int(port), password=password)
         return redis.Redis(connection_pool=pool)
 
-def command(file):
-        return 'dm call office-convert_call id=' + file
+def pop(key):
+        return popen('redis -a '+password+' lpop ' + key)
+
+def command(process):
+        return process
 
 def popen(command, bg=False):
         string = command
         if bg == True:
                 command = command + ' &'
-
-        print command
         process = os.popen(command)
         output = process.read()
         process.close()
-        print output
         return output
 
-# 文档转换
-def convert():
+# 定时执行进程
+def process():
         r = redis()
-        c = 'office_file'
+        c = 'dm_process'
         i = 0
         while 1:
-                file = r.lpop(c)
-                if file:
-                        g = command(file)
-                        popen(g, False)
+                value = r.lpop(c)
+                if value:
+                        g = command(value)
+                        popen(g)
                 i = i+1
                 if i >= 10:
-                        time.sleep(timeSleep)
+                        gevent.sleep(timeSleep)
                         i = 0
 
 def handle():
 	gevent.joinall([
-		gevent.spawn(git),
+		gevent.spawn(process),
 		#gevent.spawn(backup),
 	])
 

+ 8 - 1
src/docker/conf/daemon.conf

@@ -9,6 +9,13 @@ subnet = 10.0.0.0/255
 run = master,manager,operater
 add = client,worker
 
+[redis]
+;port = 6379:6379,8888:8888
+memory = 2048M
+volumes = {container}conf/db/redis/redis.conf:/etc/redis.conf
+command = redis
+alias = redis->redis-cli
+
 ;服务注册
 [master]
 image = consul
@@ -47,7 +54,7 @@ volumes = {container}share/lib:/data
 ;操作者,图形界面后台,可以直接访问daemon-manager
 [operater]
 image = admin
-port = 8087:8011,8088:8012
+port = 9091:8011,9092:8012
 
 ;master、manager、operater、crond为主机开启
 ;client、worker为其他机器开启