The Core Technologies Blog

Professional Software for Windows Services / 24×7 Operation


Q&A: Why won’t AlwaysUp Start my Java Application?

Why won't AlwaysUp Start my Java Server Application
  I have two Java socket applications installed in AlwaysUp. Even though they are similar and both are started from batch files, AlwaysUp runs one fine but has trouble with the other.

Whenever I look in AlwaysUp, one Java entry always says “Waiting”. But if I open the browser I can connect to the server just fine. Why does AlwaysUp think that it’s not running when it is?

— Jeff

Hi Jeff.

I suspect that your Java application is being blocked by another instance of itself. And when that happens, AlwaysUp just keeps trying to restart it. Let’s dig into the details.

Why AlwaysUp can’t start your Java application and constantly says its “Waiting”

First, understand that AlwaysUp only shows the “Waiting” state when it’s waiting to restart your application. You must have configured a delay on the Restart tab, as pictured here:

AlwaysUp delay after restarting

But AlwaysUp only waits before restarting the application. So the question is, why is your application stopping?

Since you mentioned that your Java server uses TCP/IP sockets, we have a hunch that there is a conflict with a network port. The problematic sequence probably plays out like this:

  1. The AlwaysUp Windows Service starts;

  2. AlwaysUp launches your batch file;

  3. The batch file starts your Java application;

  4. Java tries to open a specific numeric port so that it can accept network requests from clients;

  5. Windows detects that the port is already in use by another application and returns an error to the Java app;

  6. Because the Java application cannot open it port, it exits;

  7. And since all the commands in the batch file have completed, the batch file exits too;

  8. AlwaysUp detects that the batch file is done;

  9. Instead of restarting the batch file immediately, AlwaysUp pauses for a while as specified on the Restart tab (see the screenshot above). The AlwaysUp GUI application shows the state as “Waiting”:

    Waiting to restart the application
  10. Once it’s done waiting, AlwaysUp launches the batch file again (step 1) and the cycle repeats itself.

Indeed, AlwaysUp’s activity report — available by choosing Report Activity > Today from the Application menu — will likely confirm the futile attempts to start your application every minute. You probably have hundreds of entries in the Windows event logs too!

Why your application works even though AlwaysUp failed to start it

Your browser tests succeed because there is another copy of your Java application running. It’s listening to the port and responding to your browser’s requests.

You can confirm this situation by:

  1. Opening the Task Manager (or better yet, Microsoft’s amazing Process Explorer) and locating the java.exe process already running;

  2. Using the netstat command to find out which application already has the port open.

    For example, this command identifies the process listening on port 8008:

    netstat -ano -p tcp | find ":8008"

    As you can see below, the culprit was the process with ID 3484 on our Windows 11 PC:

    NETSTAT for port 8008

But why doesn’t AlwaysUp “discover” the existing Java server and manage it?

First, realize that the current instance of your Java application was not started by AlwaysUp. That is, it’s running independently of AlwaysUp.

Second, you’ve got to understand how AlwaysUp works.

AlwaysUp is designed to start an application and ensure that it’s always running. Most importantly, AlwaysUp does not “discover” or “latch on” to an application that is already running. AlwaysUp can only manage and babysit applications that it starts itself.

The fact that a process on your machine is responding to your browser means nothing to AlwaysUp because that process was not started by AlwaysUp.

How to fix the problem

The solution is straightforward.

Simply terminate the current instance of the Java application running on your machine. Doing so will free up the port and allow a new instance started by AlwaysUp to secure the port and start properly.

How to ensure that AlwaysUp always starts your Java app

As you have seen, AlwaysUp will fail to start your Java app if there is another copy already running. The solution is to stop the existing server before AlwaysUp launches its own instance.

But what if this happens again and you’re not around to kill the non-AlwaysUp process? That may leave your system in a vulnerable state, with your Java application unprotected from crashes and other interruptions.

Fortunately, there’s a two-step fix. You can:

  1. Write a batch file that terminates any process already listening on the port

  2. Have AlwaysUp run that batch file right before it starts your application

That way, your Java application always starts properly because there won’t be anything holding on to the port.

Download our batch file that terminates the application listening on a given port

Good news!

We’ve gone ahead and created a batch file that stops the process listening on a given port.

Batch file to end a process by port

Download the batch file and save to a folder on your computer.

Plug the “terminate process by port” batch file into AlwaysUp

