I don’t know if this is better...
I would use a configuration instead of a file. (Details assume karaf is using 
r7 ca, I don’t know if this is true yet)
Install the configuration from json in the bundle (this is the r7 bit). It 
needs 2 entries, current version and last updated version (initialized to 0).
Have a ds component requiring the configuration, and with a mandatory reference 
to config admin. In the activate method, where the configuration arrives as a 
parameter, compare the current and last updated versions and if they differ do 
your initialization, and then use ca to update the configuration so the 
versions match.

The current version could be hard coded in the class if that is easier than 
updating the json.

David Jencks 
Sent from my iPhone

> On Jun 7, 2018, at 5:48 PM, Leschke, Scott <[email protected]> wrote:
> 
> You mean the logic should only execute if the service is "changed", but not 
> in the case where the service is stopped and restarted?
> 
> -----Original Message-----
> From: Max Spring [mailto:[email protected]] 
> Sent: Thursday, June 07, 2018 7:40 PM
> To: [email protected]
> Subject: execute only at first startup?
> 
> I've got a Karaf-based service.
> Whenever I deploy a new revision of my service, I need to execute some code 
> only at the very first startup.
> I have this first-time functionality available as a Karaf command which I 
> currently run manually each time right after startup after a new deployment.
> I'd like to automate this.
> 
> I'm thinking of using a marker file somewhere to indicate "first startup".
> I'd have a new bundle checking for this file when it starts up. When it 
> detect the file, the bundle executes my business logic initialization and 
> then deletes the marker file.
> 
> Or, is there something better for this scenario?
> 
> -Max
> 

Reply via email to