Link to home
Start Free TrialLog in
Avatar of Pavan Joshi
Pavan Joshi

asked on

Force Stop Domino Service in Windows using windows script

Hello All,

I have 20 servers and need to stop Domino services before running a maintenance script. Until now I have been logging in to server and then stop the services manually which takes a long time to complete others too. Some times I get a message windows service could not stop and comes as pending. I am looking for a script which can stop the windows service (Domino) forcefully even if it fails to stop. Also, I need a confirmation that the services was stopped successfully.

Hope this can be done and I need your help on the same.
Avatar of Muhammad Burhan
Muhammad Burhan
Flag of Pakistan image

Schedule that PS before your backup

stop-service Domino -force -confirm
$a = new-object -comobject wscript.shell
$b = $a.popup(“Domino Service is stopped “,0,“Powershell Message”,1)

Open in new window


it will stop and show a message box. You can also do the same from remote, review the link and edit procedure for your requirement.
https://community.spiceworks.com/topic/395518-script-to-start-and-or-stop-a-service-on-remote-machines
Avatar of Pavan Joshi
Pavan Joshi

ASKER

I will try very soon and update with results Muhammad.
IMHO Domino shouldn't be stopped like that. There are a lot of background processes that ought to be allowed to save their data.

The proper way is to run
     C:\path\to\domino\nserver -q
but you might also try a
     net stop "Lotus Domino Server (Data)"
Is there a Lotus Notes script for stopping all domino servers which are located in many servers?
"Using the Domino Console, you can send commands to multiple servers."

See https://www.ibm.com/support/knowledgecenter/en/SSKTMJ_8.0.1/com.ibm.help.domino.admin.doc/DOC/H_THE_DOMINO_CONTROLLER_AND_CONSOLE_OVER.html

Incidentally, do you have to stop your servers for backup purposes? Many backup tools have means to interact with the Domino server they are on, in order to suspend execution while databases are backed up.

An example: https://www.veritas.com/support/en_US/article.TECH46513
I am checking it Sjef... Will get back once I perform this on this weekend
Hello Sjef,

The commands you gave worked and it is the best way to stop domino server and stop the services..

Now I need a script to run this on all 40 servers using power shell or batch file... I always prefer powershell as its easy.

1.The script should navigate to F:\Lotus\Domino>nserver -q
2. Then execute this command F:\Lotus\Domino>net stop "Lotus Domino Server (FLotusDominodata)"
3. Give me a confirmation that Domino services has stopped successfully

Please help !!!!!!!!!!!!!!!!!1111
A batch file would also do...
Hello All,

The commands you gave worked and it is the best way to stop domino server and stop the services..

Now I need a script to run this on all 40 servers using power shell or batch file... I always prefer powershell as its easy.

1.The script should navigate to F:\Lotus\Domino>nserver -q
2. Then execute this command F:\Lotus\Domino>net stop "Lotus Domino Server (FLotusDominodata)"
3. Give me a confirmation that Domino services has stopped successfully

Please help !!!!!!!!!!!!!!!!!1111
Sorry, can't help you there. I asked an Admin/Powerscript expert to drop by. I hope he can help, but I doubt very much that it can be done.
Are these all on the same windows domain and you can run a script as domain admins or suitable admin on each machine?  Also assuming they are all hosted on Windows servers, not Linux etc.?

Also do you know if the service names on each server are the same?

Would suggest you could do with powershell, but also with batch, e.g. on one machine logged in as admin then would do along the lines of :

e.g. a text file with:

Windows.servername,"servicename"
i.e.

ABC123,"Lotus Domino Server (FLotusDominodata)"

In this %%s gets the first token off each line, %%t the rest of the line after the , and is used in a for loop in the .cmd file, checks the status before and after for each with SC QUERY

@echo off
set logfile="c:\somedir\logfile.txt"
set serverlist="c:\somedir\servers.txt"

