?i»?

Your IP : 18.217.37.129


Current Path : /home/scgforma/www/cloud/core/doc/admin/configuration_server/
Upload File :
Current File : /home/scgforma/www/cloud/core/doc/admin/configuration_server/background_jobs_configuration.html

<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Defining background jobs &mdash; Nextcloud 13 Administration Manual 13 documentation</title>
    
    <link rel="stylesheet" href="../_static/" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../_static/main.min.css" type="text/css" />
    <link rel="stylesheet" href="../_static/styles.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '13',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/js/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="../_static/js/jquery-fix.js"></script>
    <script type="text/javascript" src="../_static/bootstrap-3.1.0/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../_static/bootstrap-sphinx.js"></script>
    <link rel="top" title="Nextcloud 13 Administration Manual 13 documentation" href="../contents.html" />
    <link rel="up" title="Server configuration" href="index.html" />
    <link rel="next" title="Config.php Parameters" href="config_sample_php_parameters.html" />
    <link rel="prev" title="Configuring memory caching" href="caching_configuration.html" />
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1'>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="theme-color" content="#1d2d44">

  </head>
  <body role="document">


<div class="wrap container not-front">
  <div class="content row">
  <main class="main">
    
			<div class="row">
				<div class="col-md-3">
					<div class="sidebar">
            <h1>Nextcloud 13 Administration Manual</h1>
            
            <div class="sidebar-search">
              <form class="headersearch" action="../search.html" method="get">
                <input type="text" value="" name="q" id="q" class="form-control" /> 
                <button  class="btn btn-default" type="submit" id="searchsubmit">Search</button>
              </form>
            </div>
            
							<div class="menu-support-container">
								<ul id="menu-support" class="menu">
									<ul>
                    <li><a href="../contents.html">Table of Contents</a></li>
									</ul>
                  <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../release_notes.html">Release notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Server configuration</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="security_setup_warnings.html">Warnings on admin page</a></li>
<li class="toctree-l2"><a class="reference internal" href="occ_command.html">Using the occ command</a></li>
<li class="toctree-l2"><a class="reference internal" href="activity_configuration.html">Configuring the activity app</a></li>
<li class="toctree-l2"><a class="reference internal" href="caching_configuration.html">Configuring memory caching</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="">Defining background jobs</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#parameters">Parameters</a></li>
<li class="toctree-l3"><a class="reference internal" href="#cron-jobs">Cron jobs</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="config_sample_php_parameters.html">Config.php Parameters</a></li>
<li class="toctree-l2"><a class="reference internal" href="email_configuration.html">Email configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="external_sites.html">Linking external sites</a></li>
<li class="toctree-l2"><a class="reference internal" href="language_configuration.html">Language configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="logging_configuration.html">Logging configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="harden_server.html">Hardening and security guidance</a></li>
<li class="toctree-l2"><a class="reference internal" href="reverse_proxy_configuration.html">Reverse proxy configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="thirdparty_php_configuration.html">Using third party PHP components</a></li>
<li class="toctree-l2"><a class="reference internal" href="automatic_configuration.html">Automatic configuration setup</a></li>
<li class="toctree-l2"><a class="reference internal" href="server_tuning.html">Server tuning</a></li>
<li class="toctree-l2"><a class="reference internal" href="theming.html">Theming</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../configuration_user/index.html">User management</a></li>
<li class="toctree-l1"><a class="reference internal" href="../configuration_files/index.html">File sharing and management</a></li>
<li class="toctree-l1"><a class="reference internal" href="../file_workflows/index.html">File workflows</a></li>
<li class="toctree-l1"><a class="reference internal" href="../configuration_database/index.html">Database configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../configuration_mimetypes/index.html">Mimetypes management</a></li>
<li class="toctree-l1"><a class="reference internal" href="../maintenance/index.html">Maintenance</a></li>
<li class="toctree-l1"><a class="reference internal" href="../issues/index.html">Issues and troubleshooting</a></li>
</ul>

								</ul>
							</div>
					</div>
				</div>
        

				<div class="col-md-9">
					<div class="page-content">
            
