Play 2.0 - starting as Windows service after server restart - windows-services

I have the Play! application running as a windows service. It is implemented according to this guidance.
The problem is that the RUNNING_PID at the root folder of the application is not removed when the server is restarted and the application cannot start again. I have to remove this file and start the service again manually.
Is there any option to solve it?

YAJSW
In case of YAJSW I found this answer with better understanding. It's of course pretty similar to link you gave, anyway keep in mind that it's more often advised to use dist command instead of stage as it has got better developers attention (more bugs fixed in dist). And Mikhail's answer is just clearer (vote him up!)
RUNNING_PID
In case of RUNNING_PID, there was some pull requests which suggested to add an option of disabling pidfile... anyway as I can see, none of them was accepted still...
Actually if you can't avoid creating it, you can... remove it right after application's start, preferably with Globals object's onStart() method. To stay informed what is current PID of the working instance, just rename the file to something, which won't be checked by Play at the startup - for an example RUNNING_PID_INFO. In such case after server's restart service will run your application without problems.
import play.GlobalSettings;
import java.io.File;
public class Global extends GlobalSettings {
#Override
public void onStart(Application application) {
File pidFile = new File("RUNNING_PID");
pidFile.renameTo(new File("RUNNING_PID_INFO"));
}
#Override
public void onStop(Application application) {
File pidFile = new File("RUNNING_PID_INFO");
pidFile.delete();
}
}
(note: changing pidfile.path in apllication.conf will NOT solve the problem, as play will use that for checking if instance is working).

Since Play Framework 2.1 you can disable the PID file by setting the pidfile.path property:
Windows:
-Dpidfile.path=NUL
Unix:
-Dpidfile.path=/dev/null
Found at https://groups.google.com/forum/#!topic/play-framework/4amD9o37Ki4

I recently installed a play framework app using YAJSW by following this answer. I noticed that now, RUNNING_PID is automatically deleted and you don't have to worry about modifying your code to delete the file. Also, if your service depends on other services, it is better to set DELAYED_AUTO_START as the start mode to ensure the service is properly started after server reboot.

Related

How to run DartVoid Vane application on localhost

