Wednesday, December 21, 2011

How to manage bundle using curl command

Get bundle Symbolic Name:

(You can use jsawk tool to parse this data as well https://github.com/micha/jsawk)

curl -u admin:admin http://localhost:4502/system/console/bundles</bundlenumber>.json

Start
curl -u admin:admin -F action=start http://localhost:4502/system/console/bundles/$bundle symbolic name

Stop
curl -u admin:admin -F action=stop http://localhost:4502/system/console/bundles/$bundle symbolic name

Update
curl -u admin:admin -F action=update http://localhost:4502/system/console/bundles/$bundle symbolic name

Refresh
curl -u admin:admin -F action=refresh http://localhost:4502/system/console/bundles/$bundle symbolic name

Unistall
curl -u admin:admin -F action=uninstall http://localhost:4502/system/console/bundles/$bundle symbolic name
Or
curl -XDELETE -u user:pass http://.../apps/${app}/install/${bundle-file-name}

Install
curl -X POST -v -F action=install -F bundlestart=start -F bundlestartlevel=20 -F bundlefile=/path/to/jar/file.jar http://admin:admin@localhost:4502/system/console/bundles
OR
curl -u admin:admin -F action=install -F bundlestartlevel=20 -F bundlefile=@"/path/of/jar" http://localhost:9002/system/console/bundles


Here is some example with jswak (Here is how you can install jswak on MAC)
How to check if a CQ bundle is Active

curl -u admin:admin http://localhost:4502/system/console/bundles/<bundle number or symbolic name>.json | jsawk -n 'if(this.data[0].state=="Active")' | echo "Bundle is Active"


How to check if All bundles are active

curl -u admin:admin http://localhost:4502/system/console/bundles/<bundle number or symbolic name>.json | jsawk -n 'if(this.s[3] + this.s[4] > 0)' | echo "There is some problem not all bundle is active"

Find all Bundle having some problems

curl -u admin:admin http://localhost:4502/system/console/bundles.json | jsawk -n 'for(var i=0;i<this.data.length;i++) {if(this.data[i].state!="Active" && this.data[i].state!="Fragment") out("Bundle " + this.data[i].symbolicName+"  is "+ this.data[i].state)}'


 

15 comments:

  1. Hi Yogesh,

    I am using install command -

    C:\Users\ssha49\Desktop\infra scripts>curl -X POST -v -F "action=install" -F "bundlestart=start" -F "bundlestartlevel=20" -F "bundlefile=C:\Users\ssha49\Desktop\gsamjars\search-1.1.jar" http://admin:admin@localhost:4502/system/console/bundl
    es
    but I am getting error -
    * About to connect() to localhost port 4502 (#0)
    * Trying 127.0.0.1...
    * connected
    * Connected to localhost (127.0.0.1) port 4502 (#0)
    * Server auth using Basic with user 'admin'
    > POST /system/console/bundles HTTP/1.1
    > Authorization: Basic YWRtaW46YWRtaW4=
    > User-Agent: curl/7.28.1
    > Host: localhost:4502
    > Accept: */*
    > Content-Length: 506
    > Expect: 100-continue
    > Content-Type: multipart/form-data; boundary=------------------------
    030db4
    >
    < HTTP/1.1 100 Continue
    < HTTP/1.1 302 Moved Temporarily
    < Connection: Keep-Alive
    < Server: Day-Servlet-Engine/4.1.24
    < Content-Type: text/html
    < Date: Mon, 04 Feb 2013 09:51:22 GMT
    < Transfer-Encoding: chunked
    < Location: /system/console/bundles
    * HTTP error before end of send, stop sending

    This page moved to /system/console/bundles

    * Closing connection #0

    ReplyDelete
    Replies
    1. I just updated CURL command. Can you try now ?

      Delete
    2. Hi Yogesh, I have tried the same curl command to install a jar in AEM but I am also getting the same error as that of Mr. Sujeeth. Can you help me regarding this.

      Delete
    3. Can you please use curl -u admin:PASSWORD -F action=install -F bundlestart=start -F bundlestartlevel=20 -F bundlefile=/path/to/jar/file.jar http://HOST:PORT/system/console/bundles Let me know if that helps. Also what version of CQ are you using ?

      Delete
  2. Excellent post, Yogesh. Is it be possible to refresh bundle configuration with CURL as well?

    ReplyDelete
    Replies
    1. Yes. You can refresh bundle as well. I have command for that listed above. Let me know if that does not work. Note that you need to use bundle symbolic name for that.

      Delete
  3. Hi Yogesh, for bundle, we can just update/ activate/update via package: /apps/${app}/install/${bundle-file-name}
    any implications on doing that?
    sometimes i noticed that the bundle is not being updated. is it because of the version on META-INF? or anything else?

    ReplyDelete
    Replies
    1. Hello Mildred,

      Bundle only get update if new bundle version is either greater than current installed bundle version or it is same as current installed version but have SNAPSHOT in version number.

      For example,

      Current is 1.0.0 and new is 1.0.1 -> update happen
      Current is 1.0.2 and new is 1.0.1 -> update will not happen
      Current is 1.0.2 and new is 1.0.1-SNAPSHOT -> update will not happen
      Current is 1.0.2 and new is 1.0.2-SNAPSHOT -> update will happen
      Current is 1.0.2-SNAPSHOT and new is 1.0.2-SNAPSHOT -> update will happen
      Current is 1.0.2-SNAPSHOT and new is 1.0.1-SNAPSHOT -> update will not happen

      Yogesh

      Delete
  4. Hi Yogesh ,

    Do you know how to create a cq node with Long type ?

    ReplyDelete
    Replies
    1. Hello Madhavan,

      Do you mean create a node with Long property ? For that you can use sling post servlet. Here is example http://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html

      Yogesh

      Delete
  5. Hi Yogesh,

    I tried the command but not sure if it ran successfully or not. I did not receive any response to the command.

    I do not have access to Felix console, so
    - Is there a way to find out if a particular bundle exists or got installed
    - To star the bundles, how to find the bundle symbolic name

    ReplyDelete
    Replies
    1. For bundle symbolic name just query bundles.json and then use any json parser tool to find it.

      Delete
  6. Do we have any cURL command to check the status of the bundle? If so,could you please suggest. Thanks in advance.


    ReplyDelete
    Replies
    1. Hello Swathi,

      You can use curl with jswak to check this. I have added some example for your reference above. Please let me know if that helps.

      Yogesh

      Delete
  7. Wheely | The largest platform to play wheely online games in 2019. We have a number of fun games for kids both boys and girls.http://wheelygames.com/

    ReplyDelete