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