Restart Services using a TM1 Process

Ideas and tips for enhancing your TM1 application
Post Reply
rkpeck
Posts: 4
Joined: Tue Jan 10, 2012 10:53 pm
OLAP Product: TM1
Version: 9.4.1 and 9.5.2
Excel Version: 2003 2007

Restart Services using a TM1 Process

Post by rkpeck » Fri Apr 20, 2012 9:39 pm

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);

asutcliffe
Regular Participant
Posts: 162
Joined: Tue May 04, 2010 10:49 am
OLAP Product: Cognos TM1
Version: 9.4.1 - 10.1
Excel Version: 2003 and 2007

Re: Restart Services using a TM1 Process

Post by asutcliffe » Tue May 22, 2012 10:07 pm

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?

iansdigby
Community Contributor
Posts: 108
Joined: Thu Feb 26, 2009 8:44 am
OLAP Product: TM1
Version: 9 + 10 + Plan An
Excel Version: All
Location: Isle of Wight, UK

Re: Restart Services using a TM1 Process

Post by iansdigby » Tue Dec 04, 2012 9:35 am

It makes me chuckle but also feel good, that I am not the only one who has to dance around the chinese walls.
"the earth is but one country, and mankind its citizens" - Baha'u'llah

TJMurphy
Posts: 68
Joined: Mon May 12, 2008 12:25 pm
OLAP Product: TM1
Version: PA 2.0.6 Local
Excel Version: Excel 2016

Re: Restart Services using a TM1 Process

Post by TJMurphy » Tue Dec 18, 2012 9:11 am

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

!TM1Rules
Posts: 10
Joined: Thu Dec 06, 2012 3:51 am
OLAP Product: TM1\Cognos Express
Version: All
Excel Version: 2013 + 2016
Location: Sydney, Australia

Re: Restart Services using a TM1 Process

Post by !TM1Rules » Wed Dec 19, 2012 6:25 am

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

!TM1Rules
Posts: 10
Joined: Thu Dec 06, 2012 3:51 am
OLAP Product: TM1\Cognos Express
Version: All
Excel Version: 2013 + 2016
Location: Sydney, Australia

Re: Restart Services using a TM1 Process

Post by !TM1Rules » Mon Jan 28, 2013 11:50 pm

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

iansdigby
Community Contributor
Posts: 108
Joined: Thu Feb 26, 2009 8:44 am
OLAP Product: TM1
Version: 9 + 10 + Plan An
Excel Version: All
Location: Isle of Wight, UK

Re: Restart Services using a TM1 Process

Post by iansdigby » Thu Feb 28, 2013 11:24 am

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?
"the earth is but one country, and mankind its citizens" - Baha'u'llah

lotsaram
MVP
Posts: 3325
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: Restart Services using a TM1 Process

Post by lotsaram » Thu Feb 28, 2013 1:07 pm

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.

User avatar
jim wood
Site Admin
Posts: 3749
Joined: Wed May 14, 2008 1:51 pm
OLAP Product: TM1
Version: TM1 10.2.2
Excel Version: 2007
Location: 1639 Route 10, Suite 107, Parsippany, NJ, USA
Contact:

Re: Restart Services using a TM1 Process

Post by jim wood » Thu Feb 28, 2013 1:58 pm

Very useful thank you.
Struggling through the quagmire of life to reach the other side of who knows where.
Application Consulting Group (ACG) TM1 Consulting
OS: Windows 10 64-bit. TM1 Version: 10.2.2

RJ!
Community Contributor
Posts: 219
Joined: Mon Jul 23, 2012 8:31 am
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2010

Re: Restart Services using a TM1 Process

Post by RJ! » Fri Jun 14, 2013 4:35 am

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

Post Reply