How do I install Tomcat service as Automatic (Delayed Start)? - windows-services

I created an installer with install4j that calls the provided Tomcat service.bat file to create a Windows service.
That works fine, but is there anyway to modify the service.bat so by default the installed service is Automatic (Delayed Start) as opposed to Automatic or Manual?
According to this page:
http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html
The --Startup parameter takes either auto or manual with a default of manual if left empty. I'm a little confused because I left it out and my services are set to Automatic after installation, which contradicts that page.

Doesn't seem like a parameter for Automatic (Delayed Start) is supported so I ended up simply calling a .bat file after the service is installed. It sets the appropriate key/value in the Windows registry to mark a service as delayed-start.
reg add "HKLM\SYSTEM\CurrentControlSet\services\%1" /v DelayedAutostart /t REG_DWORD /d 0x1 /f"
Just run the batch file, passing an argument for the service name.
automaticDelayedStart.bat MyService

You can also write a batch script as below:
rem :To create service with name TestTomcat
call service.bat install TestTomcat
rem :To set tomcat service as a startup service and also set heap size.
call tomcat7 //US//TestTomcat --Startup=auto ++JvmOptions=-Xmx2048m
rem :To start service
call sc start TestTomcat
And from installer you can run this batch file using "Run executable or file" action.
Thanks
-Satish Lakhani

Related

Automatically Configure Config inside Docker Container

While setting up and configure some docker containers I asked myself how I could automatically edit some config files inside the container after the containerized service finished installing (since the config files are created at the installation).
I have tried that using a shell file and adding it as the entrypoint in the Dockerfile. However, as I have said the config file does not exist right at the beginning and hence the sed commands in the script fail.
Linking an config files with - ./myConfig.conf:/xy/myConfig.conf is also not an option because the config contains some installation dependent options.
The most reasonable solution I have found was running a script, which edits the config, manually after the installation has finished with docker exec -i mycontainer sh < editconfig.sh
EDIT
My question is formulated in general terms. However, the question arose while working with Nextcloud in a docker-compose setup similar to the official example. That container contains a config.php file which is the general config file of Nextcloud and is generated during the installation. Certain properties of that files have to be changed (there are only a very limited number of environmental variables to specify). Since I am conducting some tests with this container I have to repeatedly reinstall it and thus reedit the config file.
Maybe you can try another approach and have your config file/application pick its settings from the environmental variables. That would be consistent with the 12factor app methodology see here
How I understand your case you need to start your container from creating config by some template.
I see a number of options to do it:
Use some script that generates a config from template and arguments from a command line or environment variables. (Jinja2 and python for example or Mustache and node.js ). In this case, your entrypoint generate the template and after this start application. For change config, you will be forced restart service (container).
Run some service can save the configuration and render you configuration in run time. Personally, I like consul template, we active use this engine in our environment, and have no problems for while. In this case, config is more dynamic and able to be changed "on the fly". In your container, you will have two processes, application, and consul-template daemon. Obviously, you will need to run and maintain consul. For reloading config restart of an application process is enough.
Run a custom script to create the config. :)

Jenkins shell command work flow

Under the link http://docs.buildbot.net/latest/manual/cfg-buildsteps.html#shellcommand,
in the shell command it states that
On Windows, commands are run via cmd.exe /c which works well. However, if you're running a batch file, the error level does not get propagated correctly unless you add 'call' before your batch file's name: cmd=['call', 'myfile.bat', ...].
It says that the commands are executed cmd.exe.
I assume the cmd.exe is located in the c:\windows\system32\cmd.exe, am i right or it calls from some other location like in the windows startup .
The cmd.exe is the one found in the system path variable PATH for the Jenkins process. On my machine it is in C:\windows\system32\cmd.exe.

Create memcached service in windows failed

I'm using Memcached-for-Windows, see:
http://blog.elijaa.org/index.php?post/2010/08/25/Memcached-1.4.5-for-Windows&similar
I've tried to use:
sc create "memcached" binPath="C:/memcached/mem
cached.exe" start=auto
but I can't create the Windows service, and no warning or error, just:
Creates a service entry in the registry and Service Database.
SYNTAX:
sc create [service name] [binPath= ] <option1> <option2>...
CREATE OPTIONS:
NOTE: The option name includes the equal sign.
type= <own|share|interact|kernel|filesys|rec>
(default = own)
start= <boot|system|auto|demand|disabled>
(default = demand)
error= <normal|severe|critical|ignore>
(default = normal)
binPath= <BinaryPathName>
group= <LoadOrderGroup>
tag= <yes|no>
depend= <Dependencies(separated by / (forward slash))>
obj= <AccountName|ObjectName>
(default = LocalSystem)
DisplayName= <display name>
password= <password>
To implement this, you can even execute a command line, which inturn creates a service.
First go to the path where the .exe file exists through command line.
C:\Users\sireesh.yarlagadda>memcached.exe -d install
After executing this line, you will be seeing a new service created for memcached
The reason you're getting an error is that there must be a space after the binPath= . This is a very annoying 'feature' of sc. Also you'd need a space after the start=.
sc create "memcached" binPath= "C:/memcached/memcached.exe" start= auto
The above command wouldn't give you the syntax error. However, I suspect memcached still won't run successfully as a service.
memcached isn't a native Windows Service so you must use a "service wrapper" program to add the missing functionality. Microsoft's free Srvany utility should do the trick but several commercial alternatives are also available.
(Note that some Windows ports of memcached support the "-d" flag to automatically install and manipulate memcached as a native Windows Service but that doesn't seem to be available in NorthScale's version...)
You can build Memcached on Windows.
http://vasil9v.tumblr.com/post/31921755331/compiling-memcached-on-cygwin-windows

