How to shut down cleanly on user logoff?

Find and share HowTos to various installations / configurations!
10 posts • Page 1 of 1
iain
Posts:33
Joined: Fri May 19, 2017 7:08 pm

How to shut down cleanly on user logoff?

Post by iain »

I'm trying to avoid running an OA application as a service. (I'm using additional utilities which don't work well as a service.)

Normally application stops with a user action and everything is fine. I'd like to cover the case where an operator logs out or shuts down without first terminating the application, though.

I've added a Windows logoff and shutdown script which is a batch file which uses
C:\\Siemens\\Automation\\WinCC_OA\\3.15\\bin\\wccilpmon -currentproj -stopWait

This works just fine when run from a command prompt, but if I log off instead, the OA managers appear to stop cleanly, but on next startup I get
Datenbank wird nach 30 Sekunden Wartezeit repariert.
in the log.

Is there a way that I can safely shut an application down from a logout script?

nmnogueira
Posts:125
Joined: Thu May 05, 2011 12:59 pm

Re: How to shut down cleanly on user logoff?

Post by nmnogueira »

You can try running "kill_pvss2.cmd" from the /bin/ folder. I am not sure that the result won't be the same though...

iain
Posts:33
Joined: Fri May 19, 2017 7:08 pm

Re: How to shut down cleanly on user logoff?

Post by iain »

I'm thinking that the problem may be unsolvable. Windows appears to be stopping the managers directly; either it's terminating them individually or they're handling the shutdown message and exiting. I get occasional application error dialogs in the archive manager, and if I cancel the logoff then the next startup still causes a database repair.

kill_pvss2.cmd doesn't seem to help this. It successfully shuts the app down for me from a command prompt, but always hangs. Interrupting and restarting doesn't cause a repair. If I have it in my logout script, though, when restarting the application the database repair starts just as before, so I don't think it's changing the behavior, and the managers are not shutting down cleanly.

Any suggestions?

Gertjan van Schijndel
Posts:634
Joined: Mon Aug 02, 2010 10:37 am

Re: How to shut down cleanly on user logoff?

Post by Gertjan van Schijndel »

Perhaps you should consider running the additional utilities in a separate (user session) project, while the other managers run in a (service) project.

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: How to shut down cleanly on user logoff?

Post by leoknipp »

Maybe stopping the project lasts longer than the time which is needed for the shutdown of the computer and therefore some processes are not stopped properly.
Please have a look at the logfile pmon. to see if WinCC OA processes are stopped when executing one of the commands to stop a project.

Maybe you can configure Windows to wait a defined time before shutting down the computer.
Please get in contact with your system administration to see if there is such a possibility.

Best Regards
Leopold Knipp
Senior Support Specialist

iain
Posts:33
Joined: Fri May 19, 2017 7:08 pm

Re: How to shut down cleanly on user logoff?

Post by iain »

Re: running utilities in a separate project: That's an interesting idea, and in a perfect world I think that would be my preference. Have a control project and a separate user-space management project. I can't see me getting approval for two licenses per station though :).

It does bring up a thought. The UI does run under the user account. I believe that the problems we're having are in a control manager, which is part of the service. I have control of one of the utilities and have already made it a service. Other than lack of testing, that resolves one problem. The other, and major one, is Excel. We had a recent failure in several applications at once, and when our engineer looked at the applications he found many instances of Excel running invisibly. So our suspicion is someone copied a file with an error (possibly a macro that Excel wanted permission to run) and Excel popped up dialogs that we couldn't see because it didn't have a UI. Maybe if I could move the Excel access functions into scripts within the user interface that wouldn't be a problem.

iain
Posts:33
Joined: Fri May 19, 2017 7:08 pm

Re: How to shut down cleanly on user logoff?

Post by iain »