To make AlwaysUp run the “terminate process by port” batch file before it fires up your “main” batch file:

  1. Double-click your batch file entry in AlwaysUp to open its properties;

  2. In the Edit/View Application window, switch to the Startup tab;

  3. Check the Run the following program/batch file box;

  4. Enter the full path to the “terminate process by port” batch file you downloaded. Be sure to surround the value with quotes if it contains a space;

  5. After the path, enter the Java application’s listening port number. We’ve entered 8008 for our application;

  6. Check the Also whenever the application is restarted box as well:

    Plug in the terminate-port-process batch file
  7. Finally, save your changes.

With the “terminate process by port” batch file involved, here is the new sequence when you start your Java entry in AlwaysUp:

  1. The AlwaysUp Windows Service starts;

  2. AlwaysUp launches the “terminate process by port” batch file;

  3. The batch file checks for an application listening on the designated port. If an instance of your Java app is already running on the port, the batch file terminates it;

  4. AlwaysUp launches your “main” batch file;

  5. The batch file starts your Java application;

  6. Since the port is available, your Java application secures the port and starts properly;

  7. AlwaysUp monitors the “main” batch file and restarts it if it stops for any reason.

You will be good to go!

Posted in AlwaysUp | Tagged , , , , , , | Leave a comment

Our Software is TAA Compliant

Our Software is TAA Compliant

What is the TAA?

TAA refers to the Trade Agreements Act (19 U.S.C. & 2501-2582), which was enacted by the U.S. government in 1979 to foster fair and open international trade.

The TAA requires that the U.S. Government acquire “U.S. made” products — ones that are produced or undergo a “substantial transformation” within the United States or a designated country.

TAA compliance make it possible for U.S. government agencies and educational institutions to do business with USA-based companies like Core Technologies Consulting. Federal procurement contracts that require TAA compliance include GSA (General Services Administration) Schedule contracts, IDIQ (Indefinite Delivery, Indefinite Quantity) contracts, and most DoD (Department of Defense) contracts.

AlwaysUp, Service Protector and all our software comply with the TAA

Core Technologies Consulting’s software solutions are designed, implemented and supported entirely in the United States. As such, our software meets and exceeds the TAA standards outlined above.

Please contact us if you have questions about TAA compliance

If you need more information about TAA compliance, please get in touch. We’ll be happy to provide an official, signed statement suitable for government agencies.

Posted in Company | Tagged , , , , , | Leave a comment


Q&A: How can a Non-Admin User Start my AlwaysUp Service?

How can a Non-Admin User Start my AlwaysUp Service?
  Hi — long time user of AlwaysUp here!

I followed your suggestion in the FAQ to allow my non-admin user to control the Windows Service that AlwaysUp created. Now he can run the NET command to start and stop our application in Session 0 whenever he likes, which is great. But we’re still having one problem.

Sometimes the user needs to start the application in the current session to make changes. The user manual says that running AlwaysUp.exe with the “-restart-in-current-session” parameter will do the trick.

And that command works fine for me (I’m an admin). However, the non-admin user is prompted for admin credentials because his account doesn’t have the rights to run AlwaysUp.

Is there any way to start AlwaysUp.exe without needing admin credentials?

— Steve

Hi Steve. Thanks for getting in touch — and for being a loyal customer!

Permissions is always a thorny topic but we can help you. Let’s start by reviewing why there is no direct remedy from the AlwaysUp executable (AlwaysUp.exe).

AlwaysUp needs admin rights to do its work

Unfortunately it’s not possible to launch AlwaysUp without elevated rights. That’s because AlwaysUp needs to:

  1. Read, create and update your Windows Services

  2. Interrogate the Windows Event logs for errors and warnings

  3. Carefully monitor your important applications and react quickly when they use too much memory, hog the CPU, hang or crash.

Typically only administrators — with broad access to low-level systems — can perform those actions.

So your non-admin user won’t be able to run AlwaysUp.exe. But as you know, there are other ways to start or stop the Windows Service created by AlwaysUp. Let’s explore the NET command since you’re already familiar with how it works.

Use NET to start your application in a given session

To recap, you’re already using the NET command to start your application. If your application is called “MyServer” in AlwaysUp, then this command will do the trick:

NET START "MyServer (managed by AlwaysUpService)"

Notice that you must add the "(managed by AlwaysUpService)" suffix as that is how the service is named in the Service Control Manager.

In any case, running that command instructs AlwaysUp to start your application in Session 0 — the background desktop hosting Windows Services. You won’t see the application on your normal desktop.

