Lisp HUG Maillist Archive

LWW and Delivering a NTSERVICE

Has anyone successfully made a LWW deliverable that runs as a NT Service?

I have ported Franz's ntservice.cl to LW but have run into a a few snags.
First I have to deliver the executable with :multiprocessing nil, if not
the StartServiceCtrlDispatcher fails because of stack problems.  I think
it is because a multiprocessing deliverable does not run the "main" delivery
entry point on the main stack.  If I deliver with :multiprocessing nil than
when I try to (mp:initialize-multiprocessing) it drops my main entry 
function
into the top-level-repl (ugh).  If I forgo multiprocessing I can get most
everything to work but the service-control-handler fails because (I assume)
it is called from another service manager thread into the LW image which 
does
not have multiprocessing enabled.

Any ideas?  This is a long and involved problem which needs a lot moving
parts to test and debug.

Files attached.

Wade

Re: LWW and Delivering a NTSERVICE

On Sun, 23 Oct 2005 13:49:56 -0600, Wade Humeniuk <whumeniu@telus.net> wrote:

> Has anyone successfully made a LWW deliverable that runs as a NT
> Service?

I think Nick Levine once has.  You can check the source for his
"FastIndex" service.  The relevants parts would be here, I guess:

  <http://www.fast-index.com/distrib/fast-index/admin/install-as-service.lisp>
  <http://www.fast-index.com/distrib/fast-index/C/>

Cheers,
Edi.


Re: LWW and Delivering a NTSERVICE


--- Wade Humeniuk <whumeniu@telus.net> wrote:

> Has anyone successfully made a LWW deliverable that runs as a NT Service?
> 
> I have ported Franz's ntservice.cl to LW but have run into a a few snags.
> First I have to deliver the executable with :multiprocessing nil, if not
> the StartServiceCtrlDispatcher fails because of stack problems.  I think
> it is because a multiprocessing deliverable does not run the "main"
> delivery
> entry point on the main stack.  If I deliver with :multiprocessing nil than
> when I try to (mp:initialize-multiprocessing) it drops my main entry 
> function
> into the top-level-repl (ugh).  If I forgo multiprocessing I can get most
> everything to work but the service-control-handler fails because (I assume)
> it is called from another service manager thread into the LW image which 
> does
> not have multiprocessing enabled.

What do you mean by the service-control-handler failing? It seems to work OK
for me (XP Pro SP2). I get the sleep... sleep... messages from the loop in
'real-main.  Also, I can get multiprocessing working like this:

(defparameter *so* nil)

(defun main ()
  (let ((args system:*line-arguments-list*))
    (format t "args are ~S~%" args)
    (let ((exepath (pop args)))
      (if (member "/install" args :test #'equalp)
          (progn
            (add-service exepath)
            (return-from main)))
      (if (member "/remove" args :test #'equalp)
          (progn
            (remove-service)
            (return-from main)))
      (setq *so* *standard-output*)
      (ntservice:start-service 'idle-main :init 'init)
      t)))

(defun init (args) 
  (format t "Start parameters: ~S~%" args)
  t)

(defun real-main ()
  (loop
    (format *so* "real-main sleeping...~%")
    (sleep 5)))

(defun idle-main ()
  (push '("NT Service Process" nil real-main) mp:*initial-processes*)
  (mp:initialize-multiprocessing)
  (loop
   (format *so* "idle-main sleeping...~%")
   (sleep 5)))

I never see the idle-main sleeping... message. 

There still is a bug. In your original version, when I stop the service,
there is an exception. The console window goes away quickly but I do see "no
exception handler".  In my version, with multiprocessing, the interesting
behavior below happens when I stop the service. I have to kill the console
window manually.

args are ("c:\\lisp\\projects\\ntservice\\testapp.exe" "arg1" "arg2" "arg3")
ARGC 1 ARGV #<Pointer to type :POINTER = #x00146B18>
ARGS: ("MyService")
Start parameters: NIL
real-main sleeping...
real-main sleeping...
real-main sleeping...
Failed to find stack-no 000000ac stack 0012f8c4
Stack dump
0012f8c0  0012f8d4 20944291 00000000 00000010
0012f8d0  000000ac 0012f8ec 2000c423 210bb7f4
0012f8e0  0012f900 00147a50 0012f988 0012f95c
0012f8f0  77deb6ca 77deb6ca 77deb6ca 00000001
0012f900  00000000 00000000 0012fc90 20015ed2
0012f910  20015ed2 00000001 77deb479 00146b10
0012f920  00650070 00000000 00147a50 00000ec4
0012f930  00000000 00000000 0012f99c 00000000
0012f940  00000000 0012f900 00350034 0012fbac
0012f950  77df5655 77deb390 00000000 0012fbbc
0012f960  77deb568 00000050 0012f988 00000216
0012f970  00000000 2025c3ac 0012fc90 00000000
0012f980  7c910895 00000050 0000002c 00000001
0012f990  00000000 00000014 00000000 0079004d
0012f9a0  00650053 00760072 00630069 00000065
0012f9b0  00000000 0012f9c4 00000000 7c9105c8
real-main sleeping...
real-main sleeping...
real-main sleeping...
real-main sleeping...


Jeff


		
__________________________________ 
Start your day with Yahoo! - Make it your home page! 
http://www.yahoo.com/r/hs


Re: LWW and Delivering a NTSERVICE

Jeff Caldwell wrote:

>--- Wade Humeniuk <whumeniu@telus.net> wrote:
>
>  
>
>>Has anyone successfully made a LWW deliverable that runs as a NT Service?
>>
>>I have ported Franz's ntservice.cl to LW but have run into a a few snags.
>>First I have to deliver the executable with :multiprocessing nil, if not
>>the StartServiceCtrlDispatcher fails because of stack problems.  I think
>>it is because a multiprocessing deliverable does not run the "main"
>>delivery
>>entry point on the main stack.  If I deliver with :multiprocessing nil than
>>when I try to (mp:initialize-multiprocessing) it drops my main entry 
>>function
>>into the top-level-repl (ugh).  If I forgo multiprocessing I can get most
>>everything to work but the service-control-handler fails because (I assume)
>>it is called from another service manager thread into the LW image which 
>>does
>>not have multiprocessing enabled.
>>    
>>
>
>What do you mean by the service-control-handler failing? It seems to work OK
>for me (XP Pro SP2). I get the sleep... sleep... messages from the loop in
>'real-main.  Also, I can get multiprocessing working like this:
>  
>

You encountered the problem I am talking about below.  It happens when 
the service is stopped
and the service-control-handler is invoked as a result.

>(defparameter *so* nil)
>
>(defun main ()
>  (let ((args system:*line-arguments-list*))
>    (format t "args are ~S~%" args)
>    (let ((exepath (pop args)))
>      (if (member "/install" args :test #'equalp)
>          (progn
>            (add-service exepath)
>            (return-from main)))
>      (if (member "/remove" args :test #'equalp)
>          (progn
>            (remove-service)
>            (return-from main)))
>      (setq *so* *standard-output*)
>      (ntservice:start-service 'idle-main :init 'init)
>      t)))
>
>(defun init (args) 
>  (format t "Start parameters: ~S~%" args)
>  t)
>
>(defun real-main ()
>  (loop
>    (format *so* "real-main sleeping...~%")
>    (sleep 5)))
>
>(defun idle-main ()
>  (push '("NT Service Process" nil real-main) mp:*initial-processes*)
>  (mp:initialize-multiprocessing)
>  (loop
>   (format *so* "idle-main sleeping...~%")
>   (sleep 5)))
>
>I never see the idle-main sleeping... message. 
>  
>

Yes, this is the case.  The (mp:initialize-multiprocessing) call seems 
to create a repl loop
and the subsequent loop does not work.  Your idle-main code gives me 
some ideas
to implement my actual service, thank-you, but I am going to have to 
clear up the
stop problems (and also any other service indications).

>There still is a bug. In your original version, when I stop the service,
>there is an exception. The console window goes away quickly but I do see "no
>exception handler".  In my version, with multiprocessing, the interesting
>behavior below happens when I stop the service. I have to kill the console
>window manually.
>  
>

Yes the problem happens when I stop the service, I get a slightly 
different message. Yes the problems
all seem to revolve multi-processing issues.


>args are ("c:\\lisp\\projects\\ntservice\\testapp.exe" "arg1" "arg2" "arg3")
>ARGC 1 ARGV #<Pointer to type :POINTER = #x00146B18>
>ARGS: ("MyService")
>Start parameters: NIL
>real-main sleeping...
>real-main sleeping...
>real-main sleeping...
>Failed to find stack-no 000000ac stack 0012f8c4
>Stack dump
>0012f8c0  0012f8d4 20944291 00000000 00000010
>0012f8d0  000000ac 0012f8ec 2000c423 210bb7f4
>0012f8e0  0012f900 00147a50 0012f988 0012f95c
>0012f8f0  77deb6ca 77deb6ca 77deb6ca 00000001
>0012f900  00000000 00000000 0012fc90 20015ed2
>0012f910  20015ed2 00000001 77deb479 00146b10
>0012f920  00650070 00000000 00147a50 00000ec4
>0012f930  00000000 00000000 0012f99c 00000000
>0012f940  00000000 0012f900 00350034 0012fbac
>0012f950  77df5655 77deb390 00000000 0012fbbc
>0012f960  77deb568 00000050 0012f988 00000216
>0012f970  00000000 2025c3ac 0012fc90 00000000
>0012f980  7c910895 00000050 0000002c 00000001
>0012f990  00000000 00000014 00000000 0079004d
>0012f9a0  00650053 00760072 00630069 00000065
>0012f9b0  00000000 0012f9c4 00000000 7c9105c8
>real-main sleeping...
>real-main sleeping...
>real-main sleeping...
>real-main sleeping...
>
>
>  
>

This stack problem also shows up when I deliver the app with 
:multiprocessing t

Thanks for giving it a try, perhaps Lispworks can shed some more light
on the problem.

Wade



Updated at: 2020-12-10 08:50 UTC