<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>
<channel>
	<title>G-Loaded Journal &#187; Administration</title>
	<atom:link href="http://www.g-loaded.eu/tag/administration/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.g-loaded.eu</link>
	<description>An open-source software and technology related journal</description>
	<lastBuildDate>Mon, 05 Dec 2011 19:55:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<item>
		<title>Speed up Apache by including htaccess files into httpd.conf</title>
		<link>http://www.g-loaded.eu/2011/11/28/speed-up-apache-by-including-htaccess-files-into-httpd-conf/</link>
		<comments>http://www.g-loaded.eu/2011/11/28/speed-up-apache-by-including-htaccess-files-into-httpd-conf/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 05:12:59 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Security]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=2522</guid>
		<description><![CDATA[It is widely known that, if virtual hosts in Apache (httpd) are configured to permit vhost administrators override specific configuration options at the directory level using htaccess files, the web server consumes valuable time in order to check whether an htaccess file exists in every directory included in the requested path and parse it. On [...]]]></description>
			<content:encoded><![CDATA[<p>It is widely known that, if virtual hosts in Apache (httpd) are configured to permit vhost administrators override specific configuration options at the directory level using htaccess files, the web server consumes valuable time in order to check whether an htaccess file exists in every directory included in the requested <em>path</em> and parse it. On the other hand, many popular web applications utilize htaccess files, especially those residing in the <em>DocumentRoot</em>, in order to implement pretty URLs or HTTP redirections, which is extremely convenient since the virtual host owner does not have to edit httpd&#8217;s configuration directly. So, I had the idea to include the htaccess file of the DocumentRoot directory on the filesystem into the virtual host&#8217;s configuration.<br />
<span id="more-2522"></span><br />
Suppose we have the <code>/home/example.org/public_html/</code> directory on the filesystem, which serves as the document root of our virtualhost. The relevant httpd configuration for that vhost would look like this:</p>
<pre class="codesnp">
&lt;VirtualHost 123.123.123.123:80&gt;
  ServerName example.org:80
  ...
  DocumentRoot /home/example.org/public_html
  &lt;Directory /home/example.org/public_html&gt;
    AllowOverride All
    ...
  &lt;/Directory&gt;
  ...
&lt;/VirtualHost&gt;
</pre>
<p>In order to prevent the htaccess lookups on the filesystem without losing the htaccess functionality &#8211; at least at the DocumentRoot level- I transformed the configuration to the following:</p>
<pre class="codesnp">
&lt;VirtualHost 123.123.123.123:80&gt;
  ServerName example.org:80
  ...
  DocumentRoot /home/example.org/public_html
  &lt;Directory /home/example.org/public_html&gt;
    AllowOverride None
    Include /home/example.org/public_html/.htaccess
    ...
  &lt;/Directory&gt;
  ...
&lt;/VirtualHost&gt;
</pre>
<p>Let&#8217;s see what we have accomplished with this:</p>
<ol>
<li>httpd does not waste any time looking for and parsing htaccess files resulting in faster request processing,</li>
<li>the virtual host administrator can still override the configuration options of the document root manually or through the web interface of the web application.</li>
</ol>
<p>Seems like a win-win situation performance and functionality wise.</p>
<p>But, as usual, there is no win-win situation without a downside. In this case, the above trick weakens the server&#8217;s security. Let&#8217;s see how.</p>
<p>Although the configuration of a directory can be set in both <code>httpd.conf</code> and the directory&#8217;s htaccess file, not all directives can be used in both contexts. htaccess files support a subset of the directives that can be used in the <code>Directory</code> context within <code>httpd.conf</code>. By including the htaccess file in httpd&#8217;s configuration the vhost admin is no longer restricted to that subset of directives.</p>
<p>This means that by implementing the above configuration the virtual host administrator is granted more privileges regarding the configuration of the virtual host. This also means that a potential attacker, that would exploit a vulnerability of the web application, would be granted the same privileges once he got write access to that htaccess file.</p>
<p>So, although this trick may seem like a good idea at first, it is in fact a rather <strong>bad idea</strong> and <em>should never be used in production, unless you trust the virtual host administrator and the web application</em>. I do not intend to use such a configuration and I do not recommend it. There are by far better ways to speed up Apache.</p>
<p>Your comments and suggestions are welcome.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2011/11/28/speed-up-apache-by-including-htaccess-files-into-httpd-conf/">Speed up Apache by including htaccess files into httpd.conf</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2007/02/21/htaccess-cheat-sheet/" rel="bookmark">.htaccess Cheat Sheet</a></li>
<li><a href="http://www.g-loaded.eu/2007/08/10/ssl-enabled-name-based-apache-virtual-hosts-with-mod_gnutls/" rel="bookmark">SSL-enabled Name-based Apache Virtual Hosts with mod_gnutls</a></li>
<li><a href="http://www.g-loaded.eu/2008/05/10/use-mod_deflate-to-compress-web-content-delivered-by-apache/" rel="bookmark">Use mod_deflate to Compress Web Content delivered by Apache</a></li>
<li><a href="http://www.g-loaded.eu/2010/03/28/script-apache-error-report/" rel="bookmark">Script for Apache Error Report</a></li>
<li><a href="http://www.g-loaded.eu/2008/12/18/using-the-mod_dav_svn-svnparentpath-directive-with-multiple-authz-files/" rel="bookmark">Using the mod_dav_svn SVNParentPath directive with multiple authz files</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2011/11/28/speed-up-apache-by-including-htaccess-files-into-httpd-conf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Running supervisor 3 on CentOS 5</title>
		<link>http://www.g-loaded.eu/2011/05/12/running-supervisor-3-on-centos-5/</link>
		<comments>http://www.g-loaded.eu/2011/05/12/running-supervisor-3-on-centos-5/#comments</comments>
		<pubDate>Thu, 12 May 2011 04:56:52 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[RHEL]]></category>
		<category><![CDATA[RPM]]></category>
		<category><![CDATA[Servers]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=2263</guid>
		<description><![CDATA[It&#8217;s been a long time since the last time I checked the available software for managing long running processes. Software in this particular area has evolved and, after some research and testing on a virtual machine, I tried to install supervisord in a CentOS 5.6 box. Unfortunately, no RPM package exists for the latest 3.X [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a long time since the last time I checked the available software for managing long running processes. Software in this particular area has evolved and, after some research and testing on a virtual machine, I tried to install <a href="http://supervisord.org/">supervisord</a> in a CentOS 5.6 box. Unfortunately, no RPM package exists for the latest 3.X version, so I decided to go through the procedure to rebuild the <em>supervisor RPM</em> from the Fedora development tree, since v3.X has some really cool features I cannot do without.<br />
<span id="more-2263"></span><br />
If you haven&#8217;t built an RPM package before, you will need to go through a simple procedure in order to <a href="http://www.g-loaded.eu/2006/04/05/how-to-build-rpm-packages-on-fedora/">prepare an RPM building environment</a>. It is highly recommended that you build your packages in a separate box, dedicated to this kind of work, and also use a typical user and not <em>root</em> for building. So, let&#8217;s get the source RPM of <strong>supervisord</strong> from a Fedora Rawhide mirror:</p>
<pre class="console">
wget ftp://ftp.cc.uoc.gr/mirrors/linux/fedora/linux/development/rawhide/source/SRPMS/supervisor-3.0-0.4.a10.fc16.src.rpm
</pre>
<p>The simplest way to build an RPM for our CentOS release is to use the <code>--rebuild</code> option of <code>rpmbuild</code>:</p>
<pre class="console">
rpmbuild --rebuild supervisor-3.0-0.4.a10.fc16.src.rpm
</pre>
<p>Wait a few seconds for it to finish and then your binary RPM package will be in <code>~/&lt;your_building_env&gt;/RPMS/...</code>. </p>
<p>To satisfy dependencies, you will also need the package <strong>python-meld3</strong>. So, download and rebuild it:</p>
<pre class="console">
wget ftp://ftp.cc.uoc.gr/mirrors/linux/fedora/linux/development/rawhide/source/SRPMS/python-meld3-0.6.7-4.fc16.src.rpm
rpmbuild --rebuild python-meld3-0.6.7-4.fc16.src.rpm
</pre>
<p>Having built RPM packages for <strong>supervisor</strong> and <strong>python-meld3</strong>, you can now transfer them to a testing box and install them:</p>
<pre class="console">
yum localinstall /path/to/supervisor.rpm /path/to/python-meld3
yum install python-elementtree
</pre>
<p>We also installed <strong>elementtree</strong> as this is a dependency missing from the supervisor spec file (note to self: file a bug report).</p>
<p>Finally, try to start supervisord:</p>
<pre class="console">
/etc/init.d/supervisord start
</pre>
<p>Surprisingly, it complains about the missing elementtree!</p>
<pre class="codesnp">
Starting supervisord: Traceback (most recent call last):
  File "/usr/bin/supervisord", line 5, in ?
    from pkg_resources import load_entry_point
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 2479, in ?
    working_set.require(__requires__)
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 585, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 483, in resolve
    raise DistributionNotFound(req)  # XXX put more info here
pkg_resources.DistributionNotFound: elementtree
</pre>
<p>Checking the requirements file at: <code>/usr/lib/python2.4/site-packages/supervisor-3.0a10-py2.4.egg-info/requires.txt</code> there are no special version requirements:</p>
<pre class="codesnp">
meld3 >= 0.6.5
elementtree
[iterparse]
cElementTree >= 1.0.2
</pre>
<p>After some investigation on the supervisor-users mailing list, I found a message that <a href="http://lists.supervisord.org/pipermail/supervisor-users/2007-October/000106.html">indicated</a> that <em>setuptools.setup()</em> should be used instead of <em>distutils.core.setup()</em> in the <strong>setup.py</strong> script.</p>
<p>So, the dependency resolution depends on the way the package has been installed! I didn&#8217;t even bother to patch setup.py&#8230; Knowing that the dependencies are correctly installed, I commented out the <code>elementtree</code> line and also the <code>meld3</code> line as this caused the same error.</p>
<p>So, my <code>/usr/lib/python2.4/site-packages/supervisor-3.0a10-py2.4.egg-info/requires.txt</code> file looks like this:</p>
<pre class="codesnp">
#meld3 >= 0.6.5
#elementtree
[iterparse]
cElementTree >= 1.0.2
</pre>
<p>Now supervisor starts without errors:</p>
<pre class="console">
# /etc/init.d/supervisord start
Starting supervisord:                                      [  OK  ]
# cat /var/log/supervisor/supervisord.log
2011-05-12 02:56:08,221 CRIT Supervisor running as root (no user in config file)
2011-05-12 02:56:08,267 INFO RPC interface 'supervisor' initialized
2011-05-12 02:56:08,267 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2011-05-12 02:56:08,271 INFO daemonizing the supervisord process
2011-05-12 02:56:08,272 INFO supervisord started with pid 21337
</pre>
<p>This is what it takes to run <strong>supervisord 3</strong> in CentOS 5 or RHEL 5. If you have any comments and suggestions, please let me know in the comments below.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2011/05/12/running-supervisor-3-on-centos-5/">Running supervisor 3 on CentOS 5</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2009/12/18/high-cpu-usage-centos-guest-virtualbox-vmware/" rel="bookmark">High CPU usage while running CentOS as guest on Virtualbox or VMware</a></li>
<li><a href="http://www.g-loaded.eu/2009/04/07/sticking-with-centos-rpmforge-and-yum-priorities-for-now/" rel="bookmark">Sticking with CentOS, RPMforge and yum-priorities for now</a></li>
<li><a href="http://www.g-loaded.eu/2009/04/09/yum-priorities-configuration-for-a-centos-desktop/" rel="bookmark">YUM-Priorities Configuration for a CentOS Desktop</a></li>
<li><a href="http://www.g-loaded.eu/2011/02/28/awaiting-centos-6/" rel="bookmark">Awaiting CentOS 6</a></li>
<li><a href="http://www.g-loaded.eu/2006/11/20/my-running-dog/" rel="bookmark">My running dog</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2011/05/12/running-supervisor-3-on-centos-5/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>mod_wsgi incompatible with mod_python</title>
		<link>http://www.g-loaded.eu/2010/04/07/mod_wsgi-incompatible-with-mod_python/</link>
		<comments>http://www.g-loaded.eu/2010/04/07/mod_wsgi-incompatible-with-mod_python/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 09:00:58 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[WSGI]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1676</guid>
		<description><![CDATA[This is a quick note that mod_wsgi daemon processes are now incompatible with mod_python. Upgraded mod_wsgi earlier today in CentOS and saw the following note. I guess this limitation has been around for a while before affecting CentOS/RHEL: ################################################################################# # mod_python and mod_wsgi compatibility note ################################################################################# # mod_wsgi will deadlock if run in daemon mode [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick note that <a href="http://code.google.com/p/modwsgi/">mod_wsgi</a> daemon processes are now incompatible with <a href="http://www.modpython.org/">mod_python</a>. Upgraded <strong>mod_wsgi</strong> earlier today in CentOS and saw the following note. I guess this limitation has been around for a while before affecting CentOS/RHEL:<br />
<span id="more-1676"></span></p>
<pre class="codesnp">
#################################################################################
# mod_python and mod_wsgi compatibility note
#################################################################################
# mod_wsgi will deadlock if run in daemon mode while mod_python is enabled
# do not enable both mod_python and mod_wsgi if you are going to use the
# WSGIDaemonProcess directive
# In previous version of mod_wsgi, apache would segfault when both mod_wsgi
# and mod_python were enabled.  This update does not guarantee that will not
# happen.
#################################################################################
# Do not enable mod_python and mod_wsgi in the same apache process.
#################################################################################
</pre>
<p>Keep this in mind if you plan to mix both modules under the same Apache instance.</p>
<p><strong>Update</strong>: As <a href="http://blog.dscpl.com.au/">Graham</a> pointed out in <a href="http://www.g-loaded.eu/2010/04/07/mod_wsgi-incompatible-with-mod_python/#comment-12257">this comment</a>, there is no issue if <strong>mod_python 3.3.1</strong> is used. That&#8217;s great news because I would miss the flexibility of mod_python when it comes to request processing.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2010/04/07/mod_wsgi-incompatible-with-mod_python/">mod_wsgi incompatible with mod_python</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2006/11/20/my-running-dog/" rel="bookmark">My running dog</a></li>
<li><a href="http://www.g-loaded.eu/2010/01/02/spamassassin-fh_date_past_20xx-test-buggy-in-2010/" rel="bookmark">Spamassassin FH_DATE_PAST_20XX test buggy in 2010</a></li>
<li><a href="http://www.g-loaded.eu/2008/12/09/making-a-directory-writable-by-the-webserver/" rel="bookmark">Making a directory writable by the webserver</a></li>
<li><a href="http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/" rel="bookmark">SELinux audit reports script</a></li>
<li><a href="http://www.g-loaded.eu/2006/01/24/beagle-part-ii/" rel="bookmark">Beagle Part II</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2010/04/07/mod_wsgi-incompatible-with-mod_python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Permanently remove deleted posts and topics in bbPress</title>
		<link>http://www.g-loaded.eu/2010/04/07/permanently-delete-posts-topics-bbpress/</link>
		<comments>http://www.g-loaded.eu/2010/04/07/permanently-delete-posts-topics-bbpress/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 06:51:50 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[bbPress]]></category>
		<category><![CDATA[Maintenance]]></category>
		<category><![CDATA[Snippet]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1686</guid>
		<description><![CDATA[Permanently removing deleted posts and topics in bbPress can be cumbersome. bbPress does not provide a decent way to completely remove deleted content from the database. I am not sure why&#8230; In my case, these posts mostly contain spam and there is absolutely no reason to keep them in the database any more. As it [...]]]></description>
			<content:encoded><![CDATA[<p>Permanently removing deleted posts and topics in bbPress can be cumbersome. bbPress does not provide a decent way to completely remove deleted content from the database. I am not sure why&#8230; In my case, these posts mostly contain spam and there is absolutely no reason to keep them in the database any more. As it usually happens when I try to administer bbPress, I ended up executing SQL queries at the MySQL prompt. I hereby publish these SQL statements.<br />
<span id="more-1686"></span><br />
First delete all posts in deleted topics:</p>
<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> bb_posts <span style="color: #993333; font-weight: bold;">WHERE</span> post_id <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span>
    <span style="color: #993333; font-weight: bold;">SELECT</span> post_id <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#40;</span>
        <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">DISTINCT</span><span style="color: #66cc66;">&#40;</span>p<span style="color: #66cc66;">.</span>post_id<span style="color: #66cc66;">&#41;</span>
        <span style="color: #993333; font-weight: bold;">FROM</span> bb_posts <span style="color: #993333; font-weight: bold;">AS</span> p <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> bb_topics <span style="color: #993333; font-weight: bold;">AS</span> t <span style="color: #993333; font-weight: bold;">ON</span> p<span style="color: #66cc66;">.</span>topic_id<span style="color: #66cc66;">=</span>t<span style="color: #66cc66;">.</span>topic_id
        <span style="color: #993333; font-weight: bold;">WHERE</span> t<span style="color: #66cc66;">.</span>topic_status<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span>
    <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> bb_posts_in_deleted_topics
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>
<p>Then remove all deleted posts:</p>
<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> bb_posts <span style="color: #993333; font-weight: bold;">WHERE</span> post_status<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span>;</pre></div></div>
<p>Finally, remove all deleted topics:</p>
<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> bb_topics <span style="color: #993333; font-weight: bold;">WHERE</span> topic_status<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span>;</pre></div></div>
<p>In the bbPress administration panel, you can now use the &#8220;Tools&#8221; section to recount posts.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2010/04/07/permanently-delete-posts-topics-bbpress/">Permanently remove deleted posts and topics in bbPress</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2009/10/06/reclaiming-the-forums-from-bots/" rel="bookmark">Reclaiming the forums from bots</a></li>
<li><a href="http://www.g-loaded.eu/2007/04/25/bbpress-for-wordpress/" rel="bookmark">bbPress for WordPress</a></li>
<li><a href="http://www.g-loaded.eu/2007/07/10/bbpress-registration-functions-patch/" rel="bookmark">bbPress registration functions patch</a></li>
<li><a href="http://www.g-loaded.eu/2008/05/09/remove-generator-meta-tag-wordpress-plugin/" rel="bookmark">Remove-Generator-Meta-Tag WordPress Plugin</a></li>
<li><a href="http://www.g-loaded.eu/2006/11/27/effectively-remove-a-user-from-the-system/" rel="bookmark">Effectively remove a user from the system</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2010/04/07/permanently-delete-posts-topics-bbpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Script for Apache Error Report</title>
		<link>http://www.g-loaded.eu/2010/03/28/script-apache-error-report/</link>
		<comments>http://www.g-loaded.eu/2010/03/28/script-apache-error-report/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 17:26:47 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Cron]]></category>
		<category><![CDATA[Report]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Snippet]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1648</guid>
		<description><![CDATA[The last incident with the php-cgi errors as a result of a bad PHP script made me re-evaluate the daily reports I receive from the server. I realized that a report about the httpd errors that have occured during the previous day, including all virtualhosts, is more important than I had initially thought. Such a [...]]]></description>
			<content:encoded><![CDATA[<p>The last incident with the <a href="http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/">php-cgi errors</a> as a result of a bad PHP script made me re-evaluate the daily reports I receive from the server. I realized that a report about the <em>httpd errors</em> that have occured during the previous day, including all virtualhosts, is more important than I had initially thought. Such a report would have brought the problem to my attention much earlier and could also point me to the right direction while I was trying to figure out what was the cause of it. Fortunately, I found a nice error report generator for this purpose.<br />
<span id="more-1648"></span><br />
The script is called <a href="http://www.librelogiciel.com/software/ScanErrLog/action_Presentation">scanerrlog</a> and has some quite nice features. I highly recommend you check it out. In order to run it you will also need an extra Python module, <a href="http://www.librelogiciel.com/software/jaxml/action_Presentation">jaxml</a>. Download both packages and extract <strong>scanerrlog.py</strong> and <strong>jaxml.py</strong> to the same directory. Then you can call <code>scanerrlog.py</code> using the following cronjob.</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/env bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Error Report for httpd</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Requires:</span>
<span style="color: #666666; font-style: italic;">#   - scanerrlog - http://www.librelogiciel.com/software/ScanErrLog/action_Presentation</span>
<span style="color: #666666; font-style: italic;">#   - jaxml - http://www.librelogiciel.com/software/jaxml/action_Presentation</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>error_log \
    <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>vhosts<span style="color: #000000; font-weight: bold;">/*/</span>log<span style="color: #000000; font-weight: bold;">/</span>error_log \
    <span style="color: #000000; font-weight: bold;">|</span> python <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>scanerrlog.py <span style="color: #660033;">-f</span> text \
    <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;<span style="color: #780078;">`hostname`</span> - Apache Error Report&quot;</span> root<span style="color: #000000; font-weight: bold;">@</span>localhost
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>
<p>Some notes:</p>
<ol>
<li>Make sure that this cronjob runs before <strong>log rotation</strong> takes place.</li>
<li>The above shell script concatenates the <strong>error_log</strong> files from the main web server and all <em>virtualhosts</em>. Edit the paths to reflect your server configuration and virtualhost layout.</li>
<li>Edit the path to <code>scanerrlog.py</code>.</li>
</ol>
<p>Scanerrlog has some quite nice features that let you further customize the report. Make sure you read the help message.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2010/03/28/script-apache-error-report/">Script for Apache Error Report</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/" rel="bookmark">SELinux audit reports script</a></li>
<li><a href="http://www.g-loaded.eu/2009/10/05/strange-mod_dav_svn-error/" rel="bookmark">Strange mod_dav_svn error</a></li>
<li><a href="http://www.g-loaded.eu/2011/11/28/speed-up-apache-by-including-htaccess-files-into-httpd-conf/" rel="bookmark">Speed up Apache by including htaccess files into httpd.conf</a></li>
<li><a href="http://www.g-loaded.eu/2007/08/10/ssl-enabled-name-based-apache-virtual-hosts-with-mod_gnutls/" rel="bookmark">SSL-enabled Name-based Apache Virtual Hosts with mod_gnutls</a></li>
<li><a href="http://www.g-loaded.eu/2006/09/25/how-to-integrate-seaudit-report-in-logwatch/" rel="bookmark">How to integrate seaudit-report in logwatch</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2010/03/28/script-apache-error-report/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Issues with the feeds are now resolved</title>
		<link>http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/</link>
		<comments>http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 06:06:46 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Errors]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Wordpress]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1634</guid>
		<description><![CDATA[This is just a quick notice that during the last five days there was a problem with the website feeds. The web server returned a 500 Internal Server Error to almost all requests for /feed/ URLs. Also, there was a big increase of the server&#8217;s CPU load behind the scenes, which was caused by php-cgi [...]]]></description>
			<content:encoded><![CDATA[<p>This is just a quick notice that during the last five days there was a problem with the website feeds. The web server returned a <em>500 Internal Server Error</em> to almost all requests for <code>/feed/</code> URLs. Also, there was a big increase of the server&#8217;s <strong>CPU load</strong> behind the scenes, which was caused by <em>php-cgi</em> processes. It turned out that a custom plugin (unpublished) I had written for WordPress in the past was the cause of all the trouble, but, before coming to that conclusion, the fact that the problems had started without me doing anything on the blog during the last weeks together with a series of other random observations led me do a thorough examination of the whole server just in case.<br />
<span id="more-1634"></span><br />
So, after spending two days in front of a Linux terminal, I came to the conclusion that the following code had been problematic from the beginning and it was like a time-bomb for which the time had come to cause issues to the web site and the server that hosted it.</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> rsse_add_related_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$PostBody</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>rsse_verify_feed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$PostBody</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'yarpp_related'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$PostBody</span> <span style="color: #339933;">.=</span> yarpp_related<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'rss'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$PostBody</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rsse_add_related_posts'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">252</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>
<p>This code used a function of another plugin to attach a &#8216;<em>related posts</em>&#8216; section at the end of the full content of each feed entry. As soon as I commented out the above filter and started attaching the related-posts section to the feed content through the <a href="http://mitcho.com/code/yarpp/">YARPP</a> plugin&#8217;s administration interface, everything was normal again. No more php-cgi processes timing-out or over-consuming the CPU cycles.</p>
<p>The following graph shows clearly the problematic period:</p>
<div id="attachment_1639" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.g-loaded.eu/wp-content/uploads/phpcgi-cpu-time.png"><img src="http://www.g-loaded.eu/wp-content/uploads/phpcgi-cpu-time.png" alt="php-cgi processes consuming the CPU" title="phpcgi-cpu-time" width="640" class="size-full wp-image-1639" /></a><p class="wp-caption-text">php-cgi processes consuming the CPU</p></div>
<p>The httpd error_log included many errors like the following:</p>
<pre class="codesnp">
[...]
Allowed memory size of 33554432 bytes exhausted (tried to allocate 18893 bytes)
[...]
mod_fcgid: process ... exit(communication error), terminated by calling exit(), return code: 1
[...]
[warn] (104)Connection reset by peer: mod_fcgid: read data from fastcgi server error.
[...]
[warn] mod_fcgid: stderr: PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 4864 bytes)
[...]
Premature end of script headers: index.php
[...]
</pre>
<p>Note that these errors might appear in several occasions.</p>
<p>In my case, finding that faulty piece of code was a huge relief, I can tell you.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/">Issues with the feeds are now resolved</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2007/01/12/wordpress-206-feed-issues-resolved/" rel="bookmark">WordPress 2.0.6 &#8211; Feed Issues Resolved</a></li>
<li><a href="http://www.g-loaded.eu/2009/11/19/g-loaded-feeds/" rel="bookmark">G-Loaded Feeds</a></li>
<li><a href="http://www.g-loaded.eu/2009/10/08/redmine-deployment-delayed/" rel="bookmark">Redmine deployment delayed</a></li>
<li><a href="http://www.g-loaded.eu/2007/07/12/issue-addressed-author-feeds-deliver-full-content/" rel="bookmark">Issue addressed: Author feeds deliver full content</a></li>
<li><a href="http://www.g-loaded.eu/2008/10/17/status-of-content-availability-via-feeds/" rel="bookmark">Status of content availability via feeds</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Python SSH Server for UNIX Systems using Twisted.conch</title>
		<link>http://www.g-loaded.eu/2010/03/26/python-ssh-server-unix-twisted-conch/</link>
		<comments>http://www.g-loaded.eu/2010/03/26/python-ssh-server-unix-twisted-conch/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 20:27:00 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Remote]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Twisted]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1572</guid>
		<description><![CDATA[I can still recall the excitement of the first time I tried to access and administer a remote system using SSH. Accessing my shell at a remote machine securely, being able to do local and remote port forwarding in order to access remote services through encrypted tunnels, X forwarding, secure file transfers using scp or [...]]]></description>
			<content:encoded><![CDATA[<p>I can still recall the excitement of the first time I tried to access and administer a remote system using <strong>SSH</strong>. Accessing my shell at a remote machine securely, being able to do local and remote port forwarding in order to access remote services through encrypted tunnels, X forwarding, secure file transfers using <em>scp</em> or <em>sftp</em>, <a href="http://www.g-loaded.eu/2005/11/10/ssh-with-keys/">authentication using public key infrastructure</a> are just a few of the features that justify the excitement of the first time. The only <em>Secure Shell</em> server implementation I had used all that time was the <a href="http://www.openssh.com/">OpenSSH</a> server. Although this is an open-source project, the fact that it is written in C makes it extremely difficult for me to have fun with it by making any modifications in order to implement even simple things like command filtering. This is because I have never programmed in <strong>C</strong> and do not intend to learn how to do it in the foreseeable future. So what I&#8217;ve been looking for today was a server implementation of the <strong>SSH2 protocol</strong> written in <a href="http://python.org">Python</a>. Unfortunately, there is no such project ready for immediate use. I had to hack my own! After several hours of trial and error, having written dozens of sample scripts for testing, I finally created a minimal project, called <strong>RapidSSH</strong>, in order to demonstrate how to create a fully functional SSH server with just a few lines of Python code by using <em>Twisted.conch</em>, part of the <a href="http://twistedmatrix.com">Twisted Framework</a>. Read on&#8230;<br />
<span id="more-1572"></span><br />
At first, I tried to experiment with the <a href="http://twistedmatrix.com/documents/current/conch/examples/sshsimpleserver.py">sshsimpleserver.py</a> example script that exists on the Twisted homepage. But, soon I realized that this script is there just to give an idea about how to use <code>Twisted.conch</code> and also provide a sensible starting point for your own implementations. That script was not even close in having the functionality I had in mind. After spending some time examining the Twisted source code, I found a fantastic, but completely undocumented, module: <a href="http://twistedmatrix.com/trac/browser/trunk/twisted/conch/unix.py">twisted.conch.unix</a>. Having gained some experience by my experimentation with <code>sshsimpleserver.py</code> I managed to easily put the pieces together and come up with the SSH server implementation as shown below.</p>
<p>But first, let&#8217;s install some <strong>dependencies</strong>. I assume that you will try the code on a machine aimed for testing, so I won&#8217;t be using the system&#8217;s package manager but instead use <strong>easy_install</strong> to install the needed Python modules. Other commands like <em>pip</em> could be used as well. If you do not want to mess with your system-wide python installation, just use <strong>virtualenv</strong> and <strong>pip</strong>, but I won&#8217;t go into the details about how to use these tools in the current document.</p>
<p>Install the needed dependencies:</p>
<pre class="console">
easy_install pycrypto
easy_install pyasn1
easy_install pam
easy_install twisted
</pre>
<p>Make sure you have <strong>gcc</strong> installed, because it will be needed to complete the installation of Twisted and PyCrypto.</p>
<p>I have created a project for this code at <strong>Bitbucket</strong>, called <a href="http://bitbucket.org/gnotaras/rapidssh/">RapidSSH</a>. This will make it easier to share code and ideas about SSH server implementations in Python using Twisted.</p>
<p>Filename: <code>scripts/rapidsshd_unix.py</code></p>
<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># This file is part of rapidssh - http://bitbucket.org/gnotaras/rapidssh/</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># rapidssh - A set of Secure Shell (SSH) server implementations in Python</span>
<span style="color: #808080; font-style: italic;">#            using Twisted.conch, part of the Twisted Framework.</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Copyright (c) 2010 George Notaras - http://www.g-loaded.eu</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<span style="color: #808080; font-style: italic;"># of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<span style="color: #808080; font-style: italic;"># in the Software without restriction, including without limitation the rights</span>
<span style="color: #808080; font-style: italic;"># to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<span style="color: #808080; font-style: italic;"># copies of the Software, and to permit persons to whom the Software is</span>
<span style="color: #808080; font-style: italic;"># furnished to do so, subject to the following conditions:</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># The above copyright notice and this permission notice shall be included in</span>
<span style="color: #808080; font-style: italic;"># all copies or substantial portions of the Software.</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<span style="color: #808080; font-style: italic;"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span style="color: #808080; font-style: italic;"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<span style="color: #808080; font-style: italic;"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span style="color: #808080; font-style: italic;"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<span style="color: #808080; font-style: italic;"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</span>
<span style="color: #808080; font-style: italic;"># THE SOFTWARE.</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Initially based on the sshsimpleserver.py kindly published by:</span>
<span style="color: #808080; font-style: italic;"># Twisted Matrix Laboratories - http://twistedmatrix.com</span>
<span style="color: #808080; font-style: italic;">#</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> pam
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">conch</span>.<span style="color: black;">unix</span> <span style="color: #ff7700;font-weight:bold;">import</span> UnixSSHRealm
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">cred</span> <span style="color: #ff7700;font-weight:bold;">import</span> portal
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">cred</span>.<span style="color: black;">credentials</span> <span style="color: #ff7700;font-weight:bold;">import</span> IUsernamePassword
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">cred</span>.<span style="color: black;">checkers</span> <span style="color: #ff7700;font-weight:bold;">import</span> ICredentialsChecker
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">cred</span>.<span style="color: black;">error</span> <span style="color: #ff7700;font-weight:bold;">import</span> UnauthorizedLogin
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">conch</span>.<span style="color: black;">checkers</span> <span style="color: #ff7700;font-weight:bold;">import</span> SSHPublicKeyDatabase
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">conch</span>.<span style="color: black;">ssh</span> <span style="color: #ff7700;font-weight:bold;">import</span> factory, userauth, connection, keys, session
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">internet</span> <span style="color: #ff7700;font-weight:bold;">import</span> reactor, defer
<span style="color: #ff7700;font-weight:bold;">from</span> zope.<span style="color: black;">interface</span> <span style="color: #ff7700;font-weight:bold;">import</span> implements
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">python</span> <span style="color: #ff7700;font-weight:bold;">import</span> log
&nbsp;
<span style="color: #808080; font-style: italic;"># Logging</span>
<span style="color: #808080; font-style: italic;"># Currently logging to STDERR</span>
log.<span style="color: black;">startLogging</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">stderr</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Server-side public and private keys. These are the keys found in</span>
<span style="color: #808080; font-style: italic;"># sshsimpleserver.py. Make sure you generate your own using ssh-keygen!</span>
&nbsp;
publicKey = <span style="color: #483d8b;">'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAGEArzJx8OYOnJmzf4tfBEvLi8DVPrJ3/c9k2I/Az64fxjHf9imyRJbixtQhlH9lfNjUIx+4LmrJH5QNRsFporcHDKOTwTTYLh5KmRpslkYHRivcJSkbh/C+BR3utDS555mV'</span>
&nbsp;
privateKey = <span style="color: #483d8b;">&quot;&quot;&quot;-----BEGIN RSA PRIVATE KEY-----
MIIByAIBAAJhAK8ycfDmDpyZs3+LXwRLy4vA1T6yd/3PZNiPwM+uH8Yx3/YpskSW
4sbUIZR/ZXzY1CMfuC5qyR+UDUbBaaK3Bwyjk8E02C4eSpkabJZGB0Yr3CUpG4fw
vgUd7rQ0ueeZlQIBIwJgbh+1VZfr7WftK5lu7MHtqE1S1vPWZQYE3+VUn8yJADyb
Z4fsZaCrzW9lkIqXkE3GIY+ojdhZhkO1gbG0118sIgphwSWKRxK0mvh6ERxKqIt1
xJEJO74EykXZV4oNJ8sjAjEA3J9r2ZghVhGN6V8DnQrTk24Td0E8hU8AcP0FVP+8
PQm/g/aXf2QQkQT+omdHVEJrAjEAy0pL0EBH6EVS98evDCBtQw22OZT52qXlAwZ2
gyTriKFVoqjeEjt3SZKKqXHSApP/AjBLpF99zcJJZRq2abgYlf9lv1chkrWqDHUu
DZttmYJeEfiFBBavVYIF1dOlZT0G8jMCMBc7sOSZodFnAiryP+Qg9otSBjJ3bQML
pSTqy7c3a2AScC/YyOwkDaICHnnD3XyjMwIxALRzl0tQEKMXs6hH8ToUdlLROCrP
EhQ0wahUTCk1gKA4uPD6TMTChavbh4K63OvbKg==
-----END RSA PRIVATE KEY-----&quot;&quot;&quot;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> PamPasswordDatabase:
    <span style="color: #483d8b;">&quot;&quot;&quot;Authentication/authorization backend using the 'login' PAM service&quot;&quot;&quot;</span>
    credentialInterfaces = IUsernamePassword,
    implements<span style="color: black;">&#40;</span>ICredentialsChecker<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> requestAvatarId<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, credentials<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> pam.<span style="color: black;">authenticate</span><span style="color: black;">&#40;</span>credentials.<span style="color: black;">username</span>, credentials.<span style="color: black;">password</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> defer.<span style="color: black;">succeed</span><span style="color: black;">&#40;</span>credentials.<span style="color: black;">username</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> defer.<span style="color: black;">fail</span><span style="color: black;">&#40;</span>UnauthorizedLogin<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;invalid password&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> UnixSSHdFactory<span style="color: black;">&#40;</span>factory.<span style="color: black;">SSHFactory</span><span style="color: black;">&#41;</span>:
    publicKeys = <span style="color: black;">&#123;</span>
        <span style="color: #483d8b;">'ssh-rsa'</span>: keys.<span style="color: black;">Key</span>.<span style="color: black;">fromString</span><span style="color: black;">&#40;</span>data=publicKey<span style="color: black;">&#41;</span>
    <span style="color: black;">&#125;</span>
    privateKeys = <span style="color: black;">&#123;</span>
        <span style="color: #483d8b;">'ssh-rsa'</span>: keys.<span style="color: black;">Key</span>.<span style="color: black;">fromString</span><span style="color: black;">&#40;</span>data=privateKey<span style="color: black;">&#41;</span>
    <span style="color: black;">&#125;</span>
    services = <span style="color: black;">&#123;</span>
        <span style="color: #483d8b;">'ssh-userauth'</span>: userauth.<span style="color: black;">SSHUserAuthServer</span>,
        <span style="color: #483d8b;">'ssh-connection'</span>: connection.<span style="color: black;">SSHConnection</span>
    <span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Components have already been registered in twisted.conch.unix</span>
&nbsp;
portal = portal.<span style="color: black;">Portal</span><span style="color: black;">&#40;</span>UnixSSHRealm<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
portal.<span style="color: black;">registerChecker</span><span style="color: black;">&#40;</span>PamPasswordDatabase<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>   <span style="color: #808080; font-style: italic;"># Supports PAM</span>
portal.<span style="color: black;">registerChecker</span><span style="color: black;">&#40;</span>SSHPublicKeyDatabase<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># Supports PKI</span>
UnixSSHdFactory.<span style="color: black;">portal</span> = portal
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    reactor.<span style="color: black;">listenTCP</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5022</span>, UnixSSHdFactory<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    reactor.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>
<p>Some notes:</p>
<ul>
<li>The server uses the very same public and private keys as found in the <code>sshsimpleserver.py</code> script. Make sure you generate new keys using <strong>ssh-keygen</strong> if you plan to run this on a public server (although this not recommended).</li>
<li>Twisted included a module for PAM authentication, <code>twisted.cred.pamauth</code>, but unfortunately I could not locate one of its dependencies to make it work. So, I used the excellent <a href="http://atlee.ca/software/pam/">python-pam</a> to create a custom PAM authenticator class.</li>
<li>I can guess what you might thought when you read about this code:<br />
<blockquote>Python is a cross-platform programming language. Twisted runs on Windows. So, is this a solution for running a SSH server on Win32?</p></blockquote>
<p> Well, at the moment it won&#8217;t run because internally it uses some Python modules that are available on UNIX platforms only. But, I intend to investigate the possibility of running this on <strong>Windows</strong> since I already need something like that.</li>
</ul>
<p>We can now enjoy our Python SSH server. Run as root:</p>
<pre class="console">
python scripts/rapidsshd_unix.py
</pre>
<p>From another machine, connect to the server using an <em>ssh client</em>:</p>
<pre class="console">
ssh -p 5022 rocky@arena
</pre>
<p>If you have deployed your public key in the <code>~/.ssh/authorized_keys</code> file on the remote machine (<em>arena</em>), you should be able to authenticate using the public key:</p>
<pre class="console">
ssh -p 5022 -i /path/to/private.key rocky@arena
</pre>
<p>You should get output like the following on the server:</p>
<pre class="console">
[root@arena ~]# python ssh.py
2010-03-26 21:30:05+0000 [-] Log opened.
2010-03-26 21:30:05+0000 [-] __main__.UnixSSHdFactory starting on 5022
2010-03-26 21:30:05+0000 [-] Starting factory <__main__.UnixSSHdFactory instance at 0xb7a0b0cc>
2010-03-26 21:30:13+0000 [__main__.UnixSSHdFactory] disabling diffie-hellman-group-exchange because we cannot find moduli file
2010-03-26 21:30:13+0000 [SSHServerTransport,0,192.168.0.172] kex alg, key alg: diffie-hellman-group1-sha1 ssh-rsa
2010-03-26 21:30:13+0000 [SSHServerTransport,0,192.168.0.172] outgoing: aes256-ctr hmac-sha1 none
2010-03-26 21:30:13+0000 [SSHServerTransport,0,192.168.0.172] incoming: aes256-ctr hmac-sha1 none
2010-03-26 21:30:14+0000 [SSHServerTransport,0,192.168.0.172] NEW KEYS
2010-03-26 21:30:14+0000 [SSHServerTransport,0,192.168.0.172] starting service ssh-userauth
2010-03-26 21:30:17+0000 [SSHService ssh-userauth on SSHServerTransport,0,192.168.0.172] rocky trying auth none
2010-03-26 21:30:17+0000 [SSHService ssh-userauth on SSHServerTransport,0,192.168.0.172] rocky trying auth publickey
2010-03-26 21:30:17+0000 [SSHService ssh-userauth on SSHServerTransport,0,192.168.0.172] rocky trying auth publickey
2010-03-26 21:30:17+0000 [SSHService ssh-userauth on SSHServerTransport,0,192.168.0.172] rocky authenticated with publickey
2010-03-26 21:30:17+0000 [SSHService ssh-userauth on SSHServerTransport,0,192.168.0.172] starting service ssh-connection
2010-03-26 21:30:17+0000 [SSHService ssh-connection on SSHServerTransport,0,192.168.0.172] got channel session request
2010-03-26 21:30:17+0000 [SSHChannel session (0) on SSHService ssh-connection on SSHServerTransport,0,192.168.0.172] channel open
2010-03-26 21:30:17+0000 [SSHChannel session (0) on SSHService ssh-connection on SSHServerTransport,0,192.168.0.172] pty request: xterm (24L, 80L, 0L, 0L)
2010-03-26 21:30:17+0000 [SSHChannel session (0) on SSHService ssh-connection on SSHServerTransport,0,192.168.0.172] getting shell
</pre>
<p>This first release of the <a href="http://bitbucket.org/gnotaras/rapidssh/">RapidSSH</a> project exists solely for demonstration purposes. Don&#8217;t get fooled by the small amount of code. Information about how to put the pieces together is scarce and it required a lot trial&#038;error and source code reading. The above implementation contains none of the customizations I had in mind. These will be done as soon as I find some time to do so. Until then it will be nice to hear about your experiences or implementations you have worked on.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2010/03/26/python-ssh-server-unix-twisted-conch/">Python SSH Server for UNIX Systems using Twisted.conch</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2006/09/23/use-python-to-get-the-web-page-data-in-epiphany/" rel="bookmark">Use Python to get the web page data in Epiphany</a></li>
<li><a href="http://www.g-loaded.eu/2006/05/17/epiphany-python-console-open-new-tab/" rel="bookmark">Epiphany Python Console &#8211; Open New Tab</a></li>
<li><a href="http://www.g-loaded.eu/2007/01/31/python-irc-bot/" rel="bookmark">Python IRC Bot</a></li>
<li><a href="http://www.g-loaded.eu/2006/04/07/python-crash-course/" rel="bookmark">Python Crash Course</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/configure-vnc-server-in-fedora/" rel="bookmark">Set up the VNC Server in Fedora</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2010/03/26/python-ssh-server-unix-twisted-conch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Using setenforce to switch SELinux mode wisely</title>
		<link>http://www.g-loaded.eu/2009/10/30/selinux-setenforce-mode/</link>
		<comments>http://www.g-loaded.eu/2009/10/30/selinux-setenforce-mode/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 15:05:14 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SELinux]]></category>
		<category><![CDATA[System]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1401</guid>
		<description><![CDATA[setenforce is a command line utility that is used to switch the mode SELinux is running in from enforcing to permissive and vice versa without requiring a reboot. Lately, I&#8217;ve started experimenting again with SELinux on a live system. The default targeted SELinux policy, as usual, needs some adjustment to work with a custom server [...]]]></description>
			<content:encoded><![CDATA[<p><strong>setenforce</strong> is a command line utility that is used to switch the mode <a href="http://en.wikipedia.org/wiki/Security-Enhanced_Linux">SELinux</a> is running in from <em>enforcing</em> to <em>permissive</em> and vice versa without requiring a reboot. Lately, I&#8217;ve started experimenting again with <strong>SELinux</strong> on a live system. The default targeted SELinux policy, as usual, needs some adjustment to work with a custom server configuration. So, I created some custom policy modules and loaded them onto the live system in order to test if my &#8220;<em>allow</em>&#8221; rules were effective.<br />
<span id="more-1401"></span><br />
In such cases, the system administrator must be wise enough to minimize risk. SELinux is not a forgiving feature. If the custom policy blocks the execution of a software and SELinux is running in enforcing mode, then the software does not run. That&#8217;s what SELinux is about after all.</p>
<p>The <strong>permissive mode</strong> exists mainly for testing. In this mode, the auditing mechanism generates notices (<em>AVC Denials</em>) about the action/event that was blocked, but without actually blocking that action/event. It is just a way to check what would have happened if SELinux had been running in <em>enforcing</em> mode. There are two ways to switch SELinux to permissive mode. One is to configure it through its configuration file (<code>/etc/selinux/config</code> on <abbr title="Enterprise Linux">EL</abbr>) to start in permissive mode on boot and the other is to use the aforementioned utility, <em>setenforce</em>, to switch modes while the system is live.</p>
<p>When performing tests on a live system, I usually take all precautions to minimize the risk of failure and usually, if possible, I am around to monitor the progress of the test. But, this time I had to use the custom SELinux policy for some days to see if it is actually effective or it needs further fine-tuning.</p>
<p><strong>The Mistake</strong>: I used setenforce to set SELinux into permissive mode (<code>/usr/sbin/setenforce 0</code>). setenforce is for <strong>temporary changes</strong> and it is definitely not suitable for testing the policy for a long period of time. This is because if for any reason the system reboots, SELinux will be set back into the mode that is defined into its configuration file. The mode set by <code>setenforce</code> does not survive a reboot. So, if the custom policy happens to be incomplete, it will block the server&#8217;s normal operation after the reboot. And such reboots can happen&#8230;</p>
<p>This is exactly what I experienced yesterday. The datacenter on which my virtual server is hosted had problems with its main power supply. This caused one hour of downtime. But G-Loaded&#8217;s outage was a lot greater, because my custom SELinux policy was incomplete. SELinux was started in enforcing mode, so my faulty policy blocked my www service.</p>
<p>This should be a lesson to anyone who performs tests on live systems. The Right Thing&trade; was simple: boot the server into permissive mode and do as many tests as desired. I can blame the datacenter for the one-hour downtime, but for the 7-hour unavailability of <a href="http://www.g-loaded.eu">G-Loaded</a> I am the only one to blame.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2009/10/30/selinux-setenforce-mode/">Using setenforce to switch SELinux mode wisely</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2006/12/20/selinux-audit-reports-script/" rel="bookmark">SELinux audit reports script</a></li>
<li><a href="http://www.g-loaded.eu/2008/11/26/using-a-switch-to-prevent-system-shutdownrebootsuspend/" rel="bookmark">Using a switch to prevent system shutdown/reboot/suspend</a></li>
<li><a href="http://www.g-loaded.eu/2007/02/09/server-upgraded-to-fedora-6/" rel="bookmark">Server upgraded to Fedora 6</a></li>
<li><a href="http://www.g-loaded.eu/2008/06/18/use-the-alternatives-system-to-switch-to-a-custom-firefox-release/" rel="bookmark">Use the Alternatives System to switch to a custom Firefox release</a></li>
<li><a href="http://www.g-loaded.eu/2006/09/25/how-to-integrate-seaudit-report-in-logwatch/" rel="bookmark">How to integrate seaudit-report in logwatch</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2009/10/30/selinux-setenforce-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>How to change the Timezone</title>
		<link>http://www.g-loaded.eu/2009/10/07/how-to-change-the-timezone/</link>
		<comments>http://www.g-loaded.eu/2009/10/07/how-to-change-the-timezone/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 13:44:03 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Fedora]]></category>
		<category><![CDATA[Scientific Linux]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Service]]></category>
		<category><![CDATA[System]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1183</guid>
		<description><![CDATA[Usually, the only time I make a change to the timezone setting of the operating system is during the installation time. But it may happen that a change to that setting is necessary. There are several ways to do this, but, as usual, there is only one Right Way&#8482; to set the timezone info in [...]]]></description>
			<content:encoded><![CDATA[<p>Usually, the only time I make a change to the <strong>timezone</strong> setting of the operating system is during the installation time. But it may happen that a change to that setting is necessary. There are several ways to do this, but, as usual, there is only one <em>Right Way</em>&trade; to set the timezone info in your <strong>Linux</strong> distribution. I investigated it for a while and I think I have figured out how to do it right using <strong>command-line</strong> utilities on <a href="http://fedoraproject.org">Fedora</a> and all RHEL rebuilds (<a href="http://centos.org">CentOS</a>, <a href="http://www.scientificlinux.org/">Scientific Linux</a>, etc). I am quite certain that many people miss this piece of information, so I describe it in detail right below.<br />
<span id="more-1183"></span></p>
<h4>Configuration</h4>
<p>The procedure must be performed by <strong>root</strong>.</p>
<p>First of all, you need to edit the <em>/etc/sysconfig/clock</em> file:</p>
<pre class="codesnp">
ZONE="Etc/GMT"
UTC=true
</pre>
<p>Please, read the notes below for more information about the settings above.</p>
<p>Then run the <strong>tzdata-update</strong> utility. This copies the correct zonefile to <em>/etc/localtime</em>:</p>
<pre class="console">
/usr/sbin/tzdata-update
</pre>
<p>Finally, update the system time by either running <strong>ntpd</strong> or the <strong>ntpdate</strong> utility. Both are part of the <code>ntp</code> RPM package, so if this is not installed, just use &#8220;<code>yum install ntp</code>&#8221; to get it installed.</p>
<pre class="console">
/usr/sbin/ntpdate -b pool.ntp.org
</pre>
<p>This will make sure your time is correct.</p>
<p>You can set a <strong>cronjob</strong> to update the system&#8217;s time using ntpdate, like this:</p>
<pre class="codesnp">
#
# Update the system time
#
55 23 * * * root /usr/sbin/ntpdate -4 -b pool.ntp.org 2>&#038;1 >> /var/log/ntpdate.log
</pre>
<h4>Notes</h4>
<p>Here are some notes about the configuration of the timezone:</p>
<ol>
<li>You can find the valid timezones by changing to the <code>/usr/share/zoneinfo/</code> directory. From there, any <em>relative path</em> to a timezone file is a valid timezone. For example, &#8220;<em>Etc/GMT</em>&#8220;, &#8220;<em>Europe/Athens</em>&#8220;, &#8220;<em>America/New_York</em>&#8221; et cetera.</li>
<li><strong>GMT</strong> and <strong>UTC</strong> time are practically the same and they both refer to the <a href="http://en.wikipedia.org/wiki/Greenwich_Mean_Time">Greenwich Mean Time</a>, so setting the timezone to &#8220;<em>Etc/UTC</em>&#8221; or &#8220;<em>Etc/GMT</em>&#8221; is practically the same.</li>
<li>In <code>/etc/sysconfig/clock</code> you can set whether the <strong>hardware clock</strong> is set to <strong>UTC/GMT</strong> time or to <strong>Local Time</strong>. I am not sure in what way the hardware clock gets involved is the time of the Operating System. But, anyway, if you know how the hardware clock is configured, set this accordingly to true or false. Usually, if I set the OS to use GMT time, I also set this to true regardless of the actual hardware clock configuration. More info on this is still needed.</li>
<li>In <code>/etc/sysconfig/clock</code> you may see the options <strong>ARC=false</strong> and <strong>SRM=false</strong>. These change the way the &#8220;epoch&#8221; is assumed by the console on Alpha systems and have no effect if you do not use such a platform. Delete them or leave as is, unless you know you need to set one of them to true.</li>
<li>In order to set the correct timezone, you could just create a <strong>symlink</strong> at <code>/etc/localtime</code> pointing to the correct timezone file in <code>/usr/share/zoneinfo/</code>. Then again, this would render the system configuration file <code>/etc/sysconfig/clock</code> (and thus all other applications that use it) useless and ineffective, so this method is generally <strong>not recommended</strong>.</li>
</ol>
<h4>Final thoughts</h4>
<p>Setting your server to use the correct time is very important. Generally, I hate it when I see web sites or other services having incorrect time. This reveals the web server or the web application administrator&#8217;s laziness or inability to properly configure the time. I hope this guide will help get rid of this issue.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2009/10/07/how-to-change-the-timezone/">How to change the Timezone</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2008/11/27/maxminds-geoip-dat-gz-location-change/" rel="bookmark">Maxmind&#8217;s GeoIP.dat.gz location change</a></li>
<li><a href="http://www.g-loaded.eu/2005/09/30/change-console-font-in-fedora/" rel="bookmark">Change console font in Fedora</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/05/assign-virtual-ips-to-your-nic/" rel="bookmark">Assign Virtual IPs to your NIC</a></li>
<li><a href="http://www.g-loaded.eu/2008/05/12/how-to-disable-ipv6-in-fedora-and-centos/" rel="bookmark">How to Disable IPv6 in Fedora and CentOS</a></li>
<li><a href="http://www.g-loaded.eu/2010/11/01/change-expiration-date-gpg-key/" rel="bookmark">How to change the expiration date of a GPG key</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2009/10/07/how-to-change-the-timezone/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Xen DomU using dynamic IP and hostname</title>
		<link>http://www.g-loaded.eu/2009/02/01/xen-domu-using-dynamic-ip-and-hostname/</link>
		<comments>http://www.g-loaded.eu/2009/02/01/xen-domu-using-dynamic-ip-and-hostname/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 14:16:43 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[DHCP]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[Xen]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=845</guid>
		<description><![CDATA[During the last months, I&#8217;ve been experimenting with Xen virtualization. An old computer, equipped with a Pentium III running at 700Mhz, 512MB of RAM and an 160GB IDE HDD runs four installations of my favorite Linux distribution, CentOS, one as a Dom0 and the other three as DomUs with 64MB of memory each. I remember [...]]]></description>
			<content:encoded><![CDATA[<p>During the last months, I&#8217;ve been experimenting with <a href="http://www.xen.org/">Xen</a> virtualization. An old computer, equipped with a <em>Pentium III</em> running at 700Mhz, 512MB of <em>RAM</em> and an 160GB <em>IDE</em> HDD runs <strong>four</strong> installations of my <em>favorite</em> Linux distribution, <a href="http://centos.org/">CentOS</a>, one as a <a href="http://wiki.xensource.com/xenwiki/Dom0">Dom0</a> and the other three as <a href="http://wiki.xensource.com/xenwiki/DomU">DomU</a>s with 64MB of memory each.<br />
<span id="more-845"></span><br />
I remember that one of the first things I needed to test was whether all those virtual machines could properly use my <strong>DHCP</strong> service, located on a separate machine within my <strong>LAN</strong>, and get a <em>dynamic IP</em>. Furthermore, each time <strong>dhclient</strong> ran on the Dom0 or any of the DomUs in order to obtain a dynamic IP address, it also sent a name (non <em>FQDN</em>) to the DHCP service. This name represented the name the machine wished to use as a <strong>hostname</strong>. The DHCP server should generate an <em>FQDN</em> out of that name and update the <em>forward</em> and <em>reverse zones</em> on the <strong>DNS</strong> server, so that each virtual machine&#8217;s <em>FQDN</em> name could properly resolve to the relevant IP address, which had been allocated to the <abbr title="Virtual Machine">VM</abbr> by the <em>DHCP</em> service. All this had already been set up in my home LAN since a long time ago, but had never actually tested it with multiple computers or other devices and virtualization definitely provided me with this option.</p>
<p>While I was performing the operating system installations, everything seemed to work as expected. Each virtual machine obtained a <strong>dynamic IP</strong> address and the <strong>DNS records</strong> were updated correctly. Glad that things work, I turned off Dom0 after the tests.</p>
<p>At a later time, when I switched <em>Dom0</em> on again, I noticed that I <strong>could not reach any of the virtual machines</strong>. Their fully qualified domain names that had been allocated to them by the DHCP service would not resolve to the proper IP. To make it worse, it seemed that the virtual machines had no active leases at all!</p>
<p>Soon I discovered that <strong>xendomains</strong>, the service responsible for starting and stopping the unprivileged Xen domains (DomU), whenever Domain Zero was shut down, it just <strong>saved</strong> the domain U&#8217;s state for later restoration instead of initiating the DomU&#8217;s shutdown procedure. When Dom0 was brought up again, <em>xendomains</em> <strong>restored</strong> the saved DomU states instead of forcing the domains to boot up normally.</p>
<p>I assume this is like suspending a laptop, which has obtained its IP automatically from a DHCP service within LAN A, moving it to a LAN B, and then bringing it up again within that LAN. It is almost certain that for an arbitrary amount of time you would experience connectivity problems.</p>
<p>In both cases above, at the time the machine resumes operations, the <strong>dhclient</strong> script (or any other similar script) is not run in order to <em>renew</em> the machine&#8217;s IP address.</p>
<p>Fortunately, this behaviour of the <code>xendomains</code> service is configurable. In order to force all DomUs to shutdown, instead of suspending, during Domain 0&#8242;s shutdown, all you have to do is make following changes in <code>/etc/sysconfig/xendomains</code>:</p>
<p>Leave empty the XENDOMAINS_SAVE variable. By default, it uses /var/lib/xen/save as the directory where the states of the DomUs are saved. By leaving it empty, the states of the virtual machines are not saved, but they are shut down as usual.</p>
<pre class="codesnp">
XENDOMAINS_SAVE=""
</pre>
<p>The second modification involves setting the XENDOMAINS_RESTORE variable to false. This determines whether saved domains will be restored from the directory set in the XENDOMAINS_SAVE variable during the Dom0 startup:</p>
<pre class="codesnp">
XENDOMAINS_RESTORE=false
</pre>
<p>From now on, whenever Dom0 starts up, it will force all U domains to boot up normally. Contrariwise, whenever Dom0 shuts down, it will force all DomU to shut down as well. No domain state saving or restoration happens any more.</p>
<p>This means that the network service on each DomU, hence the <em>dhclient</em> script, will run <strong>every time</strong> the domain U starts up or shuts down, <strong>ensuring proper allocation of dynamic IP addresses and hostnames</strong> by the DHCP service. Of course, this adds much overhead to both the boot and power off process of Domain Zero (Dom0), but it seems that there is no other way to overcome this problem. If you know of a better way, please let me know.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2009/02/01/xen-domu-using-dynamic-ip-and-hostname/">Xen DomU using dynamic IP and hostname</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2006/12/19/howto-dhcp-server-dhcpd-configuration/" rel="bookmark">Howto: DHCP Server (dhcpd) Configuration</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/05/assign-virtual-ips-to-your-nic/" rel="bookmark">Assign Virtual IPs to your NIC</a></li>
<li><a href="http://www.g-loaded.eu/2005/11/10/configure-vnc-server-in-fedora/" rel="bookmark">Set up the VNC Server in Fedora</a></li>
<li><a href="http://www.g-loaded.eu/2006/01/06/partition-images-with-partimage-and-partimaged/" rel="bookmark">Partition images with Partimage and Partimaged</a></li>
<li><a href="http://www.g-loaded.eu/2008/12/10/almost-saying-goodbye-to-innovation/" rel="bookmark">Almost saying goodbye to innovation</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2009/02/01/xen-domu-using-dynamic-ip-and-hostname/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>

