Initialize InfluxDB user + database in Automation_Custom_Script.sh Topic is solved

Having issues with your DietPi installation or found a bug? Post it here.
Post Reply
bennoheld
Posts: 8
Joined: Thu May 06, 2021 4:49 pm

Initialize InfluxDB user + database in Automation_Custom_Script.sh

Post by bennoheld »

I am trying to install Dietpi on my Raspberry 4 non-interactively with the parameter AUTO_SETUP_AUTOMATED=1. Thereby I install InfluxDB using the parameter AUTO_SETUP_INSTALL_SOFTWARE_ID=74 at the same time. The automatic setup and installation of Dietpi including InfluxDB works without problems.

But now I want to create an admin user and an initial database for Influx right at the end of the installation using the /boot/Automation_Custom_Script.sh script. For this I have modified /boot/Automation_Custom_Script.sh as follows:

Code: Select all

#!/bin/bash
# Create InfluxDB User + Password and DB
sleep 5

influx -execute "CREATE USER admin WITH PASSWORD 't0pSecret!' WITH ALL PRIVILEGES"
influx -execute $'CREATE DATABASE "sensor_database"'
Unfortunately, neither the user nor the database are created after the automated installation is complete. In the logs I get the following errors:

Code: Select all

Failed to connect to http://localhost:8086: Get http://localhost:8086/ping: dial tcp [::1]:8086: connect: connection refused
Please check your connection settings and ensure 'influxd' is running.
Failed to connect to http://localhost:8086: Get http://localhost:8086/ping: dial tcp [::1]:8086: connect: connection refused
Please check your connection settings and ensure 'influxd' is running.
It seems that the influxd service is not yet started at the time /boot/Automation_Custom_Script.sh is executed. I also don't seem to have access to the dietpi-services command in the script, which I could use to start Influx:

Code: Select all

/root/AUTO_CustomScript.sh: line 11: dietpi-services: command not found
Now the question is if and how it is possible that I can create a user and a database automatically after installing Dietpi and the InfluxDB service non-interactively.
User avatar
Joulinar
Posts: 5149
Joined: Sat Nov 16, 2019 12:49 am

Re: Initialize InfluxDB user + database in Automation_Custom_Script.sh

Post by Joulinar »

Hi,

if you like to call a command out of the script, you should use the full file path like /boot/dietpi/dietpi-services

Maybe you would need to start InfluxDB before trying to create the database

Code: Select all

/bin/systemctl start influxdb
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
bennoheld
Posts: 8
Joined: Thu May 06, 2021 4:49 pm

Re: Initialize InfluxDB user + database in Automation_Custom_Script.sh

Post by bennoheld »

thank you,
by using the absolute path for the dietpi-services I was able to start the influxdb service in the Automation_Custom_Script.sh file and create a database including users!

Here is the fixed version of the code:

Code: Select all

#!/bin/bash
# Start InfluxDB Service and wait 10 seconds
/boot/dietpi/dietpi-services start influxdb

sleep 10

# Create InfluxDB User + Password and DB
influx -execute "CREATE USER admin WITH PASSWORD 't0pSecret!' WITH ALL PRIVILEGES"
influx -execute $'CREATE DATABASE "sensor_database"'
Post Reply