(for /f "tokens=1* delims=," %%s in ('type %serverlist%') do (
  echo Working on %%s.  Current state: >CON
  sc \\%%s query "%%~t"  ^|find "STATE"
  sc \\%%s stop 
  sc \\%%s query "%%~t"  ^|find "STATE"
) >%logfile%
notepad %logfile%

Open in new window


That will no doubt need some tweaks but gives one idea of how could be done in batch.  My Powershell is less good but was trying to think of neat way to do it as would have same issue of potentially not knowing the service names.

You could get a list of the service names given a list of just the server names in a text file with something like this looking for ones that start IBM or Lotus and have Server in the name.

@echo off
set logfile="c:\somedir\logfile.txt"
set serverlist="c:\somedir\servers.txt"

(for /f "tokens=1 delims=," %%s in ('type %serverlist%') do (
  echo Checking server: %%s
  sc query | findstr /i /c:IBM /c:Lotus | find /i "Server" | find /i "SERVICE_NAME"
) > %logfile%
notepad %logfile%

Open in new window

But how to execute it is what I am confused of. As of now can you help me only below steps in a batch file.

1. Open command prompt and navigate to F:\Lotus\ Domino
2. Execute the command nserver -q
3. Execute this command F:\Lotus\Domino>net stop "Lotus Domino Server (FLotusDominodata)"

First I want to do this on one machine. Yes, Domino are on windows 2012 server.
Are these all on the same windows domain and you can run a script as domain admins or suitable admin on each machine?  Also assuming they are all hosted on Windows servers, not Linux etc.?

Answer: Yes, they are on windows server 2012 and I have access to run.

Also do you know if the service names on each server are the same?

Yes, Service name on each server is same as mentioned below:
"Lotus Domino Server (FLotusDominodata)"
You do not need to run nserver.exe -q to quit the server, stopping the service will do that anyway. There was a typo in the last script, I had missed off the SC stop line the service name:

  sc \\%%s stop

should have been

  sc \\%%s stop "%%~t"

SC is another way of controlling services and checking their statuses that does the same as NET STOP but you can run remotely.  So you can run this batch file based on a list of servers in the text file and it will run the Service stop command against them all.

As all the service names are exactly the same then you can do away with the need for listing them in a text file.  You can just make a text file in notepad listing the windows server names:

server1
server2
server3.domain.local
etc. as needed

Then You can use a simplified batch file.  Save this as stop-all.cmd choosing "all files" as type when saving in Notepad so you don't get .txt on the file name.

@echo off
set logfile="c:\somedir\logfile.txt"
set serverlist="c:\somedir\servers.txt"
set servicename="Lotus Domino Server (FLotusDominodata)" 

(for /f "tokens=1* delims=," %%s in ('type %serverlist%') do (
  echo Working on %%s.  Current state: >CON
  sc \\%%s query %servicename%  ^|find "STATE"
  sc \\%%s stop %servicename%
  sc \\%%s query %servicename%  ^|find "STATE"
) >%logfile%
notepad %logfile%

Open in new window


You can replace the word stop with start and have it restart all the services too if wanted then.

Steve
So now I just need to create one servers.txt file with server name?
I will try to night and dont know how to thank you for this... Thanks Exchange Experts :)
I just tried executing it... its just flash and does noting...

In the new text file servers.txt I have just typed the server name... Is that i am doing correct?
Also I have changed the path in the batch file....
@echo off
set logfile="c:\somedir\logfile.txt"
set serverlist="c:\temp\servers.txt"
set servicename="Lotus Domino Server (FLotusDominodata)"

(for /f "tokens=1* delims=," %%s in ('type %serverlist%') do (
  echo Working on %%s.  Current state: >CON
  sc \\%%s query %servicename%  ^|find "STATE"
  sc \\%%s stop %servicename%
  sc \\%%s query %servicename%  ^|find "STATE"
) >%logfile%
notepad %logfile%
OK.  I'm busy at the moment but will check back later.  There is a missing ) of the line

)) > %logfile%

Sorry, my typo.  The first ) closes the one with the "DO", the second ) closes the one around the whole for statement which redirects to the log file.

Also if you add "PAUSE" in the script at any point you will have to press a key to continue if you want to see what it is doing more.

Steve
User generated imageHello Steve,

Below is the error in log file,

ERROR:  Invalid Option

DESCRIPTION:
        SC is a command line program used for communicating with the
        Service Control Manager and services.

Also, When I execute the batch file it just shows this message : "Working on server.gh.com Current state:"

Can you tell me what could be the issue?
ERROR:  Invalid Option

DESCRIPTION:
        SC is a command line program used for communicating with the
        Service Control Manager and services.
USAGE:
        sc <server> [command] [service name] <option1> <option2>...


        The option <server> has the form "\\ServerName"
        Further help on commands can be obtained by typing: "sc [command]"
        Commands:
          query-----------Queries the status for a service, or
                          enumerates the status for types of services.
          queryex---------Queries the extended status for a service, or
                          enumerates the status for types of services.
          start-----------Starts a service.
          pause-----------Sends a PAUSE control request to a service.
          interrogate-----Sends an INTERROGATE control request to a service.
          continue--------Sends a CONTINUE control request to a service.
          stop------------Sends a STOP request to a service.
          config----------Changes the configuration of a service (persistent).
          description-----Changes the description of a service.
          failure---------Changes the actions taken by a service upon failure.
          failureflag-----Changes the failure actions flag of a service.
          sidtype---------Changes the service SID type of a service.
          privs-----------Changes the required privileges of a service.
          managedaccount--Changes the service to mark the service account
                          password as managed by LSA.
          qc--------------Queries the configuration information for a service.
          qdescription----Queries the description for a service.
          qfailure--------Queries the actions taken by a service upon failure.
          qfailureflag----Queries the failure actions flag of a service.
          qsidtype--------Queries the service SID type of a service.
          qprivs----------Queries the required privileges of a service.
          qtriggerinfo----Queries the trigger parameters of a service.
          qpreferrednode--Queries the preferred NUMA node of a service.
          qrunlevel-------Queries the run level of a service.
          qmanagedaccount-Queries whether a services uses an account with a
                          password managed by LSA.
          qprotection-----Queries the process protection level of a service.
          delete----------Deletes a service (from the registry).
          create----------Creates a service. (adds it to the registry).
          control---------Sends a control to a service.
          sdshow----------Displays a service's security descriptor.
          sdset-----------Sets a service's security descriptor.
          showsid---------Displays the service SID string corresponding to an arbitrary name.
          triggerinfo-----Configures the trigger parameters of a service.
          preferrednode---Sets the preferred NUMA node of a service.
          runlevel--------Sets the run level of a service.
          GetDisplayName--Gets the DisplayName for a service.
          GetKeyName------Gets the ServiceKeyName for a service.
          EnumDepend------Enumerates Service Dependencies.

        The following commands don't require a service name:
        sc <server> <command> <option>
          boot------------(ok | bad) Indicates whether the last boot should
                          be saved as the last-known-good boot configuration
          Lock------------Locks the Service Database
          QueryLock-------Queries the LockStatus for the SCManager Database