Jenkins fails to execute while running as winservice

I am able to run my script successfully from jenkins when jenking is opened using war file.
If set the jenkinks as winservice my script is failing in middle.
I am trying to run a start.bat file from jenkinks, this bat file calls a java class. again this java class uses bat file to run a plink command.
Execution stops at this stepsif jenkinks is running as winservice and also I can't view the output as it is running in background.
Is there any way to make jenkinks behave normal while running as winservice
Thanks
Try this:
1. Go to services (hit windows key, type "services", select "Services" from the list of matches).
2. Find the Jenkins service and open it's properties
3. Switch to Log On tab
4. Change the service to run as you, instead of local system user.
5. Restart service.
Alternative is to fix local system user account (probably environment variables) so it works as local system user.

How can I delete a service in Windows?

I have a couple old services that I want to completely uninstall. How can I do this?
Use the SC command, like this (you need to be on a command prompt to execute the commands in this post):
SC STOP shortservicename
SC DELETE shortservicename
Note: You need to run the command prompt as an administrator, not just logged in as the administrator, but also with administrative rights. If you get errors above about not having the necessary access rights to stop and/or delete the service, run the command prompt as an administrator. You can do this by searching for the command prompt on your start menu and then right-clicking and selecting "Run as administrator". Note to PowerShell users: sc is aliased to set-content. So sc delete service will actually create a file called delete with the content service. To do this in Powershell, use sc.exe delete service instead
If you need to find the short service name of a service, use the following command to generate a text file containing a list of services and their statuses:
SC QUERY state= all >"C:\Service List.txt"
For a more concise list, execute this command:
SC QUERY state= all | FIND "_NAME"
The short service name will be listed just above the display name, like this:
SERVICE_NAME: MyService
DISPLAY_NAME: My Special Service
And thus to delete that service:
SC STOP MyService
SC DELETE MyService
Click Start | Run and type regedit in the Open: line. Click OK.
Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
Scroll down the left pane, locate the service name, right click it and select Delete.
Reboot the system.
As described above I executed:
sc delete ServiceName
However this didn't work as I was executing it from PowerShell.
When using PowerShell you must specify the full path to sc.exe because PowerShell has a default alias for sc assigning it to Set-Content. Since it's a valid command it doesn't actually show an error message.
To resolve this I executed it as follows:
C:\Windows\System32\sc.exe delete ServiceName
Use services.msc or (Start > Control Panel > Administrative Tools > Services) to find the service in question. Double-click to see the service name and the path to the executable.
Check the exe version information for a clue as to the owner of the service, and use Add/Remove programs to do a clean uninstall if possible.
Failing that, from the command prompt:
sc stop servicexyz
sc delete servicexyz
No restart should be required.
SC DELETE "service name"
Run the command on cmd as Administrator otherwise you will get this error :-
openservice failed 5 access is denied
If you have Windows Vista or above please run this from a command prompt as Administrator:
sc delete [your service name as shown in service.msc e.g moneytransfer]
For example: sc delete moneytransfer
Delete the folder C:\Program Files\BBRTL\moneytransfer\
Find moneytransfer registry keys and delete them:
HKEY_CLASSES_ROOT\Installer\Products\
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog\
HKEY_LOCAL_MACHINE\System\CurrentControlSet002\Services\
HKEY_LOCAL_MACHINE\System\CurrentControlSet002\Services\EventLog\
HKEY_LOCAL_MACHINE\Software\Classes\Installer\Assemblies\ [remove .exe references]
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Folders
These steps have been tested on Windows XP, Windows 7, Windows Vista, Windows Server 2003, and Windows Server 2008.
We can do it in two different ways
Remove Windows Service via Registry
Its very easy to remove a service from registry if you know the right path. Here is how I did that:
Run Regedit or Regedt32
Go to the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services"
Look for the service that you want delete and delete it. You can look at the keys to know what files the service was using and delete them as well (if necessary).
Delete Windows Service via Command Window
Alternatively, you can also use command prompt and delete a service using following command:
sc delete
You can also create service by using following command
sc create "MorganTechService" binpath= "C:\Program Files\MorganTechSPace\myservice.exe"
Note: You may have to reboot the system to get the list updated in service manager.
If they are .NET created services you can use the installutil.exe with the /u switch
its in the .net framework folder like
C:\Windows\Microsoft.NET\Framework64\v2.0.50727
This did the job for me on Windows 10:
start the cmd.exe as admin
run SC DELETE "com.docker.service"
reinstall docker
Here is a vbs script that was passed down to me:
Set servicelist = GetObject("winmgmts:").InstancesOf ("Win32_Service")
for each service in servicelist
sname = lcase(service.name)
If sname = "NameOfMyService" Then
msgbox(sname)
service.delete ' the internal name of your service
end if
next
sc delete name
Before removing the service you should review the dependencies.
You can check it:
Open services.msc and find the service name, switch to the "Dependencies" tab.
Source: http://www.sysadmit.com/2016/03/windows-eliminar-un-servicio.html
You can use my small service list editor utility Service Manager
You can choose any service > Modify > Delete. Method works immediately, no reboot required.
Executable file: [Download]
Source code: [Download]
Blog post: [BlogLink]
Service editor class: WinServiceUtils.cs
For me my service that I created had to be uninstalled in Control Panel > Programs and Features

Resources