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