Run CommandBox as a Windows Service with AlwaysUp

How to Run CommandBox as a Windows Service with AlwaysUp

Automatically start your CommandBox server in the background whenever your computer boots. Keep it running 24/7 in the background — without anyone having to log on first.

CommandBox is a versatile, developer-centric command line tool written in ColdFusion. Most folks use it interactively but CommandBox can also run an embedded HTTP web server. For that scenario, some find it beneficial to launch CommandBox automatically in the background as a daemon/service.

To install CommandBox as a Windows Service with AlwaysUp:

  1. If necessary, download and install CommandBox.

    Set up your CommandBox server. Ensure that it starts and runs as expected.

    For this tutorial, we placed CommandBox in "C:\CommandBox" and configured our server to run on HTTP port 8084. It started fine from the CLI:

    CommandBox server started

  2. To prepare CommandBox for running in the background (in the isolated Session 0), please instruct Java to run in headless mode. You can do that by adding -Djava.awt.headless=true to the jvm.args key in your JSON configuration file:

    Edit server.json to run Java headless

    Note that if you don't run Java headless, starting your server as a Windows Service may fail with the cryptic message:

    "Server's output stream closed. It's been stopped elsewhere"

  3. Next, download and install AlwaysUp, if necessary.

  4. Start AlwaysUp.

  5. Select Application > Add to open the Add Application window:

    Add Application

  6. On the General tab:

    • In the Application field, enter the full path to the CommandBox executable, box.exe.

    • In the Arguments field, enter the server start parameters to launch the embedded server in the background.

      We recommend:

      server start serverConfigFile=<PATH-TO-CONFIG-FILE> --console

      where <PATH-TO-CONFIG-FILE> is the full, quoted path to your JSON configuration file (usually server.json).

      The --console flag instructs CommandBox to start the server in the foreground console process and wait until Ctrl-C is pressed to stop it. That makes it easier for AlwaysUp to monitor the server and keep it running 24x7.

    • In the Start the application field, choose Automatically, but shortly after the computer boots. With this setting, CommandBox will start a couple of minutes after boot — once all the machine's critical services are completely up and running.

    • And in the Name field, enter the name that you will call the application in AlwaysUp. We suggest CommandBox but you can specify a more descriptive name if you like.

    CommandBox Windows Service: General Tab

  7. Move to the Logon tab and enter the user name and password of the account where you installed and run CommandBox. You should avoid using the default system account as Java was never installed there.

    CommandBox Windows Service: Logon Tab

  8. When installed as a Windows Service, CommandBox will run invisibly in the background (on the isolated Session 0 desktop). Therefore, you won't see CommandBox's console window nor have access to text logged to the console.

    If lack of access to the console is a problem, you should capture CommandBox's console output to a text file. To do so:

    • Switch to the Extras tab.

    • In the Capture output to this log file field, enter the full path to the text file that should record the console output.

    • You should also specify what should happen to the output file if it grows very large.

    CommandBox Windows Service: Extras Tab

  9. We're done configuring CommandBox as a Windows Service so click the Save button to record your settings.

    In a couple of seconds, an application called CommandBox (or whatever you called it) will show up in the AlwaysUp window. It is not yet running though and the state will be "Stopped":

    CommandBox Windows Service: Installed

  10. If your CommandBox server is already running, please stop it now. We don't want an existing instance to tie up the HTTP port and cause our copy launched as a Windows Service to fail.

  11. To start CommandBox from AlwaysUp, choose Application > Start "CommandBox".

    In a few seconds, the status will change to "Running" and CommandBox will be working in the background:

    CommandBox Windows Service: Running

  12. Now, please check to make sure that CommandBox is working as expected. You can do that by:

    • Opening your browser to the server's HTTP port, and

    • Reviewing the console output captured to the text file in step 7.

    Everything should be fine, as it was on our machine:

    CommandBox Windows Service: Verified

  13. That's it! Next time your computer boots, your CommandBox server will start up immediately, in the background, without anyone needing to log on. Please restart your PC now and test that everything works as expected after Windows returns to life.

    And please feel free to edit CommandBox in AlwaysUp and explore the many other settings that may be appropriate for your environment. For example, send an email if CommandBox stops, setup a "sanity check" to monitor the HTTP port, and much more.



CommandBox not working properly as a Windows Service?

  • Consult the AlwaysUp Troubleshooter — our online tool that can help you resolve the most common problems encountered when running an application as a windows service.

  • From AlwaysUp, select Application > Report Activity > Today to bring up an HTML report detailing the interaction between AlwaysUp and CommandBox. The AlwaysUp Event Log Messages page explains the messages that may appear.

  • Browse the AlwaysUp FAQ for answers to commonly asked questions and troubleshooting tips.

  • Contact us and we'll be happy to help!

Download & Try it Free!

Download AlwaysUp and Run as a Service Today! Version 15.1 New!

7.9 MB Installer
Our 12,000+ customers include...
Compatible with Windows 11 Compatible with Windows Server 2022 Compatible with Windows 10
Over 94,000 installations, and counting!
 
AlwaysUp is number 1! Run as a Service with AlwaysUp

Rock-solid for the past 19+ years!