We are currently using AlwaysUp with several executable instances. We need to have these restarted daily due to memory leaks from the application.
I don’t see a scheduling restart option in AlwaysUp. I think this could be done through a windows task but I see that these are being run as windows services. Would you recommend doing this as a windows task or would the Service Protector be a better option?
— Kevan Hauver, AAA Northeast
Hi Kevan. Sorry to hear of the awful memory leaks!
Yes, Service Protector could help your situation but there is no need to purchase that additional software. Here are a couple of options to restart your application periodically:
Restart once daily (via the Monitor tab)
AlwaysUp makes it very easy to restart your application once per day, at a time of your choosing. Edit your application in AlwaysUp and look for the Every setting on the Monitor tab.
Here is what the Monitor tab looks like when configured to restart the program every day at 2 AM (a time when the software/server is likely to be “quiet”):
Note that AlwaysUp can restart conditionally — only when one or more conditions are met. For example, to avoid restarting when the software is busy, check the It has been idle for at least box and fill in an appropriate duration.
And if you find that simply restarting the application doesn’t clear the problem, you can try rebooting the entire machine. That option is available at the bottom of the form.
Restart multiple times per day (using the Windows Task Scheduler)
If restarting once per day is not enough, you have my sympathies!
For that situation, we recommend creating a simple script that will restart your service and then enlisting the Windows Task Scheduler to restart the service as often as you like. Follow these steps, which you should be able to complete in 10 minutes or less:
Step 1: Create a batch file to restart your AlwaysUp service
First, please create a batch file that restarts your AlwaysUp service. It will contain two lines — one to stop the service and another to start it.
For example, if your AlwaysUp application is named “Dropbox”, your batch file should contain the following calls to the Windows NET command:
NET STOP "Dropbox (Managed by AlwaysUpService)" NET START "Dropbox (Managed by AlwaysUpService)"
The ” (Managed by AlwaysUpService)” portion is a necessary part of the service’s name. All services created by AlwaysUp feature that suffix.
Note: The batch file may not work as expected if it takes your application longer than 30 seconds to shut down. This is because NET STOP will only wait for 30 seconds before giving up. And if it does give up, the subsequent call to NET START will fail too. So after running the batch file, the AlwaysUp service may end up in the “Stopped” state — not what you want for your 24/7 application!
For slow applications, we recommend using our free ServicePilot utility instead of NET. ServicePilot can be configured to wait much longer than 30 seconds for the service to stop.
Assuming that you have downloaded and saved ServicePilot to your AlwaysUp folder, here is what the batch file looks like with ServicePilot instead:
"C:\Program Files (x86)\AlwaysUp\ServicePilot.exe" -restart -wait 300 "Dropbox (Managed by AlwaysUpService)"
That command will wait for up to 300 seconds (5 minutes) for the service to restart.
Give the batch file a meaningful name and save it to your AlwaysUp folder (C:\Program Files (x86)\AlwaysUp). We’ll need its full path in the next step.
Step 2: Setup the Task Scheduler to run the batch file
Here’s how to run the batch file (and restart your application) every day at noon.
Start Task Scheduler. This is best done by running taskschd.msc from a command prompt, or by opening the Control Panel, searching for “schedule” and clicking the Schedule tasks link:
Once the Task Scheduler window appears, select Create Basic Task on the left:
In the Create Basic Task Wizard window, enter a suitable name. You can leave the description blank.
Click Next to proceed.
The Daily option (which we want) should already be selected, so click Next to move to the next screen:
Here you specify the time to restart the service/application. We have selected today at noon but you should select whatever time works for you.
Leave Recur every at 1 day and click Next when you are ready to proceed.
We want to start a program (the default), so click Next to move on:
Click the Browse button and choose the batch file you created in the previous step. Recall that we placed ours in the AlwaysUp folder (C:\Program Files (x86)\AlwaysUp):
Click Next to proceed.
The basic configuration is now complete and you will see a summary of the scheduled task to be created.
Check the Open the Properties dialog… box and click the Finish button:
And on this final screen, select the Run whether user is logged in or not option and check the Run with highest privileges box. These are required by Windows to manipulate the service on your behalf.
Click OK to wrap up. (On some versions of Windows, you will have to enter the password for your account on the way out.)
Your task is now fully configured. Navigate into the Task Scheduler Library on the left and confirm that all is well:
With this new task in place, Windows will automatically restart the AlwaysUp service every day at noon.
Step 3: Repeat the process to configure additional restarts
Want to restart again at 2 PM? Simply repeat the process to create another task but select 2 PM instead of noon.
Advanced users can save a few clicks by exporting the task to a XML file, updating the file to specify a different time, and importing the modified XML to create a new task.
Hopefully you don’t have to create too many tasks…
Best of luck with your application!