<ul class="prevnext-title list-unstyled list-inline">
  <li class="prev">
    <a href="caching_configuration.html" title="Previous Chapter: Configuring memory caching"><span class="glyphicon glyphicon-chevron-left visible-sm"></span><span class="hidden-sm">&laquo; Configuring memory caching</span>
    </a>
  </li>
  <li class="next">
    <a href="config_sample_php_parameters.html" title="Next Chapter: Config.php Parameters"><span class="glyphicon glyphicon-chevron-right visible-sm"></span><span class="hidden-sm">Config.php Parameters &raquo;</span>
    </a>
  </li>
</ul>
						
  <div class="section" id="defining-background-jobs">
<h1>Defining background jobs<a class="headerlink" href="#defining-background-jobs" title="Permalink to this headline">¶</a></h1>
<p>A system like Nextcloud sometimes requires tasks to be done on a regular basis
without the need for user interaction or hindering Nextcloud performance. For
that purpose, as a system administrator, you can define background jobs (for
example, database clean-ups) which are executed without any need for user
interaction.</p>
<p>These jobs are typically referred to as <em>cron jobs</em>.  Cron jobs are commands or
shell-based scripts that are scheduled to run periodically at fixed times,
dates, or intervals.   <code class="docutils literal"><span class="pre">cron.php</span></code> is an Nextcloud internal process that runs
such background jobs on demand.</p>
<p>Nextcloud plug-in applications register actions with <code class="docutils literal"><span class="pre">cron.php</span></code> automatically
to take care of typical housekeeping operations, such as garbage collecting of
temporary files or checking for newly updated files using <code class="docutils literal"><span class="pre">filescan()</span></code> for
externally mounted file systems.</p>
<div class="section" id="parameters">
<h2>Parameters<a class="headerlink" href="#parameters" title="Permalink to this headline">¶</a></h2>
<p>In the admin settings menu you can configure how cron-jobs should be executed.
You can choose between the following options:</p>
<ul class="simple">
<li>AJAX</li>
<li>Webcron</li>
<li>Cron</li>
</ul>
</div>
<div class="section" id="cron-jobs">
<h2>Cron jobs<a class="headerlink" href="#cron-jobs" title="Permalink to this headline">¶</a></h2>
<p>You can schedule cron jobs in three ways &#8211; using AJAX, Webcron, or cron. The
default method is to use AJAX.  However, the recommended method is to use cron.
The following sections describe the differences between each method.</p>
<div class="section" id="ajax">
<h3>AJAX<a class="headerlink" href="#ajax" title="Permalink to this headline">¶</a></h3>
<p>The AJAX scheduling method is the default option.  Unfortunately, however, it is
also the least reliable. Each time a user visits the Nextcloud page, a single
background job is executed. The advantage of this mechanism is that it does not
require access to the system nor registration with a third party service. The
disadvantage of this mechanism, when compared to the Webcron service, is that it
requires regular visits to the page for it to be triggered.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Especially when using the Activity App or external storages, where new
files are added, updated or deleted one of the two methods below should be
preferred.</p>
</div>
</div>
<div class="section" id="webcron">
<h3>Webcron<a class="headerlink" href="#webcron" title="Permalink to this headline">¶</a></h3>
<p>By registering your Nextcloud <code class="docutils literal"><span class="pre">cron.php</span></code> script address at an external webcron
service (for example, <a class="reference external" href="https://www.easycron.com/">easyCron</a>), you ensure that background jobs are executed
regularly. To use this type of service with your server, you must be able to
access your server using the Internet. For example:</p>
<div class="highlight-python"><div class="highlight"><pre>URL to call: http[s]://&lt;domain-of-your-server&gt;/nextcloud/cron.php
</pre></div>
</div>
</div>
<div class="section" id="cron">
<h3>Cron<a class="headerlink" href="#cron" title="Permalink to this headline">¶</a></h3>
<p>Using the operating system cron feature is the preferred method for executing
regular tasks.  This method enables the execution of scheduled jobs without the
inherent limitations the Web server might have.</p>
<p>To run a cron job on a *nix system, every 15 minutes, under the default Web
server user (often, <code class="docutils literal"><span class="pre">www-data</span></code> or <code class="docutils literal"><span class="pre">wwwrun</span></code>), you must set up the following
cron job to call the <strong>cron.php</strong> script:</p>
<div class="highlight-python"><div class="highlight"><pre># crontab -u www-data -e
*/15  *  *  *  * php -f /var/www/nextcloud/cron.php
</pre></div>
</div>
<p>You can verify if the cron job has been added and scheduled by executing:</p>
<div class="highlight-python"><div class="highlight"><pre># crontab -u www-data -l
*/15  *  *  *  * php -f /var/www/nextcloud/cron.php
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You have to replace the path <code class="docutils literal"><span class="pre">/var/www/nextcloud/cron.php</span></code> with the
path to your current Nextcloud installation.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">On some systems it might be required to call <strong>php-cli</strong> instead of <strong>php</strong>.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Please refer to the crontab man page for the exact command syntax.</p>
</div>
</div>
<div class="section" id="systemd">
<h3>systemd<a class="headerlink" href="#systemd" title="Permalink to this headline">¶</a></h3>
<p>If systemd is installed on the system, a systemd timer could be an alternative to a cronjob.</p>
<p>This approach requires two files: <strong>nextcloudcron.service</strong> and <strong>nextcloudcron.timer</strong>. Create these two files in <code class="docutils literal"><span class="pre">/etc/systemd/system/</span></code>.</p>
<p><strong>nextcloudcron.service</strong> should look like this:</p>
<div class="highlight-python"><div class="highlight"><pre>[Unit]
Description=Nextcloud cron.php job

