Refactor SWIFT_HASH_PATH_SUFFIX to be in a config file. Adding new conf file /etc/swift/swift.conf
This commit is contained in:
@@ -199,6 +199,12 @@ virtual machine will emulate running a four node Swift cluster.
|
|||||||
[filter:cache]
|
[filter:cache]
|
||||||
use = egg:swift#memcache
|
use = egg:swift#memcache
|
||||||
|
|
||||||
|
#. Create `/etc/swift/swift.conf`::
|
||||||
|
|
||||||
|
[swift-hash]
|
||||||
|
# random unique string that can never change (DO NOT LOSE)
|
||||||
|
swift_hash_path_suffix = changeme
|
||||||
|
|
||||||
#. Create `/etc/swift/account-server/1.conf`::
|
#. Create `/etc/swift/account-server/1.conf`::
|
||||||
|
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
|
3
etc/swift.conf-sample
Normal file
3
etc/swift.conf-sample
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[swift-hash]
|
||||||
|
swift_hash_path_suffix = changeme
|
||||||
|
|
@@ -45,6 +45,7 @@ class Daemon(object):
|
|||||||
sys.stderr = utils.LoggerFileObject(self.logger)
|
sys.stderr = utils.LoggerFileObject(self.logger)
|
||||||
|
|
||||||
utils.drop_privileges(self.conf.get('user', 'swift'))
|
utils.drop_privileges(self.conf.get('user', 'swift'))
|
||||||
|
utils.validate_configuration()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.setsid()
|
os.setsid()
|
||||||
|
@@ -31,7 +31,7 @@ import ctypes
|
|||||||
import ctypes.util
|
import ctypes.util
|
||||||
import fcntl
|
import fcntl
|
||||||
import struct
|
import struct
|
||||||
from ConfigParser import ConfigParser
|
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
|
||||||
from tempfile import mkstemp
|
from tempfile import mkstemp
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
|
|
||||||
@@ -56,12 +56,25 @@ _posix_fadvise = None
|
|||||||
# Used by hash_path to offer a bit more security when generating hashes for
|
# Used by hash_path to offer a bit more security when generating hashes for
|
||||||
# paths. It simply appends this value to all paths; guessing the hash a path
|
# paths. It simply appends this value to all paths; guessing the hash a path
|
||||||
# will end up with would also require knowing this suffix.
|
# will end up with would also require knowing this suffix.
|
||||||
HASH_PATH_SUFFIX = os.environ.get('SWIFT_HASH_PATH_SUFFIX', 'endcap')
|
hash_conf = ConfigParser()
|
||||||
|
HASH_PATH_SUFFIX = ''
|
||||||
|
if hash_conf.read('/etc/swift/swift.conf'):
|
||||||
|
try:
|
||||||
|
HASH_PATH_SUFFIX = hash_conf.get('swift-hash',
|
||||||
|
'swift_hash_path_suffix')
|
||||||
|
except (NoSectionError, NoOptionError):
|
||||||
|
pass
|
||||||
|
|
||||||
# Used when reading config values
|
# Used when reading config values
|
||||||
TRUE_VALUES = set(('true', '1', 'yes', 'True', 'Yes', 'on', 'On'))
|
TRUE_VALUES = set(('true', '1', 'yes', 'True', 'Yes', 'on', 'On'))
|
||||||
|
|
||||||
|
|
||||||
|
def validate_configuration():
|
||||||
|
if HASH_PATH_SUFFIX == '':
|
||||||
|
sys.exit("Error: [swift-hash]: swift_hash_path_suffix missing "
|
||||||
|
"from /etc/swift/swift.conf")
|
||||||
|
|
||||||
|
|
||||||
def load_libc_function(func_name):
|
def load_libc_function(func_name):
|
||||||
"""
|
"""
|
||||||
Attempt to find the function in libc, otherwise return a no-op func.
|
Attempt to find the function in libc, otherwise return a no-op func.
|
||||||
|
@@ -34,7 +34,7 @@ wsgi.ACCEPT_ERRNO.add(ECONNRESET)
|
|||||||
from eventlet.green import socket, ssl
|
from eventlet.green import socket, ssl
|
||||||
|
|
||||||
from swift.common.utils import get_logger, drop_privileges, \
|
from swift.common.utils import get_logger, drop_privileges, \
|
||||||
LoggerFileObject, NullLogger
|
validate_configuration, LoggerFileObject, NullLogger
|
||||||
|
|
||||||
|
|
||||||
def monkey_patch_mimetools():
|
def monkey_patch_mimetools():
|
||||||
@@ -112,6 +112,7 @@ def run_wsgi(conf_file, app_section, *args, **kwargs): # pragma: no cover
|
|||||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 600)
|
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 600)
|
||||||
worker_count = int(conf.get('workers', '1'))
|
worker_count = int(conf.get('workers', '1'))
|
||||||
drop_privileges(conf.get('user', 'swift'))
|
drop_privileges(conf.get('user', 'swift'))
|
||||||
|
validate_configuration()
|
||||||
|
|
||||||
def run_server():
|
def run_server():
|
||||||
wsgi.HttpProtocol.default_request_version = "HTTP/1.0"
|
wsgi.HttpProtocol.default_request_version = "HTTP/1.0"
|
||||||
|
Reference in New Issue
Block a user