Initialize InfluxDB user + database in Automation_Custom_Script.sh

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:

#!/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:

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:

/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.

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

/bin/systemctl start influxdb

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:

#!/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"'