[Service]
User=www-data
ExecStart=/usr/bin/php -f /var/www/nextcloud/cron.php

[Install]
WantedBy=basic.target
</pre></div>
</div>
<p>Replace the user <code class="docutils literal"><span class="pre">www-data</span></code> with the user of your http server and <code class="docutils literal"><span class="pre">/var/www/nextcloud/cron.php</span></code> with the location of <strong>cron.php</strong> in your nextcloud directory.</p>
<p><strong>nextcloudcron.timer</strong> should look like this:</p>
<div class="highlight-python"><div class="highlight"><pre>[Unit]
Description=Run Nextcloud cron.php every 15 minutes

[Timer]
OnBootSec=5min
OnUnitActiveSec=15min
Unit=nextcloudcron.service

[Install]
WantedBy=timers.target
</pre></div>
</div>
<p>The important parts in the timer-unit are <code class="docutils literal"><span class="pre">OnBootSec</span></code> and <code class="docutils literal"><span class="pre">OnUnitActiveSec</span></code>.``OnBootSec`` will start the timer 5 minutes after boot, otherwise you would have to start it manually after every boot. <code class="docutils literal"><span class="pre">OnUnitActiveSec</span></code> will set a 15 minute timer after the service-unit was last activated.</p>
<p>Now all that is left is to start and enable the timer by running these commands:</p>
<div class="highlight-python"><div class="highlight"><pre>systemctl start nextcloudcron.timer
systemctl enable nextcloudcron.timer
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Select the option <code class="docutils literal"><span class="pre">Cron</span></code> in the admin menu for background jobs. if left on <code class="docutils literal"><span class="pre">AJAX</span></code> it would execute the AJAX job on every page load.</p>
</div>
</div>
</div>
</div>


            
<ul class="prevnext-title list-unstyled list-inline">
  <li class="prev">
    <a href="caching_configuration.html" title="Previous Chapter: Configuring memory caching"><span class="glyphicon glyphicon-chevron-left visible-sm"></span><span class="hidden-sm">&laquo; Configuring memory caching</span>
    </a>
  </li>
  <li class="next">
    <a href="config_sample_php_parameters.html" title="Next Chapter: Config.php Parameters"><span class="glyphicon glyphicon-chevron-right visible-sm"></span><span class="hidden-sm">Config.php Parameters &raquo;</span>
    </a>
  </li>
</ul>
					</div>
				</div>
			</div>
  </main>  
  </div>
</div>
  </body>
</html>