Saturday, October 16, 2010

PVSS as service (automated scripts) - part 1

    PVSS is a system and framework meant to handle a lot of things in the business of energy and industry. One of the most often used scenarios is having several interconnected machines running PVSS projects in a redundancy mode (think of it as RAID for software instead of hardware), each of them doing... well... something. During a PVSS training you may learn how to build a project, how to set up a redundant and/or a distributed system, but all of these using the same log in credentials: your own. In order for any project to start, you would need to log in first, not just into PVSS but your OS too.

    In a production environment, the used servers should be configured to start whenever there is (electrical) power available. Of course, you can't expect someone to be around whenever a power outage takes place to start the machines and log in to the OS. The whole point of a service is to allow automation and to not require a user presence or even a user log in to occur. And this is something that you won't find in the basic to medium level PVSS trainings: how to prepare a project to run as a service.

    Luckily, there is a PVSS help entry on the topic. Just search for the word service and you'll find what you're searching for. While the quite arcane and not very intuitive CHM help is used, the amount of information it provides is sufficient to help you be on your way to setting up the service.
   The following example will only show you how to set up services for the Windows family of operating systems.

    Before you start, here's what you need:
    - a project. This tutorial will show you how to make a project run as a service, not how to make a project :-). Make sure that the project is not running, so you may start it using the service. Make sure no other projects that use the same port(s) are running. Also close the any PVSS Console found open.
    - a correctly installed version of PVSS (I'll use 3.9, but other versions should behave similarly). Oh, and correctly installed also means you did not mess with the environment variables... so make sure PVSS00pmon.exe is in a folder located in your PATH.

    The simple mechanism
    Basically, you need to use a PVSS tool (PVSS00pmon.exe), and you can create a Windows service called PMON_SERVICE_1 (you can change the name), for your already existing project named MYPROJECT, located in [d:\work\pvss] (again, you can change these) by running this command from the command line:
    PVSS00pmon.exe -install -name PMON_SERVICE_1 -set d:\work\pvss\MYPROJECT\config\config 1 -user "NT AUTHORITY\NetworkService"
    Then, you must open the services console (Start Menu -> Run -> "services.msc" for Windows XP), find your process according to the used name, open its properties, go to the "Log On" tab, set to use the Local System account and allow it to interact with the desktop. (Note: here's an interesting post about this setting, but from what I've noticed, it hasn't been removed.)

    Now you may start the service (e.g. right click PMON_SERVICE_1 -> "Start").
   
    Possible issues
    If it doesn't start, you may have forgotten a PVSS project or console opened.

    After the project is started, you may open the console and check the status of the project. If you omit setting the service to interact with the desktop, you may notice that your project won't start, hanging at the Database Manager start-up sequence. If that's the case, just stop the service, apply the setting and start it again.
    Okay, so that's it, you have a running service. Why -oh why- would you need to automate something as short as that? Well... you don't really need to, but it sure pays off if you do when you need to do this for large systems. Imagine just starting a batch file as opposed to do the previous steps. Do it for one machine... not much of a difference. Do it for 20 machines? You'll feel the difference.

    In part 2, I will present a simple approach to automating most of this.

No comments:

Post a Comment