Page 1 of 1

Restart Services using a TM1 Process

Posted: Fri Apr 20, 2012 9:39 pm
by rkpeck
I thought I would post some code that I wrote to get around having to work through our IT group to get our TM1 services restarted. As long as the TM1 service user is a local administrator on the server, you can can use this concept to do anything you can do with a batch file. The code below essentially writes command lines to a batch file and then executes the batch file. I have a ping command to act as a timer to allow the service to stop before I attempt to restart it.

I have the following in my prolog tab of a process:

sLF = char(13) | char(10);
sOutputCharacterSet = 'TM1CS_UTF16ESC';
sBatchFile = '..\Restart.bat';
sBatchCommand = sLF | 'net stop "TM1 Server x64 / salesdata" > nul' | sLF |
'ping 1.1.1.1 -n 1 -w 10000 > nul' | sLF |
'net start "TM1 Server x64 / salesdata" > nul' | sLF;

SetOutputCharacterSet(sbatchfile,sOutputCharacterSet);

textoutput(sBatchFile,sBatchCommand);

ExecuteCommand(sBatchFile,0);

Re: Restart Services using a TM1 Process

Posted: Tue May 22, 2012 10:07 pm
by asutcliffe
rkpeck wrote:I thought I would post some code that I wrote to get around having to work through our IT group to get our TM1 services restarted. As long as the TM1 service user is a local administrator on the server, you can can use this concept to do anything you can do with a batch file. The code below essentially writes command lines to a batch file and then executes the batch file...
Thanks, I've usually managed to talk my way into write access to at least an area of the server's file system so hadn't had to resort to this but it's a cool idea.

Re: the specific scenario of restarting the service, occasionally IT will have already written a script that wraps the net stop/start in other stuff they want to do (like disabling alert monitoring). So running that from TI can help you fly below the radar. ;)
rkpeck wrote:I have a ping command to act as a timer to allow the service to stop before I attempt to restart it.
Note, couldn't you just use the sleep function or am I missing something?

Re: Restart Services using a TM1 Process

Posted: Tue Dec 04, 2012 9:35 am
by iansdigby
It makes me chuckle but also feel good, that I am not the only one who has to dance around the chinese walls.

Re: Restart Services using a TM1 Process

Posted: Tue Dec 18, 2012 9:11 am
by TJMurphy
I recognise the problems but it doesn't make me chuckle. If the server becomes unresponsive this approach doesn't work and it's back to the (Un)help desk in our organisation to get someone to forcibly restart the services. And it seems nigh on impossible for the help desk drone to find the right person to do this :x

Re: Restart Services using a TM1 Process

Posted: Wed Dec 19, 2012 6:25 am
by !TM1Rules
This is a really cool idea and I've tried it on my Test environment, however the process works only the first time I run it.. after that it the process completes successfully because it doesn't appear to be executing the batch file?

I am running a registered TM1 Server (i.e. appears in Services.msc). In Services.msc the TM1 Server has been set to 'Automatic' in the General tab and I have set all three failure options in the Recovery tab to 'Restart the Service'.

My laptop is running TM1 10.1.1 and Windows 7.

Also, does the process need to include a SaveDataAll() at the start of the prolog?


Thanks,
!TM1Rules

Re: Restart Services using a TM1 Process

Posted: Mon Jan 28, 2013 11:50 pm
by !TM1Rules
Hi,

For anyone interested.. Finally got this process to work by adding an ExecuteProcess('SaveDataAll'); at the end of the prolog and moving the ExecuteCommand('batchfile',0); to the Epilog.

Note: The TM1 server in Windows Services will need to be set to Automatic restart.

Thanks again to rkpeck for submitting the original process!


Cheers,
!TM1Rules

Re: Restart Services using a TM1 Process

Posted: Thu Feb 28, 2013 11:24 am
by iansdigby
So many people have this Chinese wall problem with IT over the restarting of services. In our company this existed for a while but pragmatism won the day. When IT found the constant flow of requests for server re-starts intolerable, our finance systems manager was given permissions on the server. It helped that Finance purchased a dedicated server for TM1.

This seems like a very common problem. Could we share best practice on the forum here?

Re: Restart Services using a TM1 Process

Posted: Thu Feb 28, 2013 1:07 pm
by lotsaram
If IT walls and segregation of duties are an issue then I think the "best practice" is already covered here which is to have TI process(es) to perform various "restricted admin functions" like stopping and restarting a service, preforming backup of data directory, cleansing log files, reboot of server itself, etc., etc.

Of course "best practice" is a subjective term as the IT bureaucrats that decided that segregation of duties was a good idea and sooo essential are also unlikely to think that ways to burrow under or go around the wall are such a great idea.

Re: Restart Services using a TM1 Process

Posted: Thu Feb 28, 2013 1:58 pm
by jim wood
Very useful thank you.

Re: Restart Services using a TM1 Process

Posted: Fri Jun 14, 2013 4:35 am
by RJ!
What Code are you putting in your batch files to restart the server?

I've found this vbScript which others on Google have managed to get to work (not necessarily for TM1):

Code: Select all

'Stop Service
strServiceName = "TM1_Dev"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
    objService.StopService()
Next

Wscript.sleep 6000

'Start Service
strServiceName = "TM1_Dev"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
    objService.StartService()
Next
Thanks,

RJ