<?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>Cake Solutions Team Blog &#187; daemon</title>
	<atom:link href="http://www.cakesolutions.net/teamblogs/tag/daemon/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cakesolutions.net/teamblogs</link>
	<description>void magic() { }</description>
	<lastBuildDate>Tue, 07 Feb 2012 12:02:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Running dm Server as a service</title>
		<link>http://www.cakesolutions.net/teamblogs/2009/07/24/running-dm-server-as-a-service/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=running-dm-server-as-a-service</link>
		<comments>http://www.cakesolutions.net/teamblogs/2009/07/24/running-dm-server-as-a-service/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 14:33:24 +0000</pubDate>
		<dc:creator>Jan Machacek</dc:creator>
				<category><![CDATA[Jan's Blog]]></category>
		<category><![CDATA[daemon]]></category>
		<category><![CDATA[dm Server 2.0]]></category>
		<category><![CDATA[Service Wrapper]]></category>
		<category><![CDATA[Windows Service]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/?p=389</guid>
		<description><![CDATA[Once you install dm Server, you may want to run it as a service or daemon. In this post, I will give you an excerpt from Chapter 2 of dm Server 2.0 in Action. Running dm Server as daemon On &#8230; <a href="http://www.cakesolutions.net/teamblogs/2009/07/24/running-dm-server-as-a-service/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Once you install dm Server, you may want to run it as a service or daemon. In this post, I will give you an excerpt from Chapter 2 of dm Server 2.0 in Action.</p>
<h2>Running dm Server as daemon</h2>
<p>On UNIX platforms, you can use <code>nohup $SERVER_HOME/bin/startup.sh&#038;</code> to allow the dm Server’s shell process tree to become child of the init (or launchd) process and thus survive <code>SIGHUP</code> signal. </p>
<h2>Configuring dm Server as Windows service</h2>
<p>On Windows platforms, you can use Project Kenai’s winsw to run the dm Server as Windows service. The service wrapper can execute arbitrary executable file and pass it different command line arguments on service startup and shutdown. </p>
<p>To get started, download winsw from its homepage at <a href="http://projectkenai.com/projects/winsw/pages/Home">http://projectkenai.com/projects/winsw/pages/Home</a>. Once you have downloaded the <code>winsw.exe</code>, rename it to, for example, <code>dmss.exe</code> and copy it to <code>%SERVER_HOME%\bin</code>. The listing of <code>%SERVER_HOME%\bin</code> should now show files in Listing 1.</p>
<p>Listing 1. Files in %SERVER_HOME%\bin</p>
<pre>
C:\&gt;dir %SERVER_HOME%\bin
 Volume in drive C has no label.
 Volume Serial Number is 7408-8BB9

 Directory of C:\opt\springsource-dm-server-2\bin

24/07/2009  14:49    &lt;dir&gt;          .
24/07/2009  14:49    &lt;/dir&gt;&lt;dir &gt;          ..
24/07/2009  14:21            31,744 dmss.exe
14/07/2009  16:42               953 jconsole.bat
14/07/2009  16:42             1,071 jconsole.sh
14/07/2009  16:42             2,468 jmxPermissions.vbs
14/07/2009  16:42               291 setupClasspath.bat
14/07/2009  16:42               658 setupClasspath.sh
14/07/2009  16:42             1,017 shutdown.bat
14/07/2009  16:42             1,243 shutdown.sh
14/07/2009  16:42             3,561 startup.bat
14/07/2009  16:42             3,459 startup.sh
              15 File(s)         50,298 bytes
               2 Dir(s)   1,316,659,200 bytes free
</pre>
<p>Because the service wrapper (now renamed to <code>dmss.exe</code>) executes the same executable to start or stop the service, we must create an executable that can decide whether to start or stop the dm Server based on command line argument. Let’s call this executable <code>dmscontrol.bat</code>; if we pass the <code>run</code> command line argument, we want it to call the <code>startup.bat</code>. Similarly, if we pass the <code>stop</code> command line argument, we want it to call the <code>shutdown.bat</code>. We show the entire source code of <code>dmscontrol.bat</code> below:</p>
<pre>
@ECHO OFF

IF "%~1"=="run" CALL %SERVER_HOME%\bin\startup.bat
IF "%~1"=="stop" CALL %SERVER_HOME%\bin\shutdown.bat
</pre>
<p>The final piece of the puzzle is the service configuration file. The service wrapper will look for a configuration file whose file name matches the executable of the service wrapper, but with xml extension. In our case, <code>dmss.exe</code> will look for <code>dmss.xml</code>. Take a look at Listing 2, which shows the <code>dmss.xml</code> service configuration file.</p>
<p>Listing 2. The service wrapper configuration file</p>
<pre>
01 &lt;service&gt;
02  &lt;id&gt;dmserver2&lt;/id&gt;
03  &lt;name&gt;dm Server 2.0&lt;/name&gt;
04  &lt;description&gt;
05    Controls the SpringSource dm Server 2.0
06  &lt;/description&gt;
07  &lt;env name="JAVA_HOME"
08    value="c:\Program Files\Java\jdk1.6.0_14" /&gt;
09  &lt;executable&gt;%SERVER_HOME%\bin\dmscontrol.bat&lt;/executable&gt;
10  &lt;startargument&gt;run&lt;/startargument&gt;
11  &lt;stopargument&gt;stop&lt;/stopargument&gt;
12 &lt;/service&gt;

02 The service identifier, it must start with a letter and must not contain spaces
03 The service name, this is the name that the Services listing will show
05 The description of the service that the Services listing will show
08 We need to set the JAVA_HOME environment variable for the service
09 The path to the service executable
10 The command line argument that the service wrapper will pass to the service executable to start the service
11 The command line argument that the service wrapper will pass to the service executable to stop the service
</pre>
<p>Before we can install the service, we must check that the permissions on the dm Server’s directory allow access from the service’s account. By default, the service will run under the SYSTEM account, therefore, we must give the SYSTEM account full control of the <code>%SERVER_HOME%</code> directory. Once this is done, we must execute the following commands:</p>
<pre>
cd %SYSTEM_HOME%\bin
dmss install
</pre>
<p>This will install the dm Server service, the proof is in the pudding – the Services listing in Figure 1.</p>
<p><a href="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2009/07/services-listing.png"><img src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2009/07/services-listing-300x180.png" alt="services-listing" title="services-listing" width="300" height="180" class="alignnone size-medium wp-image-394" /></a></p>
<p>Figure 1. The dm Server service appearing in the Services listing</p>
<p>Notice in the Services listing that the name matches the contents of the &lt;name&gt; element in the dmss.xml file and description matches the contents of the &lt;description&gt; element in the configuration file. We can now start the service; when the service starts, its shell process will become child of the services.exe process (see Figure 2).</p>
<p><a href="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2009/07/process-tree.png"><img src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2009/07/process-tree-300x245.png" alt="process-tree" title="process-tree" width="300" height="245" class="alignnone size-medium wp-image-397" /></a></p>
<p>Figure 2. Process tree showing the dm Server’s dmss.exe wrapper</p>
<p>You can verify that the service starts dm Server successfully by going to http://localhost:8080, you should see the splash screen you saw when you started the dm Server by running <code>%SERVER_HOME%\bin\startup.bat</code>.</p>
<h3>Note on security</h3>
<p>Regardless of whether you are running dm Server on UNIX or Windows, you should create a separate user account to run it. Having a separate account to run the dm Server will help limit the damage a potential successful attacker may cause.<br />
Now that we have explored the different ways to start and run dm Server, let’s find out how we can control it once it’s running. We will begin by looking at the simple web administrative console, followed by the more complex OSGi console.</p>
<h2>And there you have it!</h2>
<p>Whether you&#8217;re running UNIX or Windows, you can now configure dm Server to survive a logoff!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2009/07/24/running-dm-server-as-a-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