Re: delaying shutdown. I've experimented with this, and that doesn't seem to be the case. I can delay shutdown by adding a sleep statement to the logout script. I did that, but it doesn't delay the managers terminating, and they don't appear to be shutting down cleanly. If I wait until the logout script hits a delay and then cancel the shutdown (leaving the project administrator window up allows me to cancel) then I still see the database repair when I restart. I forget why I decided this, but I believe that the archive manager terminated unexpectedly. I will try it again and check the log.

iain
Posts:33
Joined: Fri May 19, 2017 7:08 pm

Re: How to shut down cleanly on user logoff?

Post by iain »

This is the log file from a shutdown when I run the shutdown script from a command prompt without logging out. (Shutdown script does a wccilpmon -currentproj -stopWait)

Code: Select all

WCCILpmon    (1), 2017.11.14 10:08:52.301, SYS,  INFO,        3/pmon, Got shutdown command - stopping the project and terminating
WCCILpmon    (1), 2017.11.14 10:08:52.302, SYS,  INFO,       17/pmon, Stopping Manager WCCOAui(2) with signal SIGTERM
WCCILpmon    (1), 2017.11.14 10:08:52.303, SYS,  INFO,       17/pmon, Stopping Manager WCCOActrl(4) with signal SIGTERM
WCCILpmon    (1), 2017.11.14 10:08:52.304, SYS,  INFO,       17/pmon, Stopping Manager WCCOAui(1) with signal SIGTERM
WCCILpmon    (1), 2017.11.14 10:08:52.305, SYS,  INFO,       17/pmon, Stopping Manager WCCILsim(1) with signal SIGTERM
WCCILpmon    (1), 2017.11.14 10:08:52.306, SYS,  INFO,       17/pmon, Stopping Manager WCCOActrl(1) with signal SIGTERM
WCCILpmon    (1), 2017.11.14 10:08:52.307, SYS,  INFO,       17/pmon, Stopping Manager WCCOAvalarch(0) with signal SIGTERM
WCCOAui      (2), 2017.11.14 10:08:52.310, SYS,  INFO,      170, Signal SIGTERM received - exiting ...
WCCOActrl    (4), 2017.11.14 10:08:52.310, SYS,  INFO,      170, Signal SIGTERM received - exiting ...
WCCOAui      (1), 2017.11.14 10:08:52.331, SYS,  INFO,      170, Signal SIGTERM received - exiting ...
WCCILsim     (1), 2017.11.14 10:08:52.331, SYS,  INFO,      170, Signal SIGTERM received - exiting ...
WCCOActrl    (1), 2017.11.14 10:08:52.331, SYS,  INFO,      170, Signal SIGTERM received - exiting ...
WCCOActrl    (4), 2017.11.14 10:08:54.353, SYS,  INFO,      181, Closing connection to (SYS: 1 Data -num 0 CONN: 1)
WCCILdata    (0), 2017.11.14 10:08:54.353, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Ctrl -num 4 CONN: 1), Connection closed
WCCOActrl    (4), 2017.11.14 10:08:54.353, SYS,  INFO,      181, Closing connection to (SYS: 1 Event -num 0 CONN: 1)
WCCILevent   (0), 2017.11.14 10:08:54.353, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Ctrl -num 4 CONN: 1), Connection closed
WCCOActrl    (4), 2017.11.14 10:08:54.355, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Data -num 0 CONN: 1), Connection closed
WCCOActrl    (4), 2017.11.14 10:08:54.355, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Event -num 0 CONN: 1), Connection closed
WCCOAui      (2), 2017.11.14 10:08:54.387, SYS,  INFO,      181, Closing connection to (SYS: 1 Data -num 0 CONN: 1)
WCCILdata    (0), 2017.11.14 10:08:54.387, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Ui -num 2 CONN: 1), Connection closed
WCCOAui      (2), 2017.11.14 10:08:54.387, SYS,  INFO,      181, Closing connection to (SYS: 1 Event -num 0 CONN: 1)
WCCOAui      (2), 2017.11.14 10:08:54.388, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Data -num 0 CONN: 1), Connection closed
WCCILevent   (0), 2017.11.14 10:08:54.388, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Ui -num 2 CONN: 1), Connection closed
WCCOAui      (2), 2017.11.14 10:08:54.389, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Event -num 0 CONN: 1), Connection closed
WCCILsim     (1), 2017.11.14 10:08:54.421, SYS,  INFO,      181, Closing connection to (SYS: 1 Data -num 0 CONN: 1)
WCCILdata    (0), 2017.11.14 10:08:54.421, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Driver -num 1 CONN: 1), Connection closed
WCCILsim     (1), 2017.11.14 10:08:54.421, SYS,  INFO,      181, Closing connection to (SYS: 1 Event -num 0 CONN: 1)
WCCILevent   (0), 2017.11.14 10:08:54.421, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Driver -num 1 CONN: 1), Connection closed
WCCILsim     (1), 2017.11.14 10:08:54.422, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Data -num 0 CONN: 1), Connection closed
WCCILsim     (1), 2017.11.14 10:08:54.422, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Event -num 0 CONN: 1), Connection closed
WCCILsim     (1), 2017.11.14 10:08:54.423, SYS,  INFO,        2, Manager Stop
WCCOActrl    (4), 2017.11.14 10:08:54.443, SYS,  INFO,        2, Manager Stop
WCCOAui      (2), 2017.11.14 10:08:54.491, SYS,  INFO,        2, Manager Stop
WCCOAui      (1), 2017.11.14 10:08:54.497, SYS,  INFO,      181, Closing connection to (SYS: 1 Data -num 0 CONN: 1)
WCCOAui      (1), 2017.11.14 10:08:54.497, SYS,  INFO,      181, Closing connection to (SYS: 1 Event -num 0 CONN: 1)
WCCILdata    (0), 2017.11.14 10:08:54.497, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Ui -num 1 CONN: 1), Connection closed
WCCILevent   (0), 2017.11.14 10:08:54.497, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Ui -num 1 CONN: 1), Connection closed
WCCOAui      (1), 2017.11.14 10:08:54.498, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Data -num 0 CONN: 1), Connection closed
WCCOAui      (1), 2017.11.14 10:08:54.498, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Event -num 0 CONN: 1), Connection closed
WCCOAui      (1), 2017.11.14 10:08:54.566, SYS,  INFO,        2, Manager Stop
WCCOActrl    (1), 2017.11.14 10:08:54.675, SYS,  INFO,      181, Closing connection to (SYS: 1 Data -num 0 CONN: 1)
WCCILdata    (0), 2017.11.14 10:08:54.676, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Ctrl -num 1 CONN: 1), Connection closed
WCCOActrl    (1), 2017.11.14 10:08:54.678, SYS,  INFO,      181, Closing connection to (SYS: 1 Event -num 0 CONN: 1)
WCCILevent   (0), 2017.11.14 10:08:54.679, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Ctrl -num 1 CONN: 1), Connection closed
WCCOActrl    (1), 2017.11.14 10:08:54.682, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Data -num 0 CONN: 1), Connection closed
WCCOActrl    (1), 2017.11.14 10:08:54.694, CTRL, WARNING,    38, Message could not be sent, calculateState.ctl    Line: 433, dpSet
WCCOActrl    (1), 2017.11.14 10:08:54.698, CTRL, WARNING,    38, Message could not be sent, calculateState.ctl    Line: 433, dpSet
WCCOActrl    (1), 2017.11.14 10:08:54.698, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Event -num 0 CONN: 1), Connection closed
WCCOActrl    (1), 2017.11.14 10:08:54.764, SYS,  INFO,        2, Manager Stop
WCCOAvalarch (0), 2017.11.14 10:08:58.381, SYS,  INFO,      181, Closing connection to (SYS: 1 Data -num 0 CONN: 1)
WCCILdata    (0), 2017.11.14 10:08:58.381, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Data -num 2 CONN: 1), Connection closed
WCCILdata    (0), 2017.11.14 10:08:58.381, PARAM,INFO,        2, Manager Stop, HistOrgMain, archive is now offline, archive number is:0
WCCOAvalarch (0), 2017.11.14 10:08:58.382, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Data -num 0 CONN: 1), Connection closed
WCCOAvalarch (0), 2017.11.14 10:08:58.382, SYS,  INFO,       39, Connection lost, (SYS: 1 Data -num 0 CONN: 1)
WCCOAvalarch (0), 2017.11.14 10:08:58.382, SYS,  INFO,        2, Manager Stop
WCCILpmon    (1), 2017.11.14 10:08:58.453, SYS,  INFO,       17/pmon, Stopping Manager WCCILevent(0) with signal SIGTERM
WCCILevent   (0), 2017.11.14 10:08:58.453, SYS,  INFO,        2, Manager Stop, received signal 15, exiting
WCCILevent   (0), 2017.11.14 10:08:58.483, SYS,  INFO,        2, Manager Stop, start cleanup
WCCILevent   (0), 2017.11.14 10:08:58.483, SYS,  INFO,      181, Closing connection to (SYS: 1 Data -num 0 CONN: 1)
WCCILdata    (0), 2017.11.14 10:08:58.516, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Event -num 0 CONN: 1), Connection closed
WCCILevent   (0), 2017.11.14 10:08:58.516, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Data -num 0 CONN: 1), Connection closed
WCCILevent   (0), 2017.11.14 10:08:58.521, SYS,  INFO,        2, Manager Stop
WCCILpmon    (1), 2017.11.14 10:08:58.553, SYS,  INFO,       17/pmon, Stopping Manager WCCILdata(0) with signal SIGTERM
WCCILdata    (0), 2017.11.14 10:09:01.529, SYS,  INFO,        0, , Loading DpIdentification
WCCILdata    (0), 2017.11.14 10:09:01.534, SYS,  INFO,        2, Manager Stop
WCCILpmon    (1), 2017.11.14 10:09:01.605, SYS,  INFO,       15/pmon, Completely stopped the project - terminating
WCCILpmon    (1), 2017.11.14 10:09:01.606, SYS,  INFO,        2, Manager Stop
This is what happens when I log off, with the same script as a logout script.

