refactored swift-init.do_start to handle missing config files

This commit is contained in:
Clay Gerrard
2010-07-19 21:37:01 +00:00
committed by Tarmac
3 changed files with 47 additions and 31 deletions

View File

@@ -70,7 +70,27 @@ def do_start(server, once=False):
print "Unable to increase file descriptor limit. Running as non-root?" print "Unable to increase file descriptor limit. Running as non-root?"
os.environ['PYTHON_EGG_CACHE'] = '/tmp' os.environ['PYTHON_EGG_CACHE'] = '/tmp'
def write_pid_file(pid_file, pid):
dir, file = os.path.split(pid_file)
if not os.path.exists(dir):
try:
os.mkdirs(dir)
except OSError, err:
if err.errno == errno.EACCES:
sys.exit('Unable to create %s. Running as non-root?' % dir)
fp = open(pid_file, 'w')
fp.write('%d\n' % pid)
fp.close()
def launch(ini_file, pid_file): def launch(ini_file, pid_file):
cmd = 'swift-%s' % server
args = [server, ini_file]
if once:
print 'Running %s once' % server
args.append('once')
else:
print 'Starting %s' % server
pid = os.fork() pid = os.fork()
if pid == 0: if pid == 0:
os.setsid() os.setsid()
@@ -90,38 +110,27 @@ def do_start(server, once=False):
print 'unable to launch %s' % server print 'unable to launch %s' % server
sys.exit(0) sys.exit(0)
else: else:
fp = open(pid_file, 'w') write_pid_file(pid_file, pid)
fp.write('%d\n' % pid)
fp.close() ini_file = '/etc/swift/%s-server.conf' % server_type
try: if os.path.exists(ini_file):
os.mkdir('/var/run/swift') # single config file over-rides config dirs
except OSError, err: pid_file = '/var/run/swift/%s.pid' % server
if err.errno == errno.EACCES: launch_args = [(ini_file, pid_file)]
sys.exit('Unable to create /var/run/swift. Running as non-root?') elif os.path.exists('/etc/swift/%s-server/' % server_type):
elif err.errno != errno.EEXIST: # found config directory, searching for config file(s)
raise launch_args = []
if os.path.exists('/etc/swift/%s-server.conf' % server_type):
if once:
print 'Running %s once' % server
else:
print 'Starting %s' % server
launch('/etc/swift/%s-server.conf' % server_type,
'/var/run/swift/%s.pid' % server)
else:
try:
os.mkdir('/var/run/swift/%s' % server)
except OSError, err:
if err.errno == errno.EACCES:
sys.exit(
'Unable to create /var/run/swift. Running as non-root?')
elif err.errno != errno.EEXIST:
raise
if once:
print 'Running %ss once' % server
else:
print 'Starting %ss' % server
for num, ini_file in enumerate(glob.glob('/etc/swift/%s-server/*.conf' % server_type)): for num, ini_file in enumerate(glob.glob('/etc/swift/%s-server/*.conf' % server_type)):
launch(ini_file, '/var/run/swift/%s/%d.pid' % (server, num)) pid_file = '/var/run/swift/%s/%d.pid' % (server, num)
# start a server for each ini_file found
launch_args.append((ini_file, pid_file))
else:
# maybe there's a config file(s) out there, but I couldn't find it!
sys.exit('Unable to locate config file for %s. %s does not exist?' % (server, ini_file))
# start all servers
for ini_file, pid_file in launch_args:
launch(ini_file, pid_file)
def do_stop(server, graceful=False): def do_stop(server, graceful=False):
if graceful and server in GRACEFUL_SHUTDOWN_SERVERS: if graceful and server in GRACEFUL_SHUTDOWN_SERVERS:

View File

@@ -35,6 +35,12 @@ setup(
'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.6',
'Environment :: No Input/Output (Daemon)', 'Environment :: No Input/Output (Daemon)',
], ],
install_requires=[
'eventlet>=0.9.1',
'simplejson>=2.0.9', # included for speed
'WebOb>=0.9.8',
'xattr>=0.4',
],
scripts=['bin/st', 'bin/swift-account-auditor', scripts=['bin/st', 'bin/swift-account-auditor',
'bin/swift-account-audit', 'bin/swift-account-reaper', 'bin/swift-account-audit', 'bin/swift-account-reaper',
'bin/swift-account-replicator', 'bin/swift-account-server', 'bin/swift-account-replicator', 'bin/swift-account-server',

View File

@@ -63,6 +63,7 @@ swift/__init__.py
swift.egg-info/PKG-INFO swift.egg-info/PKG-INFO
swift.egg-info/SOURCES.txt swift.egg-info/SOURCES.txt
swift.egg-info/dependency_links.txt swift.egg-info/dependency_links.txt
swift.egg-info/requires.txt
swift.egg-info/top_level.txt swift.egg-info/top_level.txt
swift/account/__init__.py swift/account/__init__.py
swift/account/auditor.py swift/account/auditor.py