Begin forwarded message:
From: Chris Muller <asqueaker@gmail.com> Date: January 20, 2011 10:05:44 PM GMT+01:00 To: The general-purpose Squeak developers list <squeak-dev@lists.squeakfoundation.org> Cc: Pharo Development <Pharo-project@lists.gforge.inria.fr> Subject: Re: [Pharo-project] [squeak-dev] Instruments for headless images Reply-To: Pharo-project@lists.gforge.inria.fr, ma.chris.m@gmail.com
The Ma stack does something similar, although not crippling the system to the same extent.
How do you determine you're running headless? I attached my implementation of #maIsHeadless for determining whether the VM was launched headless. Perhaps we should integrate this functionality into Squeak and Pharo (or a variant without the prefix, of course).
Then, I use MaCommandLineProcessor which is concerned with handling the command-line Squeak was launched with:
Then, I write my .st scripts like:
MaCommandLineProcessor do: [ : arg1 : arg2 : arg3 : etc | "my batch code script..." "args come in as Strings." "... you can have a variable number of args." ]
as well as a uniform error-handler for all scripts, to redirect to stdout and stderr, thusly:
MaCommandLineProcessor class>>#do: aBlock | stdOut stdErr | self ensureStartedUp. stdOut := StandardFileStream stdout. stdErr := StandardFileStream stderr. [ aBlock valueWithAllArguments: self args ] on: Notification , Warning do: [ : noti | stdOut nextPutAll: DateAndTime now asString ; space ; nextPutAll: noti description ; perform: MultiByteFileStream lineEndDefault. noti resume ] on: SyntaxErrorNotification do: [ : err | stdOut nextPutAll: err errorCode ; perform: MultiByteFileStream lineEndDefault. self haltOrQuit ] on: Error do: [ : err | stdErr nextPutAll: 'ERROR: ' ; nextPutAll: DateAndTime now asString ; space ; perform: MultiByteFileStream lineEndDefault ; nextPutAll: err description ; perform: MultiByteFileStream lineEndDefault. err isMaUserError ifFalse: [ stdErr nextPutAll: (err signalerContext longStack copyReplaceAll: Character cr asString with: (String perform: MultiByteFileStream lineEndDefault)) ]. self haltOrQuit ]
#haltOrQuit is where it checks #maIsHeadless to determine whether to halt or quit.
MaCommandLineProcessor is part of "Ma base additions" package, so any of the "Ma" softwares (Magma, Maui, Ma client server, etc.) will have it. But I think it would be useful to put this (or, a variant) directly into a future Squeak.
- Chris
On Thu, Jan 20, 2011 at 2:39 PM, Igor Stasenko <siguctua@gmail.com> wrote:
Hello folks.
I'd like to ask, if there any 'standartized' instruments for headless images (or alike).
I need a simple things: - redirect all ToolSet/UIManager messages to Transcript - redirect Transcript logging to file or stdout
in short, these tools should serve a simple, yet important purpose: - if image runs in headless mode, it should suppress anything which expecting user interaction (like showing warnings with 'continue' button) and either log such messages to file or simply quit image with error message.
Without such tool it is quite difficult to monitor, what happens with your headless image.. unless you have RFB installed.. but that is different and unrelated story.
I did a prototype once for Hydra (you can check it at SqS/HydraVM/HydraVM.mcz package) there are two subclasses: - MorphicUIManager subclass: #HydraUIManager - StandardToolSet subclass: #HydraDebugToolSet
and - WriteStream subclass: #HydraTranscript
which can be installed as a Transcript.
And in order to prepare image to run in headless mode, i issued: ToolSet unregister: StandardToolSet. ToolSet register: HydraDebugToolSet. UIManager default: HydraUIManager new.
Also, HydraTranscript startUp does something like:
TranscriptStream newTranscript: (self basicNew initialize on: (String new: 1000))
With that i could run the image in headless mode, knowing that in case of error or warning etc, all will be redirected to transcript, moreover i even stopped the UI process, so it never run on headless images.
I wonder if there are other work, which can offer similar, and is there any way to detect that image are running in headless mode?
-- Best regards, Igor Stasenko AKA sig.