OpenGrok

To run the OpenGrok code search engine using Unit:

  1. Install Unit with a Java 11+ language module.

  2. Follow the official OpenGrok installation guide. Here, we’ll place the files at /path/to/app/:

    mkdir -p /path/to/app/{src,data,dist,etc,log}  # Path to the application directory; use a real path in your configuration
    
    tar -C /path/to/app/dist --strip-components=1 -xzf opengrok-X.Y.Z.tar.gz  # Path to the application directory; use a real path in your configuration | Specific OpenGrok version
    

    Our servlet container is Unit so we can repackage the source.war file to an arbitrary directory at Step 2:

    opengrok-deploy -c /path/to/app/etc/configuration.xml \
          /path/to/app/dist/lib/source.war /path/to/app/  # Path to the application directory; use a real path in your configuration
    

    The resulting pathname is /path/to/app/source.war.

  3. Change ownership:

    Run the following command (as root) so Unit can access the application directory (If the application uses several directories, run the command for each one):

    # chown -R unit:unit /path/to/app/  # User and group that Unit's router runs as by default
       
    The unit:unit user-group pair is available only with official packages , Docker images, and some third-party repos. Otherwise, account names may differ; run the ps aux | grep unitd command to be sure.

    For further details, including permissions, see the security checklist.

  4. Next, prepare the OpenGrok configuration for Unit:

    {
       "listeners": {
          "*:80": {
                "pass": "applications/opengrok"
          }
       },
    
       "applications": {
          "opengrok": {
                "type": "java",
                "webapp": "/path/to/app/source.war",
                "_comment_webapp": "Path to the application directory; use a real path in your configuration | Repackaged in Step 2",
                "options": [
                   "-Djava.awt.headless=true"
                ]
          }
       }
    }
  5. Upload the updated configuration.

    Assuming the JSON above was added to config.json. Run the following command as root:

    # curl -X PUT --data-binary @config.json --unix-socket \
          /path/to/control.unit.sock \  # Path to Unit's control socket in your installation
          http://localhost/config/      # Path to the config section in Unit's control API
       
    The control socket path may vary; run unitd -h or see Startup and shutdown for details.

    After a successful update, OpenGrok should be available on the listener’s IP address and port:

    OpenGrok on Unit - Search Screen


Last modified February 6, 2025