swift-replicator-rsync revision 2892
2801N/A#!/usr/bin/python2.6
2801N/A
2801N/A# Copyright (c) 2014, 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 subprocess
2801N/Aimport sys
2801N/A
2801N/Aimport smf_include
2801N/A
2801N/A
2801N/Adef start():
2801N/A cfgfile = "/etc/swift/rsyncd.conf"
2801N/A if not os.path.isfile(cfgfile):
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 # This is the default delivered in /etc/swift/rsyncd.conf
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 cmdline = ["/usr/bin/rsync", "--daemon", "--config", cfgfile]
2801N/A try:
2801N/A proc = subprocess.Popen(cmdline)
2801N/A except OSError as err:
2801N/A print >> sys.stderr, "Error executing rsync: %s" % err
2892N/A smf_include.smf_method_exit(
2892N/A smf_include.SMF_EXIT_ERR_FATAL, "exec_error",
2892N/A "Error executing rsync: %s" % err)
2801N/A
2801N/A ret = proc.wait()
2801N/A if ret != 0:
2801N/A print >> sys.stderr, "rsync daemon failed to start (see message above)"
2801N/A print >> sys.stderr, "commandline:", " ".join(cmdline)
2801N/A print >> sys.stderr, "exit code:", ret
2892N/A smf_include.smf_method_exit(
2892N/A smf_include.SMF_EXIT_ERR_FATAL, "exec_fail",
2892N/A "rsync daemon failed to start (see service log)")
2801N/A
2801N/A return smf_include.SMF_EXIT_OK
2801N/A
2801N/Aif __name__ == "__main__":
2801N/A os.putenv("LC_ALL", "C")
2801N/A smf_include.smf_main()