Code: Select all

WCCOAui      (2), 2017.11.14 10:04:18.923, SYS,  INFO,      181, Closing connection to (SYS: 1 Data -num 0 CONN: 1)
WCCILdata    (0), 2017.11.14 10:04:18.923, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Ui -num 2 CONN: 1), Connection closed
WCCOAui      (2), 2017.11.14 10:04:18.923, SYS,  INFO,      181, Closing connection to (SYS: 1 Event -num 0 CONN: 1)
WCCOAui      (2), 2017.11.14 10:04:18.924, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Data -num 0 CONN: 1), Connection closed
WCCILevent   (0), 2017.11.14 10:04:18.924, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Ui -num 2 CONN: 1), Connection closed
WCCOAui      (2), 2017.11.14 10:04:18.927, SYS,  INFO,       39, Connection lost, MAN: (SYS: 1 Event -num 0 CONN: 1), Connection closed
WCCOAui      (2), 2017.11.14 10:04:18.987, SYS,  INFO,        2, Manager Stop
WCCILdata    (0), 2017.11.14 10:04:19.016, SYS,  WARNING,    39, Connection lost, MAN: (SYS: 1 Ctrl -num 4 CONN: 1), Connection reset by peer (10054)
WCCILevent   (0), 2017.11.14 10:04:19.016, SYS,  WARNING,    39, Connection lost, MAN: (SYS: 1 Ctrl -num 4 CONN: 1), Connection reset by peer (10054)
WCCILdata    (0), 2017.11.14 10:04:19.138, SYS,  WARNING,    39, Connection lost, MAN: (SYS: 1 Ui -num 1 CONN: 1), Connection reset by peer (10054)
WCCILevent   (0), 2017.11.14 10:04:19.138, SYS,  WARNING,    39, Connection lost, MAN: (SYS: 1 Ui -num 1 CONN: 1), Connection reset by peer (10054)
WCCILdata    (0), 2017.11.14 10:04:19.141, SYS,  WARNING,    39, Connection lost, MAN: (SYS: 1 Driver -num 1 CONN: 1), Connection reset by peer (10054)
WCCILevent   (0), 2017.11.14 10:04:19.141, SYS,  WARNING,    39, Connection lost, MAN: (SYS: 1 Driver -num 1 CONN: 1), Connection reset by peer (10054)
WCCILdata    (0), 2017.11.14 10:04:19.151, SYS,  WARNING,    39, Connection lost, MAN: (SYS: 1 Ctrl -num 1 CONN: 1), Connection reset by peer (10054)
WCCILdata    (0), 2017.11.14 10:04:19.154, SYS,  WARNING,    39, Connection lost, MAN: (SYS: 1 Event -num 0 CONN: 1), Connection reset by peer (10054)
WCCILdata    (0), 2017.11.14 10:04:19.156, SYS,  WARNING,    39, Connection lost, MAN: (SYS: 1 Data -num 2 CONN: 1), Connection reset by peer (10054)
WCCILdata    (0), 2017.11.14 10:04:19.156, SYS,  WARNING,    65, Wrong destination address, (SYS: 1 Event -num 0 CONN: 1), DP_MSG_COMPLEX_VC
WCCILdata    (0), 2017.11.14 10:04:19.156, SYS,  WARNING,    65, Wrong destination address, (SYS: 1 Event -num 0 CONN: 1), DP_MSG_COMPLEX_VC
WCCILdata    (0), 2017.11.14 10:04:19.156, PARAM,INFO,        2, Manager Stop, HistOrgMain, archive is now offline, archive number is:0
WCCILpmon    (1), 2017.11.14 10:05:01.143, PARAM,WARNING,   224, Security issue: Username or Password entry found in config file!
I don't see "got shutdown command", I don't see "SIGTERM"s. I do see a lot of TCP/IP errors. That makes me think the problem isn't really that WinCC_OA isn't handling a shutdown request, it's that Windows closed the port and the managers can't recover. If that's the case I think I'm out of luck, because there's no way that I'm aware of to reorder the Windows shutdown sequence. Any ideas?

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: How to shut down cleanly on user logoff?

