components/openstack/swift/files/swift-replicator-rsync
changeset 1896 f83e6dde6c3b
child 1944 56ac2df1785b
equal deleted inserted replaced
1895:1f133713df64 1896:f83e6dde6c3b
       
     1 #!/usr/bin/python2.6
       
     2 
       
     3 # Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
       
     4 #
       
     5 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
       
     6 #    not use this file except in compliance with the License. You may obtain
       
     7 #    a copy of the License at
       
     8 #
       
     9 #         http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 #    Unless required by applicable law or agreed to in writing, software
       
    12 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
       
    13 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
       
    14 #    License for the specific language governing permissions and limitations
       
    15 #    under the License.
       
    16 
       
    17 import errno
       
    18 import os
       
    19 import subprocess
       
    20 import sys
       
    21 
       
    22 import smf_include
       
    23 
       
    24 
       
    25 def start():
       
    26     cfgfile = "/etc/swift/rsyncd.conf"
       
    27     if not os.path.isfile(cfgfile):
       
    28         smf_include.smf_method_exit(smf_include.SMF_EXIT_ERR_CONFIG,
       
    29           "missing_config", "Missing configuration file")
       
    30 
       
    31     # This is the default delivered in /etc/swift/rsyncd.conf
       
    32     try:
       
    33         os.mkdir("/var/run/swift")
       
    34     except OSError as e:
       
    35         if e.errno != errno.EEXIST:
       
    36             raise
       
    37 
       
    38     cmdline = ["/usr/bin/rsync", "--daemon", "--config", cfgfile]
       
    39     try:
       
    40         proc = subprocess.Popen(cmdline)
       
    41     except OSError as err:
       
    42         print >> sys.stderr, "Error executing rsync: %s" % err
       
    43         smf_include.smf_method_exit(smf_include.SMF_EXIT_ERR_FATAL,
       
    44           "exec_error", "Error executing rsync: %s" % err)
       
    45 
       
    46     ret = proc.wait()
       
    47     if ret != 0:
       
    48         print >> sys.stderr, "rsync daemon failed to start (see message above)"
       
    49         print >> sys.stderr, "commandline:", " ".join(cmdline)
       
    50         print >> sys.stderr, "exit code:", ret
       
    51         smf_include.smf_method_exit(smf_include.SMF_EXIT_ERR_FATAL,
       
    52           "exec_fail", "rsync daemon failed to start (see service log)")
       
    53 
       
    54     return smf_include.SMF_EXIT_OK
       
    55 
       
    56 if __name__ == "__main__":
       
    57     os.putenv("LC_ALL", "C")
       
    58     smf_include.smf_main()