使用 supervisor 延迟10秒左右启动下面。用于根据远程 redis 上的key 来重启家里没法被外网访问到的机器。
(配合 ssh 转发 使用)
# -*- coding:utf-8 -*-
import redis
import sys
import os
import time
class Client:
def __init__(self, host=None, port=None, password=None):
self.host = host
self.port = port
self.password = password
self.cache = {}
def db(self, id):
if isinstance(id, int) == False:
return None
ret = redis.Redis(host=self.host, port=self.port, db=id, password=self.password)
self.cache[id] = ret
return ret
args = sys.argv
host = None
port = 6379
pw = None
for arg in args:
if arg.find("-h:") == 0:
host = arg.split(":")[1]
if arg.find("-p:") == 0 :
port = int(arg.split(":")[1])
if arg.find("-pw:")==0:
pw = arg.split(":")[1]
client = Client(host=host,port=port,password = pw)
db = client.db(0)
hname = "reboot_cmd"
hkey = "home_centos"
def reboot():
db.hset(hname,hkey,0)
os.system("ifconfig")
while True:
ret = db.hget(hname,hkey)
if ret is not None and int(str(ret)) == 1:
reboot()
print("nothing to do")
time.sleep(10)
网友评论