Post by leoknipp »

As you have observed there is no log message which describes a normal shutdown.
For me it looks like only the UI is stopped normally. The log messages written by the data/event describe that the peer has closed the connection. Maybe the process was stopped by Windows, e.g. by receiving a signal.
Why the normal project stop is not executed I cannot see at the log messages.

If you want to stop the project when the UI is stopped you can maybe use another solution:
-- in the Terminate-script for the main panel which is opened all the time, e.g. the panel topology template a script is defined which makes a dpSet() for a project specific datapoint element
-- a CTRL manager reacts on this datapoint element
-- in the work function a command is executed using the system() command
pkill -15

Then the project and process monitor is stopped.

Best Regards
Leopold Knipp
Senior Support Specialist

iain
Posts:33
Joined: Fri May 19, 2017 7:08 pm

Re: How to shut down cleanly on user logoff?

Post by iain »

Thanks. Yeah, we have a clean shutdown handled in-application now. What I'm trying to cover is the case where a customer logs out without shutting down cleanly. It isn't necessarily initiated by the customer, but if a power button / battery low / whatever configuration logs the user out or shuts down the system I risk corrupting the database.

Running as a service, this isn't an issue, and I think we're going to need just to keep doing that. It turns out that in the application that failed we're querying Excel from the control manager (under the service account). More recent applications do in fact embed Excel in the UI, which runs as the logged-in user, so maybe this is the solution.

If Windows is signalling / closing managers or connections directly, there's really no workaround.

Well, the other thing I've been considering is setting the application machines up as "kiosks" with logout and shutdown disabled. I would still be nervous that the Windows configuration could cause a logout or shutdown on a system event like low battery.

I appreciate all of the help and advice.

10 posts • Page 1 of 1