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