EXAMPLE:
        sc start MyService

Would you like to see help for the QUERY and QUERYEX commands? [ y | n ]:


SERVICE_NAME: Lotus Domino Server (FLotusDominodata)
        TYPE               : 110  WIN32_OWN_PROCESS  (interactive)
        STATE              : 3  STOP_PENDING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 1638256  (0x18ff70)
        CHECKPOINT         : 0x1
        WAIT_HINT          : 0x7530
Odd. Will look from pc in a bit. If you remove echo off from top can see commands it is trying to run.

Steve
OK, have tested this now.  My service names were of the form "IBM Domino Server (CIBMDominodata)" being R8.5 or R9 fresh installs but you can use your  "Lotus Domino Server (FLotusDominodata)" and if you find some are different we can go back to original version.

This queries the current state, tries to stop the service then queries the state again.

Steve

@echo off
setlocal enabledelayedexpansion
set logfile="c:\temp\logfile.txt"
set serverlist="c:\temp\servers.txt"
set servicename="Lotus Domino Server (FLotusDominodata)"

(
echo %DATE %TIME% LOG STARTED - ran by %username% on %computername%
ECHO.

for /f "tokens=1* delims=," %%s in ('type %serverlist%') do (
  echo Working on %%s.  Current state: > CON
    for /f "tokens=2 delims=:" %%X in ('sc \\%%s query %servicename% ^|find "STATE"') do echo BEFORE: %%s - %%X
    sc \\%%s stop %servicename%
    for /f "tokens=2 delims=:" %%X in ('sc \\%%s query %servicename% ^|find "STATE"') do echo AFTER: %%s - %%x
)

ECHO.
echo %DATE %TIME% LOG END
)>%logfile%

start "" notepad %logfile%

Open in new window

Will Test and get back Steve :)
Hello Steve, It worked... However I would like to ask one last question.. When we use to stop services manually it used to give message as stop pending, hence we had to restart the server at times. Can we give a force stop in this batch file by any chance?
Stopping service should always work though agreed it could get stuck in some circumstances.

You could kill off the tasks using taskkill command if the service hasn't stopped after a while say.

Alternatively you could mark the service as "manual" and restart the server (shutdown /r /m \\servername)

I'd see how you go with just using net stop as if it isn't working you have more than likely got another issue which needs looking at rather than bodging it by killing off tasks?

Steve
@Steve: I think you proved me terribly wrong (re: https:#a42045589). Good show!
You can do anything with scripts ... I suppose could probably do it in a Notes database or domino web app with status of all the servers, buttons to shut them down etc too :-)
@Steve, is there any way we can get the confirmation if the services has stopped or stuck so that we can login to that particular server and follow the above steps?
Or a script to validate if services has stopped on all servers in list will also do...
Your log file will show you the status before then after it is stopped so should show you anyway?

You can also run the script again if wanted and it will try to stop any remaining.

If wanted could do the same with just the query command not stop.

Steve
Back at pc now... I mean like this.  Just stripped out the one query and stop lines and you have a status checker.  If you want one to start the services back again afterwards.... yes same as https:#a42047680 but START :-)

@echo off
setlocal enabledelayedexpansion
set logfile="c:\temp\logfile.txt"
set serverlist="c:\temp\servers.txt"
set servicename="Lotus Domino Server (FLotusDominodata)"

(
echo %DATE %TIME% LOG STARTED - ran by %username% on %computername%
ECHO.

for /f "tokens=1* delims=," %%s in ('type %serverlist%') do (
  echo Working on %%s.  Current state: > CON
    for /f "tokens=2 delims=:" %%X in ('sc \\%%s query %servicename% ^|find "STATE"') do echo AFTER: %%s - %%x
)

ECHO.
echo %DATE %TIME% LOG END
)>%logfile%

start "" notepad %logfile%

Open in new window

ID: 42063646: The above script will give the status of the services has stopped or not?
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello Steve and other folks,

Above script worked for me and it completed what I wanted.
Appreciate for timely help and this is one the best experience with Expert Exchange till date.
Kudos to all :)
No problem, glad it helped.