Fortunately slight variants of the NET command will enable you to launch your application in a specific session.

Provide a Session ID

To start in a specific session, add the session’s numeric identifier (the Session ID) to the command. The format is:

NET START "<ApplicationName> (managed by AlwaysUpService)" /<SessionID>

For example, to start “MyServer” in Session 2, run:

NET START "MyServer (managed by AlwaysUpService)" /2

That will launch your application in Session 2, regardless of who is logged in there.

Provide a Windows username

Alternately, you can pass a username to start the application in the session occupied by that Windows user. The format of that command is:

NET START "<ApplicationName> (managed by AlwaysUpService)" /"user:<UserName>"

For example, to start “MyServer” in the session where “psmith” is logged in, run:

NET START "MyServer (managed by AlwaysUpService)" /"user:psmith"

Note that if the given user is not logged in, AlwaysUp will start the application in Session 0.

How to use NET to start your application in the current session

To achieve what you’re trying to do, we recommend going with the username variant of the NET command.

This command — which features the USERNAME environment variable — will start your application on the current user’s desktop:

NET START "<ApplicationName> (managed by AlwaysUpService)" /"user:%USERNAME%"

Again, if your application is called “MyServer”, the precise syntax is:

NET START "MyServer (managed by AlwaysUpService)" /"user:%USERNAME%"

When you run the command, %USERNAME% expands to the username of the account invoking the command. In that way, the command works for whoever runs it.

We recommend saving the command to a batch file and placing the file on the user’s desktop, for easy access. With that, your application will only be a double-click away.

Enjoy!

Posted in AlwaysUp | Tagged , , , | Leave a comment

Q&A: How do I Launch a Service after AlwaysUp Starts my Application?

How do I Launch a Service after AlwaysUp Starts Google Drive
   I’m interested in purchasing your AlwaysUp application but would like some further information first if you don’t mind.

My main goal is to run Google Drive for desktop as a service. But there is an existing Windows Service that I need to run after Google Drive has launched. Is it possible to use AlwaysUp to start it after Google Drive has started?

— Shaheed

Hi Shaheed, thanks for trying AlwaysUp.

The answer to your question is yes. Please follow these steps to setup Google Drive and your other service in AlwaysUp.

1. Install Google Drive as a service with AlwaysUp

As described in our step-by-step tutorial, the new AlwaysUp Application Advisor supports Google Drive for desktop:

Application Advisor supports Google Drive for desktop

Instead of leaving you to figure out and apply the best settings to support background file synchronization, simply click through the Advisor’s straightforward prompts to create your Google Drive service — in less than 2 minutes.

At the end of the process, your Google Drive for desktop will be installed as a 24/7 Windows Service. Afterwards, test and make sure that the new service syncs your files as expected.

2. Have AlwaysUp start the other service after it runs Google Drive

Now that Google Drive is set up, let’s turn our attention to starting the other service at the right time.

Please:

  1. Edit your Google Drive for desktop entry in AlwaysUp.

  2. Move to the Automate tab.

  3. Check the When the application starts… box at the top.

  4. Enter the following command (which will start your service):

    C:\Windows\System32\net.exe START "<Service-Name>"

    where <Service-Name> is the name of your service. Note that the quotes around the name are required if it contains a space.

  5. In the Every section, specify when the service should be started.

  6. Check the Only option and set the value to 1 (because we only need to start the service once).

  7. Finally, save your settings.

For example, if you want to start the Print Spooler service (named “Spooler”) 30 seconds after Google Drive starts, your Automate tab should look like this:

Use AlwaysUp to automate NET START

3. Change your service to start manually

Is Windows starting your service when the computer boots? If so, you may want to change that because with step 2 in place, AlwaysUp will start the service when it’s needed.

To prevent Windows from starting your service at boot:

  1. Start the Services application (run “services.msc” to launch it)

  2. Scroll the list to find your service.

  3. Double-click the entry to bring up the service’s properties.

  4. In the Startup type field, select Manual. It should look like this:

    Set the service's startup type to Manual
  5. Save your changes.

And that’s it!

Next time your computer boots:

  1. Windows will automatically start AlwaysUp

  2. AlwaysUp will start Google Drive

  3. And after a few seconds/minutes (whichever you specified), AlwaysUp will start your service.

All the best.

Posted in AlwaysUp | Tagged , , , , | Leave a comment