Dashboard > Community Wiki > ... > Deployment > Run Magnolia as a windows service
Run Magnolia as a windows service Log In View a printable version of the current page.

Added by GrĂ©gory Joseph , last edited by Olivier Marti on Aug 20, 2008  (view change)
Labels: 

The more I work with Magnolia the more I like it . This morning I was trying to run Magnolia as a Windows service. Well, I achieved it but through a dirty and, in my opinion, very ineficcient way. This article has been applied & tested sucessfully on a Windows 2000 Server box with Magnolia 1.1 and J2SDK 1.4.2_04:

  • First of all set your JAVA_HOME variable on the 'Environment variables' Windows dialog.
  • Magnolia is based on the 'two-stages' concept (the 'author' and 'public' stages, that's running two instances of Tomcat, one for each 'stage'). Each 'stage' has associated with it two .bat files that start and stop the 'stage', the files are startup.bat and shutdown.bat (located both at /bin folder).
  • Windows cannot create a Service of a non-binary file, for example, we cannot create a Service based on a .bat file, but we can do it with a .exe file so ... we have two .bat files and we want to create a Service of them. The solution that I have found is to use cmd.exe (Windows NT Command Processor) passing it a parameter that will invoke one of the .bat files (one Service will be the startup.bat file and another one will be shutdown.bat).

REMEMBER to change the paths with yours!!!. The parameter is: /c D: && cd magnolia && cd author && cd bin && startup

  1. /c is a parameter of cmd.exe that will remain the window open once the command is performed.
  2. D: will change the path to this HD.
  3. && cd magnolia will change the path to this folder.
  4. And so on... finally we invoke our startup.bat file.

The whole command that we have is - cmd.exe /c D: && cd magnolia && cd author && cd bin && startup

Well, we have now the way to start one 'stage' of Magnolia (in this case, the 'author' instance) through the Windows command-line (Start/Run). Now we need to create a Service with this line (remember that now WE can create a Windows service because we are using an .exe file (cmd) and not a .bat file

Windows has an utility called 'sc' that allows you to create a Service; I've been using it for a time but the Service that creates doesn't run so I searched on Google and I found a small freeware program (called "RunAsService", and located at Ica-dos). Download and run the program, "Create a new Service", locate cmd.exe (depending on your Windows version it's on windows/system32/ or winnt/system32 folders):

  1. Check "Run Service using Local System Account"
  2. Check "Service interacts with Desktop"
  3. Parameters: /c D: && cd magnolia && cd author && cd bin && startup
  4. Click on "Create Service" button.

Now we have Magnolia running as a Service

Go to Windows Services (Start/Run/services.msc), locate your Service, right click, properties, go to "Log On" tab and check "Allow service to interact with desktop" (this option will remain open our Magnolia window on the shell). Change if you want that your service starts when Windows start
('Automatic'), or when you start it manually ('Manual').

Now we have a service based on the startup.bat file of the 'author' stage, we need another one for the shutdown.bat (repeat the steps but one with the shutdown.bat file). Once you have the two Services you'll need to make another two Services with the .bat files of the 'public' stage and here comes why I think that this way is dirty and inefficient: imagine that you have two instances of magnolia running on your computer ... then you'll have 8 services :/

- First Magnolia instance -

One Service for startup.bat ('author' stage)
One Service for shutdown.bat ('author' stage)
One Service for startup.bat ('public' stage)
One Service for shutdown.bat ('public' stage)

- Second Magnolia instance -

One Service for startup.bat ('author' stage)
And so on ...

I'm sure that there's another way to create all of this with less steps and on a more 'professional' way but, hey, this was only an experiment and it worked!

The funny thing: if you run one of your 'Startup' Services and then you'll stop it with the 'Shutdown' Service, all seems to work, but the 'Startup' Service isn't completely closed, so in order to shutdown the 'Startup' Service you'll need to:

  1. Run 'Shutdown' Service
  2. Stop 'Startup' Service
  3. Stop 'Shutdown' Service

Alternatively you can try http://www.rz.uni-freiburg.de/pc/sys/srvany/index.php

In its previous incarnation on JspWiki, this page was last edited on Feb 9, 2007 10:59:41 AM

If you run Magnolia within JBoss as the application server you may also want to give JBoss Native a try to set up JBoss as a service for windows (pretty simple).
You can also run multiple JBoss instances with this by changing the corresponding ports and adapting the service.bat for using different service names or bindings to different IP adresses.

Powered by a free Atlassian Confluence Open Source Project License granted to Magnolia International. Evaluate Confluence today.
Powered by Atlassian Confluence 2.7, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators