Automating Starting Services in Apache NiFi and Applying Parameters
Published: 2021-01-26 19:39:40

---
title: Automating Starting Services in Apache NiFi and Applying Parameters
published: true
date: 2021-01-26 14:15:00 UTC
tags: 
canonical_url: 
---

## **Automating Starting Services in Apache NiFi and Applying Parameters**

Automate all the things!   You can call these commands interactively or script all of them with awesome devops tools.  Andre and Dan can tell you more about that.

**Enable All NiFi Services on the Canvas**

By running this three times, I get any stubborn ones or ones that needed something previously running.   This could be put into a loop and check the status before trying again.

```
nifi pg-list
nifi pg-status
nifi pg-get-services
```

 The NiFi CLI has interactive help available and also some good documentation:

[https://nifi.apache.org/docs/nifi-docs/html/toolkit-guide.html#nifi\_CLI](https://nifi.apache.org/docs/nifi-docs/html/toolkit-guide.html#nifi_CLI)

/opt/demo/nifi-toolkit-1.12.1/bin/cli.sh nifi **pg-enable-services**   -u http://edge2ai-1.dim.local:8080 --processGroupId root  

/opt/demo/nifi-toolkit-1.12.1/bin/cli.sh nifi pg-enable-services  -u http://edge2ai-1.dim.local:8080 --processGroupId root  

/opt/demo/nifi-toolkit-1.12.1/bin/cli.sh nifi pg-enable-services  -u http://edge2ai-1.dim.local:8080 --processGroupId root  

We could then start a process group if we wanted:

nifi pg-start -u http://edge2ai-1.dim.local:8080 -pgid 2c1860b3-7f21-36f4-a0b8-b415c652fc62  

**List all process groups**

/opt/demo/nifi-toolkit-1.12.1/bin/cli.sh nifi pg-list -u http://edge2ai-1.dim.local:8080   

**List Parameters**

/opt/demo/nifi-toolkit-1.12.1/bin/cli.sh nifi list-param-contexts -u http://edge2ai-1.dim.local:8080 -verbose  

Set parameters to set parameter context for a process group, you can loop to do all.

- pgid => parameter group id
- pcid => parameter context id

I need to put this in a shell or python script:

/opt/demo/nifi-toolkit-1.12.1/bin/cli.sh nifi pg-set-param-context -u http://edge2ai-1.dim.local:8080 -verbose -pgid 2c1860b3-7f21-36f4-a0b8-b415c652fc62  -pcid 39f0f296-0177-1000-ffff-ffffdccb6d90

**Example**

[https://github.com/tspannhw/ApacheConAtHome2020/blob/main/scripts/setupnifi.sh](https://github.com/tspannhw/ApacheConAtHome2020/blob/main/scripts/setupnifi.sh)

You could also use the NiFi REST API or Dan's awesome Python API ([https://nipyapi.readthedocs.io/en/latest/)](https://nipyapi.readthedocs.io/en/latest/)).

**References**

- [https://www.datainmotion.dev/2020/09/devops-working-with-parameter-contexts.html](https://dev.to/tspannhw/devops-working-with-parameter-contexts-in-apache-nifi-1-11-4-12pk)
- [https://www.datainmotion.dev/2019/11/nifi-toolkit-cli-for-nifi-110.html](https://dev.to/tspannhw/nifi-toolkit-cli-for-nifi-1-10-213h)
- [https://www.datainmotion.dev/2020/06/no-more-spaghetti-flows.html](https://dev.to/tspannhw/no-more-spaghetti-flows-2emd)
- [https://www.datainmotion.dev/2020/07/report-on-this-apache-nifi-1114-monitor.html](https://dev.to/tspannhw/report-on-this-apache-nifi-1-11-4-monitor-all-the-things-1foe)
- [https://github.com/tspannhw/EverythingApacheNiFi](https://github.com/tspannhw/EverythingApacheNiFi)
- [https://www.datainmotion.dev/2020/12/cloudera-data-platform-using-apache.html](https://dev.to/tspannhw/cloudera-data-platform-using-apache-nifi-rest-api-in-the-public-cloud-2j6e)
- [https://www.datainmotion.dev/2020/03/using-nifi-cli-to-restore-nifi-flows.html](https://dev.to/tspannhw/using-nifi-cli-to-restore-nifi-flows-from-backups-18p9)
- [https://www.datainmotion.dev/2020/10/automating-building-migration-backup.html](https://dev.to/tspannhw/automating-the-building-migration-backup-restore-and-testing-of-streaming-applications-30d8)
- [https://docs.cloudera.com/HDPDocuments/HDF3/HDF-3.5.2/nifi-toolkit/content/nifi\_cli.html](https://docs.cloudera.com/HDPDocuments/HDF3/HDF-3.5.2/nifi-toolkit/content/nifi_cli.html)
- [https://levelup.gitconnected.com/an-overview-of-apache-nifi-and-toolkit-cli-deployments-785978dbce3b](https://dev.to/treyhuffine/an-overview-of-apache-nifi-and-toolkit-cli-deployments-poe-temp-slug-2057133)
- [https://pierrevillard.com/2018/04/09/automate-workflow-deployment-in-apache-nifi-with-the-nifi-registry/](https://pierrevillard.com/2018/04/09/automate-workflow-deployment-in-apache-nifi-with-the-nifi-registry/)
- [https://dzone.com/articles/devops-for-apache-nifi-17-and-more](https://dzone.com/articles/devops-for-apache-nifi-17-and-more)