3 import os, sys, signal, time
4 from twisted.python import usage
6 class StartOptions(usage.Options):
8 ["basedir", "C", ".", "which directory to start the node in"],
11 class StopOptions(usage.Options):
13 ["basedir", "C", ".", "which directory to stop the node in"],
16 class RestartOptions(usage.Options):
18 ["basedir", "C", ".", "which directory to restart the node in"],
21 class CreateClientOptions(usage.Options):
23 ["basedir", "C", None, "which directory to create the client in"],
26 def parseArgs(self, *args):
28 self['basedir'] = args[0]
30 raise usage.UsageError("I wasn't expecting so many arguments")
32 def postOptions(self):
33 if self['basedir'] is None:
34 raise usage.UsageError("<basedir> parameter is required")
35 self['basedir'] = os.path.abspath(self['basedir'])
37 class CreateQueenOptions(usage.Options):
39 ["basedir", "C", None, "which directory to create the queen in"],
42 def parseArgs(self, *args):
44 self['basedir'] = args[0]
46 raise usage.UsageError("I wasn't expecting so many arguments")
48 def postOptions(self):
49 if self['basedir'] is None:
50 raise usage.UsageError("<basedir> parameter is required")
51 self['basedir'] = os.path.abspath(self['basedir'])
56 from allmydata import client
57 from twisted.application import service
61 application = service.Application("allmydata_client")
62 c.setServiceParent(application)
68 from allmydata import queen
69 from twisted.application import service
73 application = service.Application("allmydata_queen")
74 c.setServiceParent(application)
77 class Options(usage.Options):
78 synopsis = "Usage: allmydata <command> [command options]"
81 ["create-client", None, CreateClientOptions, "Create a client node."],
82 ["create-queen", None, CreateQueenOptions, "Create a queen node."],
83 ["start", None, StartOptions, "Start a node (of any type)."],
84 ["stop", None, StopOptions, "Stop a node."],
85 ["restart", None, RestartOptions, "Restart a node."],
88 def postOptions(self):
89 if not hasattr(self, 'subOptions'):
90 raise usage.UsageError("must specify a command")
96 except usage.error, e:
97 print "%s: %s" % (sys.argv[0], e)
99 c = getattr(config, 'subOptions', config)
103 command = config.subCommand
104 so = config.subOptions
106 if command == "create-client":
107 rc = create_client(so)
108 elif command == "create-queen":
109 rc = create_queen(so)
110 elif command == "start":
112 elif command == "stop":
114 elif command == "restart":
119 def create_client(config):
120 basedir = config['basedir']
122 f = open(os.path.join(basedir, "client.tac"), "w")
125 print "client created in %s" % basedir
126 print " please copy introducer.furl and vdrive.furl into the directory"
128 def create_queen(config):
129 basedir = config['basedir']
131 f = open(os.path.join(basedir, "queen.tac"), "w")
134 print "queen created in %s" % basedir
137 basedir = config['basedir']
138 if os.path.exists(os.path.join(basedir, "client.tac")):
141 elif os.path.exists(os.path.join(basedir, "queen.tac")):
145 print "%s does not look like a node directory" % basedir
148 rc = os.system("twistd -y %s" % tac)
150 print "node probably started"
153 print "node probably not started"
157 basedir = config['basedir']
158 pidfile = os.path.join(basedir, "twistd.pid")
159 if not os.path.exists(pidfile):
160 print "%s does not look like a running node directory (no twistd.pid)" % basedir
162 pid = open(pidfile, "r").read()
166 os.kill(pid, signal.SIGTERM)
169 # poll once per second until twistd.pid goes away, up to 5 seconds
173 print "process %d is dead" % pid
177 print "never saw process go away"
183 print "not restarting"