Restarting service (declared in init.rc) from a system app in a Java context - service

I have a service declared in my init.rc on my platform that runs always, and an Android system app (signed with the platform keys) that is persistent (i.e. always runs), which communicate through TCP/IP.
At some point I would like to restarte the service from the app, the app runs under a defined system uid, however it does not have permission to call start or stop on the console, unfortunately.
I would like the app to restart the service, just like if I had executed the following in the console:
stop service
start service
Is there an android framework call I can make to restart a specific service?

Related

How to unregister a service worker when the PWA has been trashed

This might sound like a dumb question, but here's the problem. I am developing a PWA for a client and everything works fine : the service worker gets installed, as well as the app on the desktop.
I know how to uninstall both the app and the service worker programmatically.
But, for instance on an old Samsung tablet running Android 4.4, the app icon can be dragged to the trash on the desktop (like any shortcut) and then the app is uninstalled, but the service worker is still active and running (I can see it in DevTools).
Question : how to get rid of service workers after a PWA has been trashed that way ?
My concern is that end users of the app might delete it that way, and still have a service worker active on their mobile...
Thanks in advance.
The process for a service worker will automatically stop running after a short period of idleness–somewhere between under a minute to maybe 5 minutes, depending on the browser and operating system.
If you have Chrome's DevTools open, then that will artificially keep the service worker process alive indefinitely, to aid in debugging. (It would be frustrating if you were trying to debug something related to the state of the service worker, and the service worker process stopped right in the middle.)
This only applies when you've got DevTools open, though, so you should have faith that it will stop on its own if you're not "looking" at it.

install4j windows service -- restart on failure option

I have a working install4j 6.1.3 service. Due to a 3rd party memory leak we want to be able to have our application exit and then have the service automatically restart itself on a regular basis. There is a checkbox on the install4j create services option screen "Restart on Failure" that says that it should restart the service unless the exit code is '0'.
The java application is calling System.exit(27).
We have also tried codes -1, 0 and 1.
The application exits, but the windows service does not auto restart.
Is there something more that needs to be configured for this to work, or a different way to exit the java application to get the service to automatically restart itself?

Service Fabric Guest Executable hosting and graceful stop

I have a .NET 4.6.2 console application I want to host in Service Fabric.
My application is listening on console input events for administration tasks.
The most important one is 'q' to stop the application - but in a graceful manner.
Is it somehow possible to also have this functionality in Service Fabric with a guest executable?
Of course not on 'q button pressed' but rather on service deleted or whatever events there are.
If there is no way to achieve this kind of integration with a guest executable - which project template do you recommend to build upon?
Service Fabric sends a Ctrl-C signal to the guest executable process before killing it, allowing for graceful shutdown. You can use the Console.CancelKeyPress event or the Win32 SetConsoleCtrlHandler function to get a notification. Note the exe must be compiled as a console app for this to work.
In your stateful or stateless service class:
class MyService : StatefulService /* or StatelessService */
{
protected override Task OnCloseAsync(CancellationToken cancellationToken)
{
// your graceful shutdown code goes here
}
}
But execution of that method is not guaranteed, for instance when the hosting VM unexpectedly dies.
One way to do this, would be to programmatically delete the service when you're done with it, using DeleteServiceAsync
You can recreate it too, using CreateServiceAsync

WindowsIdentity throwing a "There are currently no logon servers available to service the logon request"

The code below works fine when running from a Console C# application:
System.Security.Principal.WindowsIdentity wi = new System.Security.Principal.WindowsIdentity("User001");
but when I try to add it into a class inside my web application I get:
{There are currently no logon servers available to service the logon request}
at System.Security.Principal.WindowsIdentity.KerbS4ULogon(String upn)
at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName, String type)
at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName)
...
I am assuming this is related to Kerberos and since Web Applications run under an Application Pool I wonder if I need to register a SPN or do something extra here to get this to work(for the local Account).
The console app runs under my DOMAIN\USER001 and
the Web app (App Pool) runs under MY_LOCAL_MACHINE\USER001
so I am trying to verify if I need to run SetSPN.exe or not and what is the command line.
Thank you
I had the same issue in my 2008R2 VM running SP2010 with a backend WCF service. In the service I was calling
WindowsIdentity id = new WindowsIdentity("MyApplicationUser");
You need to make sure your NetLogon service is running. If you are running a VM, you will need to configure the DNS role in order for this service to start. Once I did this, my code worked.

Stopping the service and the babysited application before uninstalling

I have a service MyService.exe that is babysitting my application MyApp.exe, meaning it starts the application when this one crashes or whatever. Basically when the service is stopped the application is stopped (by the service) and when the service is started the application is started by the service.
In order to stop my service and by that my application when uninstalling I'm doing:
<ServiceControl Id='MyServiceControl' Name='MyServiceForTest' Start='install' Stop='uninstall' Remove='uninstall'/>
But when I want to uninstall everything I get the error message: "The setup must update files or services that cannot be updated while the system is running. If you choose to continue, a reboot will be required to complete the setup.". If I manually stop the service before running the uninstaller I don't get this msg as both my service and my application aren't then running anymore.
In the log file I noticed that this happens in InstallValidate and I get this message b/c of MyApp.exe being running.
I think what happens is: the uninstallers checks the running applications, it notices that the MyService.exe and MyApp.exe are both running, detects probably that the MyService.exe will be stopped by the uninstaller itself as instructed, but doesn't know about the MyApp.exe that this one will also be terminated once the service will be stopped so it will show the reboot-message.
I can't just close MyApp.exe from uninstaller b/c the service will restart it again.
How could I solve this problem so that the user won't need to reboot or to manually stop the service before doing an uninstall/upgrade? Also, I can't change MyService and MyApp code anymore so I will have to do this from the (un)installer only.
TIA,
Viv
I would expose a mechanism in your service in which your installer can instruct it to stand down and terminate the application. This way when Windows Installer costing looks for locked files it doesn't find any.