In Vane Roadmap:
Better support for running Vane on localhost. Right now it's certainly
possible to run Vane on localhost, but it's a little bit tricky. On
DartVoid we autogenerate a dart based server using the http_server
package. And all you need to initialize a Vane class is a standard
HttpRequest object. So, this will come soon hopefully. You can find
your autogenerated server.dart file at the root of you app if you have
a DartVoid app (it's not generated if you use a different framework).
I've created Guestbook sample application and file server.dart was missing.
Is Guestbook sample DartVoid app?
Can I reach generated server.dart file via GitHub?
Is there another way to reach this file?
Please create tags for Vane and DartVoid...
File can be reached from application:
import 'dart:async';
import 'dart:io';
import 'package:vane/vane.dart';
String collectionName = "posts";
class GetAllPosts extends Vane {
Future main() {
log.info("Guestbook : GetAllPosts");
new File("server.dart").readAsString().then((String fileContent){
log.info(fileContent);
});
return end;
}
}
Content of file will appear in system console in http://manage.dartvoid.com
TL;DR
Vane doesn't need an auto-generated server.dart file anymore, which makes it super easy to use.
Long answer
As the co-founder of DartVoid and a co-author of Vane maybe I can give a small update on how we have improved Vane's routing.
We have since the OP's question moved away from auto-generating a server file and instead we use annotations to declare Routes. At startup we parse these routes to build the 'routing table'.
If you're interested in knowing the gritty details and see a couple of examples, I recommend that you head over to the project repository at:
https://github.com/DartVoid/Vane

Is Start (Dart framework) autoreload on the server side?

Is start (Dart server side framework) auto-refresh when one of our source code changed (just like PHP)?
Is bulls_eye, bloodless and express too?
or if they are not, is there any Dart server side framework that able to do that (edit code, then test on the browser, without needing to restart the dart/server program)?
Currently this is not yet possible in Dart. If you change the code you have to restart the app.
I wouldn't expect this to work anytime soon.
A main feature to make this possible is to manipulate the code at runtime. This is planned but as far as I know not yet started.
EDIT
The above mentioned feature is necessary when you want code to be updated without loosing the current state of the application but that is usually not so important on the server because it should be (mostly) stateless anyway.
In Dart there's no need to restart the server app when only the client part changes.
If you really just want to restart the entire server when the code changes you should be able to do that by yourself. Create a console app that loads the server app into an isolate (spawnUri) and watch the source directory for file changes. In the case of a file change shutdown the server-app-isolate and create a new one.

grails: where can utility code be placed, that doesn't cause a container restart?

I'm wondering where utility code can be placed, that doesn't cause a restart of container. Updating controllers doesn't cause a container restart & the updated code is available to run (great), but I wanted a more general library/utility place for my utility code.
Putting the code in /utils or in src/groovy does cause a restart on save, at least using Intellij, but I imagine this is the same regardless of where Grails is developed.
Perhaps you have some general info/insights on how Grails does this -- includes new code but doesn't need to restart the container, if that's only special to controllers?
(v. 1.3.7)
You're out of luck out of the box unless you want to use 2.0. The alternative is to turn off auto-reloading and add in something like jrebel. See this blog for details.

Click-once for services?

I have an app that runs as a service, and I'd like it to be able to check a URL to see if a new version is available, and if so to download and install it. I can manually hack something together, but would be great if I could create an MSI package to update the service, and any other components that are part of my distribution. I'd also like it to be done without any UI, so the user is unaware of the update.
Are there any good solutions for this?
This could be tricky depending on what your update might want to do.
If you intend on deleting and re-installing the service, this may require a reboot, which will certainly be visible to the user.
In order to replace the components of the service, the service has to be stopped first. If your service itself is detecting the update availability, it may have to kick off another process to stop the service, run the installer/updater and then restart the service.
Try installer.codeeffects.com. It has this feature.
You could try MEF (http://www.codeplex.com/MEF) and use
[Import("http://someUrl/someComponent")]
public ISomeComponent SomeService;
Its not actually an auto update, but the service could be always up to date. I am not sure if it works.. its just an idea :-)

Starting a windows service fails with error 1053

I have a windows service that is failing to start, giving an error "Error 1053: The service did not respond to the start or control request in a timely fashion".
Running the service in my debugger works fine, and if I double click on the the service .exe on the remote machine a console window pops up and continues to run without problem - I can even see log messages showing me that the program is processing everything the way it should be.
The service had been running fine previously, though this is my first time, personally, trying to deploy it with the most recent changes made to the program. I've evaluated those changes and cant figure out how they might cause this problem, particuarly since everything runs fine when not started as a service.
The StartRoutine() method of the service impelmentation is empty, so should be returning in a "timely fashion".
I've checked the event logs on the computer, and it doesn't give any additional information other than it didn't hear back from the service in the 30 second requisite time frame.
Since it works on my machine, and as a double-clicked executable, how would I go about figuring out why it fails as a service?
Oh, and it's .NET 2.0, so it shouldn't be affected by the 1.1 framework bug that exhibited this symptom (http://support.microsoft.com/kb/839174)
The box is a windows server 2003 R2 machine running SP2.
This is a misleading error. It's probably an unhandled exception.
Empty your OnStart() handler then try this in your constructor...
public MainService()
{
InitializeComponent();
try
{
// All your initialization code goes here.
// For instance, my exception was caused by the lack of registry permissions
;
}
catch (Exception ex)
{
EventLog.WriteEntry("Application", ex.ToString(), EventLogEntryType.Error);
}
}
Now check the EventLog on your system for your Application Error.
Could be a number of things and it might help to get a stack trace on the machine exhibiting the problem. There are a number of ways to do this but the point is that you have to see where this is failing in the code.
You can do this with remote debugging, but a simple thing might be to just log to the event logger, or file log if you have that. Literally, putting "WriteLine("At class::function()") throughout portions of the code to see if you've made it there.
This will at least get you looking in the right direction (which ultimately is the code).
Update:
See Microsoft's How to Debug Windows Services article for details in troubleshooting startup problems using WinDbg.
This related question details nice ways to debug services that are written in .NET.
I agree with Scott, the easiest way to find out what's happening is to put some traces in the start-up code (maybe it doesn't even come to your start-up code).
If this doesn't help, you can post your code here so others can take a look.
perhaps lacking some dependence, try this :
- deregister your service
- register again
If fail at register means that lack an module.
If the StartRoutine is empty, you are probably starting it somewhere else.
IIRC you need to fire off a worker thread, and then return from StartRoutine.
One of the problems which may lead to this error is if windows service which needs to be deployed consists of some error i.e it may be simple authorization error or anything as in my case I have referenced some folders and files for logging which were not existing, but when provided the right path of those file and folders it solved my problem.
I ran through every post on this particular subject and none of the responses solved the problem, so I'm adding this response in case this helps someone else. Admittedly this only applies to a new service, not this specific case.
I was writing a File listening service. As a console app, it worked perfectly. When I ran it as a service, I got the same error as above. What I didn't know (and many of the MSDN articles about services conveniently leave out) is that you need to have your class executed from within ServiceBase.Run( YourClassName());. Otherwise, your app executes and immediately terminates and because it terminated, you get the error above even if no error or exception occurred. Here is a link to an article about this. It actually discusses setting up your app for dual use - Console app and service: Create a combo command line / Windows service app
I had that issue and the source of my problem was config file. I edited it in notepad and notepad added one special character which cause service not to run properly because config file was ruined. I saw that special character in notepadd++ and after delete it, service started to run successfully as previous did.
In my case, the correct .NET framework was not installed on the server that I was installing the Windows service on.
One other reason is If you copy the DLL in 'debug' mode to installation folder this issue will come.What you need to do is Run the project in 'Release' mode copy the DLL or directly form Release folder rather than Debug folder,,and copy that DLL in to installation folder,it will work.You can see the reduction in size of DLL ,it will not contain any debug symbols and like that

Resources