def do_restart(request):
    """
    * "test" for a django instance (this do a touch over settings.py for reload)
    * "apache"
    * "httpd"
    * "wsgi"
    * "restart_script <script_path_name>"
    """
    if request.user.is_staff:
        reload_method = get_auto_reload_method()
        reload_log = get_auto_reload_log()
        reload_time = get_auto_reload_time()
        command = "echo no script"
        if reload_method == 'test':
            command = 'touch settings.py'
        ## No RedHAT or similars
        elif reload_method == 'apache2':
            command = 'sudo apache2ctl restart'
        ## RedHAT, CentOS
        elif reload_method == 'httpd':
            command = 'sudo service httpd restart'

        elif reload_method.startswith('restart_script'):
            command = ' '.join(reload_method.split(" ")[1:])
        if os.path.exists(os.path.dirname(reload_log)):
            os.system("sleep 2 && %s &> %s & " % (command, reload_log))
        else:
            print 'The AUTO_RELOAD_LOG directory do not exist'  # Just in case our stdout is logged somewhere
            os.system("sleep 2 && %s & " % command)

        return render_to_response('inlinetrans/response.html',
                                  {'message': reload_time},
                                  context_instance=RequestContext(request))
def do_restart(request):
    """
    * "test" for a django instance (this do a touch over settings.py for reload)
    * "apache"
    * "httpd"
    * "wsgi"
    * "restart_script <script_path_name>"
    """
    if request.user.is_staff:
        reload_method = get_auto_reload_method()
        reload_log = get_auto_reload_log()
        reload_time = get_auto_reload_time()
        command = "echo no script"
        if reload_method == "test":
            command = "touch settings.py"
        ## No RedHAT or similars
        elif reload_method == "apache2":
            command = "sudo apache2ctl restart"
        ## RedHAT, CentOS
        elif reload_method == "httpd":
            command = "sudo service httpd restart"

        elif reload_method.startswith("restart_script"):
            script = reload_method.split(" ")[1]
            command = "%s &" % script
        os.system("sleep 2 && %s &> %s & " % (command, reload_log))

        return render_to_response(
            "inlinetrans/response.html", {"message": reload_time}, context_instance=RequestContext(request)
        )
Exemple #3
0
def do_restart(request):
    """
    * "test" for a django instance (this do a touch over settings.py for reload)
    * "apache"
    * "httpd"
    * "wsgi"
    * "restart_script <script_path_name>"
    """
    if get_user_can_translate(request.user):
        reload_method = get_auto_reload_method()
        reload_log = get_auto_reload_log()
        reload_time = get_auto_reload_time()
        command = "echo no script"
        if reload_method == 'test':
            command = 'touch %s' % os.path.join(settings.BASEDIR,
                                                'settings.py')
        ## No RedHAT or similars
        elif reload_method == 'apache2':
            command = 'sudo apache2ctl restart'
        ## RedHAT, CentOS
        elif reload_method == 'httpd':
            command = 'sudo service httpd restart'

        elif reload_method.startswith('restart_script'):
            command = ' '.join(reload_method.split(" ")[1:])
        if os.path.exists(os.path.dirname(reload_log)):
            os.system("sleep 2 && %s &> %s & " % (command, reload_log))
        else:
            print('The AUTO_RELOAD_LOG directory do not exist'
                  )  # Just in case our stdout is logged somewhere
            os.system("sleep 2 && %s & " % command)
        return render_to_response('inlinetrans/response.html',
                                  {'message': reload_time},
                                  context_instance=RequestContext(request))