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