<?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/"
	>

<channel>
	<title>geek scrap &#187; unix</title>
	<atom:link href="http://geekscrap.com/tags/unix/feed/" rel="self" type="application/rss+xml" />
	<link>http://geekscrap.com</link>
	<description>there is at least one way to do it</description>
	<lastBuildDate>Tue, 12 Apr 2011 10:14:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Using screen as your login shell</title>
		<link>http://geekscrap.com/2010/02/using-screen-as-your-login-shell/</link>
		<comments>http://geekscrap.com/2010/02/using-screen-as-your-login-shell/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 10:42:29 +0000</pubDate>
		<dc:creator>geekscrap</dc:creator>
				<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://geekscrap.com/?p=609</guid>
		<description><![CDATA[GNU screen is a nice utility that allows running multiple interactive shells from the same terminal session and allows you to detach from your terminal while keeping those shells alive. Later on, you can re-attach to your background screen to get back to your shells. It has a lot more features like automatic session logging and [...]]]></description>
			<content:encoded><![CDATA[<p>GNU <a rel="nofollow" href="http://www.gnu.org/software/screen/">screen</a> is a nice utility that allows running multiple interactive shells from the same terminal session and allows you to detach from your terminal while keeping those shells alive. Later on, you can re-attach to your background screen to get back to your shells. It has a lot more features like automatic session logging and terminal window splitting. You can discover them all in the <a href="http://www.gnu.org/software/screen/manual/screen.html">manual</a>.</p>
<p>How many times did you start a long-running task like gcc compilation on a remote server and then suddenly needed to disconnect from your shell? Maybe you just needed to move to some other place with your laptop, but if you disconnected from your LAN, your ssh connection would go down. How many times you thought &#8220;Damn, if I had launched screen before this&#8230;&#8221;?</p>
<p><span id="more-609"></span>The trick to save your compile time and not break your schedule is simple: just have your shell .profile script run screen at startup on your remote server. For bash, the syntax is simple, just add the following line at the end of your ˜/.profile script:</p>
<pre lang="bash">if [ ${SHLVL} -eq 1 ]; then
    ((SHLVL+=1)); export SHLVL
    exec screen -R -e "^Ee" ${SHELL} -l
fi</pre>
<p>Quick implementation notes:</p>
<ol>
<li>Parameter -R reattaches to an existing detached session, if it exists, otherwise creates a new one.</li>
<li>Parameter -e sets a non-standard escape character. This is useful since you don&#8217;t want login screen to interfere with other screens you may spawn during your activity. I chose Ctrl-E as it&#8217;s not used by other well-known keyboard shortcuts and works on most OSes.</li>
</ol>
<p>To detach from your server type <em>Ctrl-E d</em> or just close your terminal window. Running processes will remain active in background, without detaching from your shell. When you connect to your remote shell again, you&#8217;ll get back to your session.</p>
<p>Do you like Unix tips like this? Follow me on <a rel="nofollow" href="http://twitter.com/geekscrap">Twitter</a> or subscribe to my <a href="http://geekscrap.com/feed/">RSS feed</a> for more.</p>
]]></content:encoded>
			<wfw:commentRss>http://geekscrap.com/2010/02/using-screen-as-your-login-shell/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Process management roundup/1</title>
		<link>http://geekscrap.com/2010/01/process-management-roundup-1/</link>
		<comments>http://geekscrap.com/2010/01/process-management-roundup-1/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 14:11:17 +0000</pubDate>
		<dc:creator>geekscrap</dc:creator>
				<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[launchd]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[redhat]]></category>
		<category><![CDATA[smf]]></category>
		<category><![CDATA[suse]]></category>
		<category><![CDATA[sysinitv]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://geekscrap.com/?p=143</guid>
		<description><![CDATA[Under UNIX-like operating systems, there are several ways to manage long-running processes such as daemons. Process management is a crucial aspect of system maintainance and therefore it&#8217;s one of the aspects to take into account when planning a deployment. Since available solutions are getting more and more complex and specialized, I thought of writing a [...]]]></description>
			<content:encoded><![CDATA[<p>Under UNIX-like operating systems, there are several ways to manage long-running processes such as daemons. Process management is a crucial aspect of system maintainance and therefore it&#8217;s one of the aspects to take into account when planning a deployment. Since available solutions are getting more and more complex and specialized, I thought of writing a series of articles to recap the state of the art and draw up a comparative analysis.</p>
<p>This post deals with two system-wide alternatives, sysinitv and Mac OS X&#8217;s launchd: the first represents the tradition, while the latter represent innovation. Feel free to use comments to share your tips.</p>
<p><span id="more-143"></span></p>
<h3>System V init</h3>
<p>Also known as <em>sysinitv</em>, it&#8217;s the historical choice for most unices. Every OS has customized its own version so there&#8217;s no common standard. First process, typically /sbin/init reads config in /etc/inittab and executes a series of commands, depending on which <em>runlevel</em> is currently set.</p>
<p>In typical configurations, init launches a main rc script on runlevel change (boot sequence runlevel, default multiuser runlevel, etc), which in turn runs all the initialization scripts in a runlevel-specific folder. For example, in Redhat Linux each system service has an init script in /etc/init.d/. These init scripts respond to a number of actions that can be passed as parameter, for example <em>/etc/init.d/sendmail start</em> runs a function that starts sendmail daemon. Typical actions include: <em>start, stop, restart, status</em>. Some scripts implement specific actions: for instance apache service implements <em>reload</em> action, which does a graceful signal-based reload. Furthermore, most OSes include additional dependency information in those scripts and import script configuration directives from external files (/etc/sysconfig/ on Debian, SuSE, etc, /etc/conf.d/ in Gentoo).</p>
<p>When rc scripts is ready to process init scripts, it looks in appropriate runlevel folder (in RedHat Linux and derivatives its /etc/rc.d/rc&lt;runlevel&gt;.d/,  Gentoo has /etc/runlevels/&lt;runlevel&gt;/, etc) and executes entries which are symlinks to the actual /etc/init.d scripts.</p>
<p>Most of these systems use a specific naming convention for these symlinks, to define order of execution (scripts are run in alphabetic order) and action to be passed as parameter. For example, on RedHat-style systems, scripts are named as S&lt;NN&gt;&lt;service&gt; or K&lt;NN&gt;&lt;service&gt;, where NN is a number from 00 to 99. S means start action (ie. <em>/etc/rc.d/rc3.d/S60sendmail start</em>), while K means stop action. In other systems such as Gentoo, order of execution is determined dynamically by dependency information (requires additional computing and dependency caching).</p>
<p>Operating systems typically implement command-line, ncurses-based or X11-based tools to manage adding and removing items from runlevels: <a rel="nofollow" href="http://www.linuxjournal.com/article/4445">chkconfig</a> under RedHat/CentOS, <a rel="nofollow" href="http://www.debuntu.org/how-to-manage-services-with-update-rc.d">update-rc.d</a> under Debian, <a rel="nofollow" href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&amp;chap=4#doc_chap2">rc-update</a> under Gentoo, <a rel="nofollow" href="http://www.marzocca.net/linux/bum.html">boot up manager</a> (bum) under Ubuntu.</p>
<p><strong>Pros</strong>: well known, easy for unix admins, easy to add new custom scripts.<br />
<strong>Cons</strong>: no common standard, no parallel execution (except for Gentoo), no support process monitoring (ie. restarting daemons on crash).</p>
<h3>launchd</h3>
<p>It&#8217;s installed by default on <strong>Mac OS X 10.4 (Tiger)</strong> and later. Once <a rel="nofollow" href="http://launchd.macosforge.org/">launchd</a> is run by the kernel, it runs /etc/rc (a BSD-style system wide initialization script) and scans<em>/System/Library/LaunchAgents</em> and <em>/Library/LaunchDaemons</em> for plist files. Each plist contains a series of properties that define behaviour of launchd and customize run setup (command parameters, working directory, process owner, resource limits, etc). Launchd monitors processes and dynamically acts to adapt process status to requirements defined by configuration. This includes: running process automatically at boot, respawning process on unexpected quit, starting and stopping process upon several conditions (cpu load, network status, filesystem mounts, file presence, time schedule, shutdown, sleep, etc).</p>
<p>Finally, launchd companion is user tool <a rel="nofollow" href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/launchctl.1.html">launchctl</a>, which interacts with launchd through a socket and allows administrator to send in requests like start, stop, list, limit, shutdown, etc.</p>
<p><strong>Pro</strong>: amazing configuration directives, powerful extension mechanism, post-spawn process monitoring and usage management, scheduled actions (as in cron), stdio-to-inet support as inetd, can add processes without configuration files.<br />
<strong>Cons</strong>: configuration plists are an Apple-world standard, many great features are Mac OS X specific, strict process launching requisites (see <a rel="nofollow" href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html">launchd.plist manpage</a>), no support for configurable dependencies, no support for custom process signaling, complex logic may lead to unexpected results.</p>
<p><em>(continues)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://geekscrap.com/2010/01/process-management-roundup-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
