4049N/A#!/usr/bin/python2.7
2801N/A
4049N/A# Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
2801N/A#
2801N/A# Licensed under the Apache License, Version 2.0 (the "License"); you may
2801N/A# not use this file except in compliance with the License. You may obtain
2801N/A# a copy of the License at
2801N/A#
2801N/A# http://www.apache.org/licenses/LICENSE-2.0
2801N/A#
2801N/A# Unless required by applicable law or agreed to in writing, software
2801N/A# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
2801N/A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
2801N/A# License for the specific language governing permissions and limitations
2801N/A# under the License.
2801N/A
2801N/Aimport errno
2801N/Aimport os
2801N/Aimport sys
2801N/A
2801N/Aimport smf_include
2801N/A
2801N/Arings = {
2801N/A "account-reaper": ["account", "container", "object"],
2801N/A "account-replicator": ["account"],
3998N/A "container-reconciler": ["container"],
2801N/A "container-replicator": ["container"],
2801N/A "container-sync": ["container", "object"],
2801N/A "container-updater": ["account"],
2801N/A "object-expirer": ["object"],
2801N/A "object-replicator": ["object"],
2801N/A "object-updater": ["container"],
2801N/A "proxy-server": ["account", "container", "object"]
2801N/A}
2801N/A
2892N/A
2801N/Adef start():
2801N/A # All the Swift services do essentially the same thing, so there's no need
2801N/A # to have different method executables. Just look at the FMRI and run the
2801N/A # appropriate executable from /usr/lib/swift.
2801N/A fmri = os.environ["SMF_FMRI"]
2801N/A exefile = os.path.basename(fmri.split(":")[1])
2801N/A exepath = os.path.join("/usr/lib/swift", exefile)
2801N/A
2801N/A # Try to find a config file that matches the executable name (minus the
2801N/A # leading "swift-". If that fails, try using the -server config file.
2801N/A cfgfile = "/etc/swift/%s.conf" % exepath.split("-", 1)[1]
2801N/A if not os.path.isfile(cfgfile):
2801N/A cfgfile = "/etc/swift/%s-server.conf" % exepath.split("-")[1]
2801N/A if not os.path.isfile(cfgfile):
2801N/A print >> sys.stderr, "Missing configuration file"
2892N/A smf_include.smf_method_exit(
2892N/A smf_include.SMF_EXIT_ERR_CONFIG, "missing_config",
2892N/A "Missing configuration file")
2801N/A
2801N/A missing_rings = []
2801N/A for ring in rings.get(exepath.split("-", 1)[1], ()):
2801N/A ringfile = "/etc/swift/%s.ring.gz" % ring
2801N/A if not os.path.isfile(ringfile):
2801N/A missing_rings.append(ringfile)
2801N/A if missing_rings:
2801N/A print >> sys.stderr, "Missing ring(s): " + ", ".join(missing_rings)
2892N/A smf_include.smf_method_exit(
2892N/A smf_include.SMF_EXIT_ERR_CONFIG, "missing_ring",
2892N/A "Missing ring(s): " + ", ".join(missing_rings))
2801N/A
2801N/A # This is the default recon_cache_path (from the config files) as well as
2801N/A # the default run_dir (from the code).
2801N/A try:
2801N/A os.mkdir("/var/run/swift")
2801N/A except OSError as e:
2801N/A if e.errno != errno.EEXIST:
2801N/A raise
2801N/A
2801N/A smf_include.smf_subprocess("%s %s" % (exepath, cfgfile))
2801N/A
2801N/Aif __name__ == "__main__":
2801N/A os.putenv("LC_ALL", "C")
2801N/A smf_include.smf_main()