swift-replicator-rsync revision 4049
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#!/usr/bin/python2.7
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Licensed under the Apache License, Version 2.0 (the "License"); you may
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# not use this file except in compliance with the License. You may obtain
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# a copy of the License at
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# http://www.apache.org/licenses/LICENSE-2.0
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Unless required by applicable law or agreed to in writing, software
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# License for the specific language governing permissions and limitations
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# under the License.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeimport errno
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeimport os
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeimport subprocess
f71f7a61dec7c9089378d14493ad564a1dedf0b5neil_a_wilsonimport sys
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeimport smf_include
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipedef start():
f71f7a61dec7c9089378d14493ad564a1dedf0b5neil_a_wilson cfgfile = "/etc/swift/rsyncd.conf"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe if not os.path.isfile(cfgfile):
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe smf_include.smf_method_exit(
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe smf_include.SMF_EXIT_ERR_CONFIG, "missing_config",
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe "Missing configuration file")
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe # This is the default delivered in /etc/swift/rsyncd.conf
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara try:
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara os.mkdir("/var/run/swift")
266c5071a91fda6a5159b08ea8d45261228d03d5neil_a_wilson except OSError as e:
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe if e.errno != errno.EEXIST:
9da44d3de0a7180285a77b7e8d2426a72aca249ejvergara raise
cmdline = ["/usr/bin/rsync", "--daemon", "--config", cfgfile]
try:
proc = subprocess.Popen(cmdline)
except OSError as err:
print >> sys.stderr, "Error executing rsync: %s" % err
smf_include.smf_method_exit(
smf_include.SMF_EXIT_ERR_FATAL, "exec_error",
"Error executing rsync: %s" % err)
ret = proc.wait()
if ret != 0:
print >> sys.stderr, "rsync daemon failed to start (see message above)"
print >> sys.stderr, "commandline:", " ".join(cmdline)
print >> sys.stderr, "exit code:", ret
smf_include.smf_method_exit(
smf_include.SMF_EXIT_ERR_FATAL, "exec_fail",
"rsync daemon failed to start (see service log)")
return smf_include.SMF_EXIT_OK
if __name__ == "__main__":
os.putenv("LC_ALL", "C")
smf_include.smf_main()