How to gracefully shutdown your SAP ABAP Platform Developer Edition when shutting down Windows
Docker does only wait 10 seconds
As announced by the blog SAP ABAP Platform 1909, Developer Edition: AVAILABLE NOW of my colleague Julie Plummer the new ABAP Platform developer edition is available as a Docker image so that you can run it on your laptop.
Running it on you laptop does also mean that you are responsible for it and that you have to make sure to shutdown the system in a proper way.
Unfortunately Docker only waits up to 10 seconds for a container to stop before it kills the process which will then result in an inconsistent HANA DB 😒.
This happened to me on the very first day as a ABAP Platform developer edition user 😥.
As mentioned in the setup instructions of the ABAP platform docker image in order to gracefully shutdown your docker image you should run the following command before stopping docker or shutting down your laptop.
docker stop --time 7200 a4h
So if you just shutdown your laptop (as I did) without having run the above mentioned command beforehand you have a problem …
If this happens to you, you only have to delete the container using Docker Desktop and recreate it using the following command
docker run --stop-timeout 3600 -i --name a4h -h vhcala4hci -p 3200:3200 -p 3300:3300 -p 8443:8443 -p 30213:30213 -p 50000:50000 -p 50001:50001 store/saplabs/abaptrial:1909 -skip-limits-check -agree-to-sap-license
So you fortunately don’t have to download the whole image again 😅.
However all the ABAP development you have done might be lost if you haven’t saved it to some Git repository.
Gracefully shutdown docker container using Group Policy Editor
Reading through the setup instructions I was wondering whether there is a way to run the command as a script automatically when shutting down Windows because I know myself and I was sure that I would otherwise run into this problem again and again.
As described in this answer posted on Stackoverflow it is possible to do the following:
- Run gpedit.msc to open the Group Policy Editor
- Navigate to Computer Configuration | Windows Settings | Scripts (Startup/Shutdown).
- Double click on Shutdown
This will open a dialogue to select a script from a location of your choice. The default location (administrative access is needed) is the following folder
Here I have created the script stop_docker.cmd
The source code of this script is shown here
set MyDir="C:\temp" IF not exist %MyDir% ( mkdir %MyDir% ) echo stopping instance a4h %date% %time% >> %MyDir%\docker_stop.txt docker stop --time 7200 a4h 1>> %MyDir%\docker_stop.txt 2>>&1 echo instance a4h stopped %date% %time% >> %MyDir%\docker_stop.txt
The script first checks if the directory C:\temp does exist. If not, it will create it. Afterwards the system date and system time will be read from environment variables and are added to the log file docker_stop.txt and your docker container a4h will be safely stopped using the command docker stop –time 7200 a4h.
This provides up to 7200 seconds for SAP HANA to safely shut down.
Checking the log file
When you run the script manually from a cmd box (be sure to use the option Run as Administrator because the folder where the script resides can only accessed with administrative rights) you will find that a file docker_stop.txt has been created in the specified folder (here C:\temp).
Here you then find entries like the following:
- stopping instance a4h 05.03.2021 12:49:34,09
error during connect: In the default daemon configuration on Windows, the docker client must be run with elevated privileges to connect.: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/a4h/stop?t=7200: open //./pipe/docker_engine: The system cannot find the file specified.
instance a4h stopped 05.03.2021 12:49:34,35
- stopping instance a4h 05.03.2021 12:50:27,80
Error response from daemon: open \\.\pipe\docker_engine_linux: The system cannot find the file specified.
instance a4h stopped 05.03.2021 12:50:28,11
- stopping instance a4h 05.03.2021 12:51:00,26
instance a4h stopped 05.03.2021 12:51:00,54
- stopping instance a4h 05.03.2021 12:59:44,81
instance a4h stopped 05.03.2021 13:00:55,96
which have been created as follows:
- Entries like the first one you will find if Docker Desktop has not been started.
- The second type of entries you will find when run the script docker_stop.cmd but Docker Desktop is still starting.
- The third type of entries that shows a very fast shutdown you will find when Docker is running but when your instance A4H has not been started yet.
- The fourth entry is finally the one that shows the graceful shutdown of a running SAP ABAP platform docker instance.
As you can see the shutdown will take more than 60 seconds.
So we notice that the shutdown of your windows machine will not be postponed for the 7200 seconds but only for the time it takes to gracefully shutdown the docker instance of your SAP ABAP platform installation.
Putting a script on my desktop to start the SAP ABAP developer edition
Last not least I put a script start_a4.cmd on my desktop that only contains the following command.
docker start -ai a4h
so that I can conveniently start the container of my SAP ABAP developer edition.
When using the script wait until you see the line *** Have fun! *** before trying to log on to your SAP ABAP developer edition.
When you use the script stop_docker.cmd to gracefully shut down your docker image you will see in this command box the output of the shut down procedure starting with the output
My termination has been requested
In principle it would also be possible to put this script into the folder
and schedule the docker container to start automatically each time you start your laptop, but since the docker image consumes quite some resources I refrained from doing so.