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).
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.
Download the attached zip to your desktop and extract the contents of the zip.
A folder called SAS_ServicesServer_StartStopRestartReboot_v1.x is created which contains the powershell script SAS_ServicesServer_StartStopRestartReboot_v1.x.ps1and two subfolders Configuration_FilesandLogs.
TheConfiguration_Filesfolder contains the csv's with the details of the steps used to start/stop SAS services.
TheLogfolder contains details of actions performed when the script is run.
Verify that you have permission to run Powershell scripts.
At the prompt type >set-executionpolicy -ExecutionPolicy RemoteSigned
Open a powershell prompt >Start>All Programs>Accessories>Windows Powershell>Windows Powershell
At the prompt type >get-executionpolicy
If the response isRestricted: Right-click SAS_ServicesServer_StartStopRestartReboot_v1.x.ps1and chooseRun 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.
Example restart of SAS Services:
Right-clickSAS_ServicesServer_StartStopRestartReboot_v1.x.ps1 and choose Run with Powershell.
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).
Press S to load a Configuration File, and choose a ServiceSteps example.
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.
Check if there are any errors reported and press the any key to continue.
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.
When prompted type RESTART or REBOOT to perform the chosen action. NOTE: The input is case sensitive.
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 ! If you intend to maintain the script further along in the future, perhaps could you even share it from GitHub ?