{"id":257412,"date":"2015-05-18T14:32:02","date_gmt":"2015-05-18T10:32:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=257412"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=257412","title":{"rendered":"\u0420\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c web-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 Fabric"},"content":{"rendered":"<p>     \t\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0442\u0443\u0442, \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u0435\u0435. \u0420\u0430\u0441\u0442\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u0438\u0445 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f. <\/p>\n<ul>\n<li>\u041e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 <\/li>\n<li>\u041f\u0440\u043e \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0437\u0430\u0431\u044b\u0432\u0430\u044e\u0442, \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0443\u0442\u0430\u044e\u0442 \u043c\u0435\u0441\u0442\u0430\u043c\u0438 <\/li>\n<li>\u0427\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u0438\u0439 \u0444\u0430\u043a\u0442\u043e\u0440, \u043b\u0435\u0433\u043a\u043e\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u043d\u0435\u0434\u0430\u043b\u044c\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u044c <\/li>\n<\/ul>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0443\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0438, \u043c\u0435\u0441\u0442\u0430\u043c\u0438, \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0435 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432 \u043f\u0440\u043e\u0441\u0442\u0443\u044e, \u0440\u0443\u0442\u0438\u043d\u043d\u0443\u044e \u0438 \u0441\u043a\u0443\u0447\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0441 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c. <br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h5>\u041d\u0430\u0448\u0438 \u0446\u0435\u043b\u0438<\/h5>\n<ul>\n<li>\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0432 \u0442.\u0447. \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 <\/li>\n<li>\u0418\u043c\u0435\u0435\u043c \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 <\/li>\n<li>\u0418\u043c\u0435\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c <\/li>\n<\/ul>\n<h5>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Fabric<\/h5>\n<p>  \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <a href=\"http:\/\/www.fabfile.org\/\">fabric<\/a>. \u042d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u0434\u0430\u0447 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u043d \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u044d\u0442\u043e\u0439 <a href=\"http:\/\/habrahabr.ru\/post\/76619\/\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>. <\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0447\u0430\u044f \u0441\u0442\u0430\u043d\u0446\u0438\u044f \u0441 Linux \u0438 python(2.5-2.7). \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430:  <\/p>\n<pre><code class=\"bash\"># pip install fabric # pip install fabtools <\/code><\/pre>\n<h5>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u0439<\/h5>\n<p>  \u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0447\u0435\u0440\u0435\u0437 ssh. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0447\u0442\u043e \u0432\u044b \u0443\u0436\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043a\u043b\u044e\u0447, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 ~\/.ssh\/config \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u043b\u0438 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0438\u0437 \u0434\u0435\u043f\u043b\u043e\u0439-\u0438\u0436\u0435\u043d\u0435\u0440\u043e\u0432 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u043a\u043a\u0430\u0443\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438\u043b\u0438 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0435\u0433\u043e. <\/p>\n<p>  \u0418\u0437 \u0447\u0435\u0433\u043e \u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u043d\u0430\u0448 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0434\u0435\u043f\u043b\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442:  <\/p>\n<pre><code class=\"bash\">myapp_deploy\/         fabfile.py    #\u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c \u0441\u043a\u0440\u0438\u043f\u0442, \u0435\u0433\u043e \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e.         sudoers\/                 devel_sudo    #\u0438\u043d\u043a\u043b\u0443\u0434 \u0432 \/etc\/sudoers \u0434\u043b\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u0432 \u0434\u0435\u043f\u043b\u043e\u0439-\u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0430         config\/                 config-production.php    #\u043a\u043e\u043d\u0444\u0438\u0433 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <\/code><\/pre>\n<p>  \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043d\u0430\u0431\u043e\u0440 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0445 \u0435\u0433\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0443. \u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u043c\u043e\u0434\u0443\u043b\u0438 \u0438 \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u043f\u043e-\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. <\/p>\n<h5>\u041f\u0438\u0448\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442<\/h5>\n<pre><code class=\"python\">from fabric.api import env, run, sudo, local, put, settings import fabtools  def production():         &quot;&quot;&quot;Defines production environment&quot;&quot;&quot;         env.hosts = ['192.168.1.2']    #\u0430\u0434\u0440\u0435\u0441 \u0445\u043e\u0441\u0442\u0430         env.shell = 'bash -c'    #\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0438\u0442\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434 \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u043c \u0445\u043e\u0441\u0442\u0435         env.use_ssh_config = True    #\u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043d\u0430\u0448\u0435\u0433\u043e ssh-\u043a\u043b\u0438\u0435\u043d\u0442\u0430          env.project_user = &quot;myappuser&quot;    #\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435         env.sudo_user = env.project_user         env.base_dir = &quot;\/apps&quot;    #\u0431\u0430\u0437\u043e\u0432\u0430\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430         env.domain_name = &quot;myapp.example.com&quot;    #FQDN \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u043d \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f         env.domain_path = &quot;%(base_dir)s\/%(domain_name)s&quot; % { 'base_dir':env.base_dir, 'domain_name':env.domain_name }    #\u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u0435 \u0438\u043c\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0434\u043b\u044f myapp         env.current_path = &quot;%(domain_path)s\/current&quot; % { 'domain_path':env.domain_path }    #\u043f\u0443\u0442\u044c \u0434\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 myapp         env.releases_path = &quot;%(domain_path)s\/releases&quot; % { 'domain_path':env.domain_path }    #\u043f\u0443\u0442\u044c \u0434\u043e \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0441 \u0440\u0435\u043b\u0438\u0437\u0430\u043c\u0438         env.git_clone = &quot;git@git.example.com:myapp.git&quot;    #\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439, \u043e\u0442\u043a\u0443\u0434\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442.          env.config_file = &quot;config\/config-production.php&quot;    #\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430  <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u042d\u0442\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043d\u0430\u0434\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u0412\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u0440\u0443\u0447\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c\u0443 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0443, \u0438\u043c\u0435\u044e\u0449\u0435\u043c\u0443 \u043f\u043e\u043b\u043d\u044b\u0435 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. <\/p>\n<pre><code class=\"python\">def permissions():         &quot;&quot;&quot;Set proper permissions for release&quot;&quot;&quot;         sudo(&quot;chown -R %(project_user)s:%(project_user)s %(domain_path)s&quot; % { 'domain_path':env.domain_path, 'project_user':env.sudo_user })  def setup():         &quot;&quot;&quot;Prepares one or more servers for deployment&quot;&quot;&quot;         with settings(sudo_user='root'):                 sudo(&quot;mkdir -p %(domain_path)s\/releases&quot; % { 'domain_path':env.domain_path })                     sudo(&quot;mkdir -p %(base_dir)s\/logs\/&quot; % { 'base_dir':env.base_dir })                     permissions()                      put(&quot;sudoers\/devel_sudo&quot;, &quot;\/tmp\/devel_sudo&quot;)                 sudo(&quot;chown root:root \/tmp\/devel_sudo&quot;)                 sudo(&quot;chmod 0440 \/tmp\/devel_sudo&quot;)                 sudo(&quot;mv \/tmp\/devel_sudo \/etc\/sudoers.d\/devel_sudo&quot;)  <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c\u0441\u044f \u0441 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0440\u0435\u043b\u0438\u0437\u043e\u0432 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435. \u0412\u043e\u0442 \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432:   <\/p>\n<pre><code class=\"bash\">\/apps         myapp.example.com\/                 current    #\u0441\u0438\u043c\u043b\u0438\u043d\u043a \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0440\u0435\u043b\u0438\u0437                 releases\/    #\u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0440\u0435\u043b\u0438\u0437\u043e\u0432                          release0                         release1                         ...                         releaseN    #\u043d\u0430\u0448 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0440\u0435\u043b\u0438\u0437 <\/code><\/pre>\n<p>  \u0418\u043d\u0434\u0435\u043a\u0441 \u0440\u0435\u043b\u0438\u0437\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0430\u0439\u043c\u0441\u0442\u0435\u043c\u043f\u0430. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0440\u0435\u043b\u0438\u0437 \u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0440\u0435\u043b\u0438\u0437\u044b (\u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043a\u0430\u0442\u0438\u0442\u044c\u0441\u044f) \u0438 \u043f\u0443\u0442\u0438 \u0434\u043e \u043d\u0438\u0445. <\/p>\n<pre><code class=\"python\">def releases():         &quot;&quot;&quot;List a releases made&quot;&quot;&quot;         env.releases = sorted(sudo('ls -x %(releases_path)s' % { 'releases_path':env.releases_path }).split())         if len(env.releases) &gt;= 1:                 env.current_revision = env.releases[-1]                 env.current_release = &quot;%(releases_path)s\/%(current_revision)s&quot; % { 'releases_path':env.releases_path, 'current_revision':env.current_revision }         if len(env.releases) &gt; 1:                 env.previous_revision = env.releases[-2]                 env.previous_release = &quot;%(releases_path)s\/%(previous_revision)s&quot; % { 'releases_path':env.releases_path, 'previous_revision':env.previous_revision } <\/code><\/pre>\n<p>  \u0414\u0435\u043f\u043b\u043e\u0439 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u0441\u0432\u044f\u0437\u0430\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u0430\u043a\u0438\u0445-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442, \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0435\u043b\u043e\u0430\u0434\u0438\u0442\u044c php-fpm, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 <a href=\"https:\/\/sixohthree.com\/1517\/php-and-the-realpath-cache\">\u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/a>.<\/p>\n<pre><code class=\"python\">def restart():         &quot;&quot;&quot;Restarts your application services&quot;&quot;&quot;         with settings(sudo_user='root',use_shell=False):                 sudo(&quot;\/etc\/init.d\/php5-fpm reload&quot;) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0431\u0440\u0430\u0437\u043e\u043c \u0437\u0430\u0431\u0438\u0440\u0430\u0442\u044c \u043a\u043e\u0434 \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430. \u0411\u0443\u0434\u0435\u043c \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438\u0437 git-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f.<\/p>\n<pre><code class=\"python\">def checkout():         &quot;&quot;&quot;Checkout code to the remote servers&quot;&quot;&quot;         env.timestamp = run(&quot;\/bin\/date +%s&quot;)         env.current_release = &quot;%(releases_path)s\/%(timestamp)s&quot; % { 'releases_path':env.releases_path, 'timestamp':env.timestamp }         sudo(&quot;cd %(releases_path)s; git clone -q -b master --depth 1 %(git_clone)s %(current_release)s&quot; % { 'releases_path':env.releases_path, 'git_clone':env.git_clone, 'current_release':env.current_release }) <\/code><\/pre>\n<p>  \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0441 \u0440\u0435\u043b\u0438\u0437\u043e\u043c<\/p>\n<pre><code class=\"python\">def copy_config():         &quot;&quot;&quot;Copy custom config to the remote servers&quot;&quot;&quot;         if not env.has_key('releases'):    #\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0440\u0435\u043b\u0438\u0437, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433                 releases()         put(&quot;%s&quot; % env.config_file, &quot;\/tmp\/config.php&quot;)         sudo(&quot;cp \/tmp\/config.php %(current_release)s\/config\/&quot; % { 'current_release':env.current_release })         run(&quot;rm \/tmp\/config.php&quot;) <\/code><\/pre>\n<p>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0438\u043c\u043b\u0438\u043d\u043a\u0430 \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0440\u0435\u043b\u0438\u0437 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c<\/p>\n<pre><code class=\"python\">def symlink():         &quot;&quot;&quot;Updates the symlink to the most recently deployed version&quot;&quot;&quot;         if not env.has_key('current_release'):                 releases()         sudo(&quot;ln -nfs %(current_release)s %(current_path)s&quot; % { 'current_release':env.current_release, 'current_path':env.current_path }) <\/code><\/pre>\n<p>  \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u044e \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0434\u0435\u043f\u043b\u043e\u044f \u0432 \u0435\u0434\u0438\u043d\u043e\u0435 \u0446\u0435\u043b\u043e\u0435<\/p>\n<pre><code class=\"python\">def deploy():         &quot;&quot;&quot;Deploys your project. This calls  'checkout','copy_config','migration','symlink','restart','cleanup'&quot;&quot;&quot;         checkout()         copy_config()         symlink()         restart() <\/code><\/pre>\n<p>  \u041f\u043e\u0434\u0443\u043c\u0430\u0435\u043c \u043d\u0430\u0434 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u0447\u0438\u0441\u0442\u0438\u0442\u044c \u0440\u0435\u043b\u0438\u0437\u044b.<\/p>\n<pre><code class=\"python\">def cleanup():         &quot;&quot;&quot;Clean up old releases&quot;&quot;&quot;         if not env.has_key('releases'):                 releases()         if len(env.releases) &gt; 10:                 directories = env.releases                 directories.reverse()                 del directories[:10]                 env.directories = ' '.join([ &quot;%(releases_path)s\/%(release)s&quot; % { 'releases_path':env.releases_path, 'release':release } for release in directories ])                 sudo(&quot;rm -rf %(directories)s&quot; % { 'directories':env.directories }) <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u043b\u0438\u0437\u0430 \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0442\u043a\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u0434\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<pre><code class=\"python\">def rollback_code():         &quot;&quot;&quot;Rolls back to the previously deployed version&quot;&quot;&quot;         if not env.has_key('releases'):                 releases()         if env.has_key('previous_release'):                 sudo(&quot;ln -nfs %(previous_release)s %(current_path)s && rm -rf %(current_release)s&quot; % { 'current_release':env.current_release, 'previous_release':env.previous_release, 'current_path':env.current_path })         else:                 print &quot;no releases older then current&quot;                 sys.exit(1)  def rollback():         &quot;&quot;&quot;Rolls back to a previous version and restarts&quot;&quot;&quot;         rollback_code()         restart() <\/code><\/pre>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u0445\u0432\u0430\u0442\u0438\u0442 \u043f\u0438\u0442\u043e\u043d\u0430.<\/p>\n<h5>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/h5>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0433\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0443\u043c\u0435\u0435\u0442 \u043d\u0430\u0448 \u0441\u043a\u0440\u0438\u043f\u0442, \u043c\u043e\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"bash\">$ fab --list Available commands:      checkout       Checkout code to the remote servers     cleanup        Clean up old releases     copy_config    Copy custom config to the remote servers     deploy         Deploys your project. This calls  'checkout','copy_config','migration','symlink','restart','cleanup'     permissions    Set proper permissions for release     production     Defines production environment     releases       List a releases made     restart        Restarts your application services     rollback       Rolls back to a previous version and restarts     rollback_code  Rolls back to the previously deployed version     setup          Prepares one or more servers for deployment     symlink        Updates the symlink to the most recently deployed version <\/code><\/pre>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u0435\u043f\u043b\u043e\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440<\/p>\n<pre><code class=\"bash\">$ fab production deploy [192.168.1.2] Executing task 'deploy' [192.168.1.2] run: \/bin\/date +%s [192.168.1.2] out: 1431941361 [192.168.1.2] out:  [192.168.1.2] sudo: cd \/apps\/myapp.example.com\/releases; git clone -q -b master --depth 1 git@git.example.com:myapp.git \/apps\/myapp.example.com\/releases\/1431941361 [192.168.1.2] sudo: ls -x \/apps\/myapp.example.com\/releases [192.168.1.2] out: 1431940514  1431940525       1431940537  1431940547  1431940558  1431940568  1431940578  1431940589  1431940599  1431941361 [192.168.1.2] out:  [192.168.1.2] put: config\/config-production.php -&gt; \/tmp\/config.php [192.168.1.2] sudo: cp \/tmp\/config.php \/apps\/myapp.example.com\/releases\/1431941361\/config\/ [192.168.1.2] run: rm \/tmp\/config.php [192.168.1.2] sudo: ln -nfs \/apps\/myapp.example.com\/releases\/1431941361 \/apps\/myapp.example.com\/current [192.168.1.2] sudo: \/etc\/init.d\/php-fpm reload [192.168.1.2] out: Reloading php-fpm: [18-May-2015 05:29:29] NOTICE: configuration file \/etc\/php-fpm.conf test is successful [192.168.1.2] out: [192.168.1.2] out:                                       [  OK  ] [192.168.1.2] out: [192.168.1.2] out:   Done. Disconnecting from 192.168.1.2... done. <\/code><\/pre>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0441 \u0440\u0430\u0437\u043d\u043e\u0439 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u043e\u0439.     \t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/257671\/\"> http:\/\/habrahabr.ru\/post\/257671\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0442\u0443\u0442, \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u0435\u0435. \u0420\u0430\u0441\u0442\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u0438\u0445 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f. <\/p>\n<ul>\n<li>\u041e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 <\/li>\n<li>\u041f\u0440\u043e \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0437\u0430\u0431\u044b\u0432\u0430\u044e\u0442, \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0443\u0442\u0430\u044e\u0442 \u043c\u0435\u0441\u0442\u0430\u043c\u0438 <\/li>\n<li>\u0427\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u0438\u0439 \u0444\u0430\u043a\u0442\u043e\u0440, \u043b\u0435\u0433\u043a\u043e\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u043d\u0435\u0434\u0430\u043b\u044c\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u044c <\/li>\n<\/ul>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0443\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0438, \u043c\u0435\u0441\u0442\u0430\u043c\u0438, \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0435 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432 \u043f\u0440\u043e\u0441\u0442\u0443\u044e, \u0440\u0443\u0442\u0438\u043d\u043d\u0443\u044e \u0438 \u0441\u043a\u0443\u0447\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0441 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-257412","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/257412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=257412"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/257412\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=257412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=257412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=257412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}