Old 21st September 2010, 18:21   #1
preotul
Junior Member
 
Join Date: Sep 2010
Posts: 2
Question Service and delayed loop

Hello ,

I'm quite a newbie to NSIS and I am trying to check whether the PostgreSQL service is running, in which case I would go ahead and execute a certain piece of code, otherwise I would wait for 1 minute for the process to start, checking every second. Basically it would be a while loop, exit condition being either end of time either the desired process status.

code:

$5 = 0
$6 = 0

PGServiceCheck:

${If} $5 == 60
Goto PGServiceEnd
${EndIf}

SimpleSC::GetServiceStatus "postgresql-8.4"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Pop $1 ; return the status of the service (See "service_status" in the parameters)

${If} $0 == 0
$6 = 1
${EndIf}

${If} $6 == 1
Goto PGServiceEnd
${EndIf}

IntOp $5 $5 + 1
Sleep 1000

PGServiceEnd:




I would really like to know if this is the/a correct approach.

Thanks in advance,

Brad

Last edited by preotul; 21st September 2010 at 18:23. Reason: bad grammar
preotul is offline   Reply With Quote
Old 21st September 2010, 18:27   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
New to programming in general?
code:
${For} $R0 1 60
SimpleSC::GetServiceStatus "postgresql-8.4"
Pop $R1
Pop $R2
${If} $R1 == 0
${AndIf} $R2 == 4 ; SERVICE_RUNNING
${Break}
${EndIf}
Sleep 1000
${Next}

You haven't thought about an action to take if the service is never started. You could have this after the loop:
code:
${If} $R0 == 61
# handle error
#
Abort
${EndIf}

Stu

Last edited by Afrow UK; 21st September 2010 at 18:46. Reason: Added SERVICE_RUNNING check
Afrow UK is offline   Reply With Quote
Old 22nd September 2010, 05:39   #3
preotul
Junior Member
 
Join Date: Sep 2010
Posts: 2
Hey! big thanks! ... Unfortunately I'm not new to programming, just very tired to look up all the statements, instructions and functions I needed when I wrote the installer.

This was everything I knew of the GetServiceStatus
code:

; Get the current status of a service
SimpleSC::GetServiceStatus "MyService"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Pop $1 ; return the status of the service (See "service_status" in the parameters)


so for some reason I assumed that it returns 1 in $0 when status is running and anything else if it fails, popping the info in $1. Basically I get a 0 in $0 when I get a status from the service and it pops a 4 in $1 if the status is running.
Also, now I know how the for statement looks like , and of course a for or a while is the best choice for this.

In case I get out after 60 seconds I wont execute the code that follows, but that I didn't include that in the present code. As a matter of fact I forgot some things in the code I wrote (the jump backwards) so I can see why you assumed I was new to programming ^^


Anyway, big thanks
preotul is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
if-else, increment, loop, service, sleep

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump