BookmarkSubscribeRSS Feed
niallc
Calcite | Level 5

To all,

 

I'm sharing a powershell script that may be useful to those having to admin a SAS installation on Windows. 

 

This script was created to automate the stop/start/restart/reboot of all, or chosen, SAS Services and Servers. Part of the idea behind the script was that it could be used by admins and non-admins alike. So a GUI based Menu that verifies config before running and which can't be accidentally run (for the non-admins), and the ability to run from the command prompt (for the admins). 

 

The script uses a CSV file to specifiy the correct order to start/stop services (and optionally another CSV to archive/delete log files etc.) on the SAS servers. The script can also check the server.log and wait for the webservices to start before continuing. 

 

EDIT> I was a bit pressed for time when I submitted the original post, so I'll add some additional details as to why this script may be of use and what it can do:

 

  • If your SAS environment is distributed (i.e. you have separate Compute/Web/Metadata servers etc and not just one server) it will connect remotely to the servers and perform the requested tasks. Obviously, this works best when using the script on a server other than the SAS servers.
  • It can perform an automated Start/Stop or Restart (ie Stop then Start) of SAS Services in the order you specify.
  • You can choose to Start/Stop a SAS Service using powershell or by using a local batch file e.g. the SAS bat files like MetadataServer.bat or ConnectSpawner.bat etc.
  • It verifies that the Service has Started/Stopped before continuing. In addition, for SAS Services that will report Started but which actually have not finished starting, it can search a specified log file and wait for a specified text string before continuing. For example, this is used to verify that the WebAppServer service has actually finished loading by waiting for the text string "Server startup in" to appear in the server.log file. Where I work this typically takes between 3 and 5 minutes, so no more sitting around and checking a log file...
  • You can specify a delay/pause between Starting/Stopping services.
  • You can choose to perform a fully automated graceful reboot of your SAS Servers ie Stop SAS Services in order > Reboot Servers > Wait for Servers to finish restarting > Start SAS Services in order. This requires that the script is run from a Server other than the SAS servers.
  • Clearing down log files etc is Optional, and if set is only performed after the SAS Services have stopped. So clearing down log files etc is performed only with the Stop, Restart or Reboot options.
  • When clearing down log files etc you can choose to zip them and copy them to a separate file share (7zip is required for this).

 

The SAS Startup order in the examples etc was gleaned from various sources but mostly from the official http://documentation.sas.com/?docsetId=bisag&docsetTarget=p0d9d5nzmd8i4yn1usv2l22vpa7t.htm&docsetVer... .

If you are going to use the Folder Archiving and deleting/cleanup (optional), make sure that your paths are correct, or you may end up deleting more than you bargained for. You can perform recursive deletes of entire directory structures. So. Be. Careful.

 

NOTE: This script was used on a SAS 9.4 M2 installation. 

 

  1. Download the attached zip to your desktop and extract the contents of the zip.
  2. A folder called SAS_ServicesServer_StartStopRestartReboot_v1.x is created which contains the powershell script SAS_ServicesServer_StartStopRestartReboot_v1.x.ps1 and two subfolders Configuration_Files and Logs.
    • The Configuration_Files folder contains the csv's with the details of the steps used to start/stop SAS services. 
    • The Log folder contains details of actions performed when the script is run.
  3. Verify that you have permission to run Powershell scripts. 
    1. At the prompt type > set-executionpolicy -ExecutionPolicy RemoteSigned
    2. Open a powershell prompt > Start > All Programs > Accessories > Windows Powershell > Windows Powershell
    3. At the prompt type > get-executionpolicy
    4.  If the response is Restricted : Right-click SAS_ServicesServer_StartStopRestartReboot_v1.x.ps1 and choose Run with Powershell.

NOTE: At a minimum you must load a SAS Services Start Order config csv. Example files are in the Configuration_Files folder. 

NOTE: You cannot run any Actions until the Check option is run.

NOTE: To reduce the risk of accidentally running the wrong action, an additional screen prompts a written confirmation of the action before continuing.    

 

SASSS_01.jpg

 

Example restart of SAS Services:

 

  1. Right-click SAS_ServicesServer_StartStopRestartReboot_v1.x.ps1 and choose Run with Powershell.SASSS_00.jpgSASSS_02.jpg
  2. If you are not running the script as a user that has Admin rights on the SAS Servers: Press R to Run the script As a Different User. Verify that the script is now running as the different user (top right 'Script RUN AS User Account: xxxxxx). 
  3.  Press S to load a Configuration File, and choose a ServiceSteps example.
  4.  Press C to check that the configuration is correct. This will verify that you have the rights to perform these actions on the remote Servers, and that the specified Services and files exist on the specified servers. NOTE: It will not perform any tasks, just check configuration.SASSS_06.jpg
  5. Check if there are any errors reported and press the any key to continue.SASSS_07.jpg
  6. Press 3 to Restart the SAS Services OR Press 4 to perform a full graceful (i.e. the SAS Services are first stopped) Reboot of the SAS Servers.
  7. When prompted type RESTART or REBOOT to perform the chosen action. NOTE: The input is case sensitive. SASSS_08.jpg

2 REPLIES 2
ronan
Lapis Lazuli | Level 10

I cannot test the script but this looks very useful, especially since SAS_lsm does not cover Windows. Thanks a lot for sharing with the community ! Smiley Happy If you intend to maintain the script further along in the future, perhaps could you even share it from GitHub ?

 

niallc
Calcite | Level 5

thanks, I'm moving to a new job soon that doesn't involve SAS, so I won't be in a position to support the script. But if someone finds it useful and wants to extend/improve it... that's fine with me.

 

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

Get Started with SAS Information Catalog in SAS Viya

SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 2614 views
  • 6 likes
  • 2 in conversation