-
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:
-
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:
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"
-
Next, download and install AlwaysUp, if necessary.
-
Start AlwaysUp.
-
Select Application > Add to open the Add Application window:
-
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.
-
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.
-
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.
-
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":
-
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.
-
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:
-
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:
-
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.