playbook working, tidying up task order

This commit is contained in:
2025-11-02 23:33:13 -08:00
parent 378b740d93
commit c6d51f2a49
14 changed files with 220 additions and 375 deletions

View File

@ -6,4 +6,8 @@ The data is also stored locally and can be viewed on a web dashboard at port 808
When deployed with Matt-Cloud Jenkins there is a Chromium kiosk option that will allow this web dashboard to be deployed as a local kiosk. When deployed with Matt-Cloud Jenkins there is a Chromium kiosk option that will allow this web dashboard to be deployed as a local kiosk.
The daabase is handled by the python service now.
Instead of using an API key with the python service, I am binding everything to the docker interface to keep it unreachable externally. It's easier and good enough, it's not like this is the nuclear codes or anything.
https://jenkins.matt-cloud.com/job/Projects/job/SSD%20Health%20Checker/ https://jenkins.matt-cloud.com/job/Projects/job/SSD%20Health%20Checker/

View File

@ -15,7 +15,7 @@ autologin_user: "ssd_health"
# php container vars # php container vars
container_name: "ssd_dashboard" container_name: "ssd_dashboard"
container_http_port: "8088" container_http_port: "80"
extra_volumes: "" extra_volumes: ""
# api service vars # api service vars
@ -26,14 +26,21 @@ api_service_exe: "{{ service_folder }}/venv/bin/python -u {{ service_folder }}/a
# kiosk service vars # kiosk service vars
kiosk_service_name: "drive_check" kiosk_service_name: "drive_check"
kiosk_service_exe: "{{ service_folder }}/drive_check.sh" kiosk_service_exe: "{{ service_folder }}/drive_check.sh"
kiosk_service_templates:
- chrome_website: "http://0.0.0.0:{{ container_http_port }}"
service_name: ssd_dashboard
service_description: "SSD Health Web Dashboard"
user_data_dir: ""
extra_service_configs: ""
extra_chrome_configs: ""
# other vars # other vars
service_folder: "/opt/ssd_health" service_folder: "/opt/ssd_health"
db_path: "{{ service_folder }}/drive_records.db" db_path: "{{ service_folder }}/drive_records.db"
hello_there_url: "https://docs.theregion.beer/hello-there.png" hello_there_url: "https://docs.theregion.beer/hello-there.png"
sector_size: "512" sector_size: "512"
install_kiosk: false
sleep_time: "5" sleep_time: "5"
install_kiosk: false
quick_refresh: false quick_refresh: false
service_only: false service_only: false

View File

@ -24,36 +24,34 @@ def init_db():
# this code deletes the db file if 0 bytes # this code deletes the db file if 0 bytes
if os.path.exists(db_path) and os.path.getsize(db_path) == 0: if os.path.exists(db_path) and os.path.getsize(db_path) == 0:
try: try:
os.remove(db_path)
print("Database is 0 bytes, deleting.") print("Database is 0 bytes, deleting.")
os.remove(db_path)
except Exception as e: except Exception as e:
print(f"error during file deletion - 405: {e}") print(f"error during file deletion - 405: {e}")
return jsonify({'error during file deletion': e}), 405 return jsonify({'error during file deletion': e}), 405
try: try:
result = bool(query_db(db_check)) result = bool(query_db(db_check))
print(result)
# Check if any tables were found # Check if any tables were found
if result: if result:
print(result)
print("drive_records exists - 205") print("drive_records exists - 205")
#return jsonify({'drive_records exists - 205': result}), 205
else: else:
print("drive_records does not exist, creating") print("drive_records does not exist, creating")
try: try:
result_init = query_db(create_table_command) result_init = query_db(create_table_command)
print(result_init)
print("Database created - 201") print("Database created - 201")
#return jsonify({'Database created': True, 'Result': result_init}), 201
except sqlite3.Error as e: except sqlite3.Error as e:
print(f"error during table initialization: {e}") print(f"error during table initialization: {e}")
return jsonify({'error during table initialization - 401': e}), 401 return jsonify({'error during table initialization - 401': e}), 401
#return len(result) > 0
except sqlite3.Error as e: except sqlite3.Error as e:
print(f"error during table check: {e}") print(f"error during table check: {e}")
return jsonify({'error during table check - 400': e}), 400 return jsonify({'error during table check - 400': e}), 400
# sqlite query function # sqlite query function with lots of protection
def query_db(sql_query): def query_db(sql_query):
try: try:
# Establish a connection to the SQLite database using a context manager
with sqlite3.connect(db_path) as conn: with sqlite3.connect(db_path) as conn:
cursor = conn.cursor() cursor = conn.cursor()
print("Executing SQL query:", sql_query) print("Executing SQL query:", sql_query)
@ -61,15 +59,8 @@ def query_db(sql_query):
rows = cursor.fetchall() rows = cursor.fetchall()
return rows return rows
except sqlite3.Error as e: except sqlite3.Error as e:
# Handle any potential errors that might occur during database operations
print("An error occurred:", e) print("An error occurred:", e)
return [] return []
#conn = sqlite3.connect(db_path)
#cursor = conn.cursor()
#cursor.execute(sql_query)
#rows = cursor.fetchall()
#conn.close()
#return rows
# Function to return all drive records in database # Function to return all drive records in database
def get_all_drive_records(): def get_all_drive_records():
@ -149,6 +140,6 @@ def test():
if __name__ == '__main__': if __name__ == '__main__':
result=init_db() result=init_db()
print(result) print(result)
app.run(debug=True, host='0.0.0.0', port=5000) app.run(debug=True, host='172.17.0.1', port=5000)

View File

@ -1,197 +0,0 @@
#!/bin/bash
# script for handling adding and updating local drive database
# Function to display usage
usage() {
echo "Usage: $0 [-v] [-x] -d /path/to/drive_records.db [-a 'serial,model,flavor,capacity,TBW,smart' OR -u 'serial,TBW,smart'] "
echo "Options - choose only one of a or u, v and x are optional and not exclusive, and always provide the d"
echo " -d /path/to/drive_records.db Specify path to DB, required"
echo " -a 'serial,model,flavor,capacity,TBW,smart' Add new drive to sqlite db"
echo " -u 'serial,TBW,smart' Update drive data in sqlite db"
echo " -v Output verbose information"
echo " -x Output debug information"
exit 1
}
# init_db subroutine
init_db() {
if [ "$BE_VERBOSE" == "true" ] ; then
echo "initializing database"
fi
# Check if the file does not exist
if [ ! -e "$DB_FILE" ]; then
if [ "$BE_VERBOSE" == "true" ] ; then
echo "No database file, initializing at $DB_FILE"
fi
sqlite3 "$DB_FILE" "$CREATE_TABLE"
chmod 666 $DB_FILE
else
if [ "$BE_VERBOSE" == "true" ] ; then
ls -lah $DB_FILE
echo "Database file exists, checking tables."
fi
DB_PRESENT=$(sqlite3 $DB_FILE .tables | grep drive_records)
if [ -z "$DB_PRESENT" ]; then
sqlite3 "$DB_FILE" "$CREATE_TABLE"
chmod 666 $DB_FILE
fi
fi
}
# Define variables
DB_FILE="drive_records.db"
NEEDS_ARGS=false
INIT_ONLY=false
ADD_DRIVE=false
UPDATE_DRIVE=false
DB_PROVIDED=false
VALID_FLAGS=false
BE_VERBOSE=false
OUTPUT_DEBUG=false
CREATE_TABLE="CREATE TABLE drive_records (
id INTEGER PRIMARY KEY,
serial TEXT NOT NULL,
model TEXT NOT NULL,
flavor TEXT NOT NULL,
capacity TEXT NOT NULL,
TBW TEXT NOT NULL,
smart TEXT NOT NULL
);"
# Parse command line options
while getopts ":d:a:u:vx" opt; do
case ${opt} in
v ) # process option v
echo "Be Verbose"
BE_VERBOSE=true
;;
x ) # process option x
echo "Debug Info Enabled"
OUTPUT_DEBUG=true
;;
d ) # process option d
if [ "$BE_VERBOSE" == "true" ] ; then
echo "database path provided"
fi
DB_PROVIDED=true
DB_FILE=$OPTARG
;;
a ) # process option a
if [ "$BE_VERBOSE" == "true" ] ; then
echo "add new drive"
fi
ADD_DRIVE=true
NEEDS_ARGS=true
VALID_FLAGS=true
DRIVE_DATA=$OPTARG
;;
u ) # process option u
if [ "$BE_VERBOSE" == "true" ] ; then
echo "update existing drive"
fi
UPDATE_DRIVE=true
NEEDS_ARGS=true
VALID_FLAGS=true
DRIVE_DATA=$OPTARG
;;
\? ) usage
;;
esac
done
shift $((OPTIND -1))
# Check if all required options are provided
if [ "$DB_PROVIDED" == "false" ] ; then
if [ "$BE_VERBOSE" == "true" ] ; then
echo "Database Not Provided"
fi
usage
fi
if [ "$VALID_FLAGS" == "false" ] ; then
if [ "$BE_VERBOSE" == "true" ] ; then
echo "Invalid Flags"
fi
usage
fi
if [ "$NEEDS_ARGS" == "true" ] ; then
if [ "$BE_VERBOSE" == "true" ] ; then
echo "NEEDS_ARGS: $NEEDS_ARGS"
fi
if [ -z "$DRIVE_DATA" ] ; then
if [ "$BE_VERBOSE" == "true" ] ; then
echo "Missing Arguments"
fi
usage
fi
fi
# add new drive
if [ "$ADD_DRIVE" == "true" ]; then
if [ "$BE_VERBOSE" == "true" ] ; then
echo "Adding new drive"
fi
if [ "$OUTPUT_DEBUG" == "true" ] ; then
echo "DRIVE_DATA for new drive:"
echo "$DRIVE_DATA"
fi
# Extract the values from the argument string
IFS=',' read -ra data <<< "$DRIVE_DATA"
# Check if we have exactly 6 arguments
if [ ${#data[@]} -ne 6 ]; then
echo "Exactly 6 arguments are required."
exit 1
fi
# Check if the file does not exist, this should never fail
if [ ! -e "$DB_FILE" ]; then
if [ "$BE_VERBOSE" == "true" ] ; then
echo "No database file, exiting"
exit 2
fi
fi
DRIVE_EXISTS=$(curl -s http://0.0.0.0:5000/check?serial_lookup=${data[0]} | jq .serial_number_exists)
if [ "$DRIVE_EXISTS" == "false" ]; then
# Insert the values into the database
echo "http://0.0.0.0:5000/add_drive?serial='${data[0]}'&model='${data[1]}'&flavor='${data[2]}'&capacity='${data[3]}'&TBW='${data[4]}'&smart='${data[5]}'"
curl -s "http://0.0.0.0:5000/add_drive?serial='${data[0]}'&model='${data[1]}'&flavor='${data[2]}'&capacity='${data[3]}'&TBW='${data[4]}'&smart='${data[5]}'"
else
if [ "$BE_VERBOSE" == "true" ] ; then
echo "Drive already exists, skipping"
fi
fi
fi
# update existing drive
if [ "$UPDATE_DRIVE" == "true" ]; then
if [ "$BE_VERBOSE" == "true" ] ; then
echo "Update existing drive"
fi
if [ "$OUTPUT_DEBUG" == "true" ] ; then
echo "DRIVE_DATA for new drive:"
echo "$DRIVE_DATA"
fi
# Extract the values from the argument string
IFS=',' read -ra data <<< "$DRIVE_DATA"
# Check if we have exactly 3 arguments
if [ ${#data[@]} -ne 3 ]; then
echo "Exactly 3 arguments are required."
exit 1
fi
# Check if the file does not exist, this should never fail
if [ ! -e "$DB_FILE" ]; then
if [ "$BE_VERBOSE" == "true" ] ; then
echo "No database file, exiting"
exit 3
fi
fi
DRIVE_EXISTS=$(curl -s http://0.0.0.0:5000/check?serial_lookup=${data[0]} | jq .serial_number_exists)
if [ "$DRIVE_EXISTS" == "true" ]; then
# Update the values in the database
echo "http://0.0.0.0:5000/update_drive?serial='${data[0]}'&TBW='${data[1]}'&smart='${data[2]}"
curl -s "http://0.0.0.0:5000/update_drive?serial='${data[0]}'&TBW='${data[1]}'&smart='${data[2]}"
else
if [ "$BE_VERBOSE" == "true" ] ; then
echo "Drive does not exist, skipping"
fi
fi
fi

View File

@ -13,7 +13,7 @@
state: directory state: directory
mode: '0700' mode: '0700'
- name: autologin - "create {{ autologin_user }} .bashrc" - name: autologin - "create {{ autologin_user }} .bash_aliases"
copy: copy:
#dest: "/home/{{ autologin_user }}/.bash_aliases" #dest: "/home/{{ autologin_user }}/.bash_aliases"
dest: "/home/{{ autologin_user }}/.bash_aliases" dest: "/home/{{ autologin_user }}/.bash_aliases"
@ -39,6 +39,34 @@
when: not quick_refresh | bool when: not quick_refresh | bool
include_tasks: hello_there.yaml include_tasks: hello_there.yaml
- name: autologin - script permission settings
when: not service_only | bool
block:
- name: User setup - update permissions on smartctl 1
shell: "chmod 755 /usr/sbin/smartctl"
- name: autologin - User setup - update permissions on smartctl 2
shell: "chmod u+s /usr/sbin/smartctl"
- name: autologin - User setup - update permissions on fdisk
shell: "chmod u+s /usr/sbin/fdisk"
- name: autologin - User setup - create symlink for smartctl
ignore_errors: yes
shell: "ln /usr/sbin/smartctl /usr/bin/smartctl"
- name: autologin - User setup - create symlink for fdisk
ignore_errors: yes
shell: "ln /usr/sbin/fdisk /usr/bin/fdisk"
- name: autologin - "User setup - allow {{ autologin_user }} to smartctl"
copy:
dest: /etc/sudoers.d/smartctl
content: |
{{ autologin_user }} ALL=(ALL) NOPASSWD: /usr/sbin/smartctl
{{ autologin_user }} ALL=(ALL) NOPASSWD: /usr/sbin/fdisk
- name: autologin - Restart getty@tty1 service - name: autologin - Restart getty@tty1 service
systemd: systemd:
name: getty@tty1.service name: getty@tty1.service

View File

@ -3,9 +3,6 @@
# This part sets up drive history dashboard # This part sets up drive history dashboard
############################################### ###############################################
- name: drive history dashboard web files
block:
- name: drive history dashboard - set docker folder variable - name: drive history dashboard - set docker folder variable
set_fact: set_fact:
service_control_web_folder: "{{ service_folder }}/web" service_control_web_folder: "{{ service_folder }}/web"
@ -27,21 +24,17 @@
owner: root owner: root
group: root group: root
############################################### - name: docker container
# Start service_control_website
###############################################
- name: start drive history dashboard
when: not quick_refresh | bool when: not quick_refresh | bool
block: block:
- name: service_control_website - template config - name: service_control_website - template docker-compose.yaml
template: template:
src: docker-compose-php.yaml src: docker-compose-php.yaml
dest: "{{ service_control_web_folder }}/docker-compose.yaml" dest: "{{ service_control_web_folder }}/docker-compose.yaml"
mode: 0644 mode: 0644
- name: "service_control_website - Start container at 0.0.0.0:{{ container_http_port }}" - name: "service_control_website - Start container at {{ container_http_port }}"
shell: "docker-compose -f {{ service_control_web_folder }}/docker-compose.yaml up -d" shell: "docker-compose -f {{ service_control_web_folder }}/docker-compose.yaml up -d"
register: docker_output register: docker_output
- debug: | - debug: |

View File

@ -1,15 +1,5 @@
--- ---
- name: Drive Index - Install Packages
when: not quick_refresh | bool
apt:
name:
- "{{ ssd_health_packages_item }}"
state: present
loop: "{{ ssd_health_packages }}"
loop_control:
loop_var: ssd_health_packages_item
- name: Drive Index - file and folder handler - name: Drive Index - file and folder handler
block: block:
@ -90,46 +80,4 @@
state: started state: started
enabled: yes enabled: yes
- name: Drive Index - kiosk mode handler
when: install_kiosk | bool or service_only | bool
block:
- name: Drive Index - set sleep_time to 1
set_fact:
sleep_time: "1"
- name: "Drive Index - template drive_check.sh again"
template:
src: drive_check.sh
dest: "{{ service_folder }}/drive_check.sh"
mode: 0755
owner: "{{ autologin_user }}"
group: "{{ autologin_user }}"
- name: "Drive Index - {{ kiosk_service_name }}.service - stop service if running"
ignore_errors: yes
systemd:
name: "{{ kiosk_service_name }}.service"
state: stopped
- name: "Drive Index - template {{ kiosk_service_name }}.service"
vars:
service_name: "{{ kiosk_service_name }}"
service_working_folder: "{{ service_folder }}"
service_exe: "{{ kiosk_service_exe }}"
template:
src: "service_template.service"
dest: "/etc/systemd/system/{{ kiosk_service_name }}.service"
mode: 0644
- name: "Drive Index - {{ kiosk_service_name }} - daemon reload"
systemd:
daemon_reload: yes
- name: "Drive Index - {{ kiosk_service_name }} - enable and start service api"
systemd:
name: "{{ kiosk_service_name }}.service"
state: started
enabled: yes
... ...

30
tasks/initialiaze.yaml Normal file
View File

@ -0,0 +1,30 @@
---
- name: Initialiaze - Install Packages
when: not quick_refresh | bool
apt:
name:
- "{{ ssd_health_packages_item }}"
state: present
loop: "{{ ssd_health_packages }}"
loop_control:
loop_var: ssd_health_packages_item
- name: "Initialiaze - create {{ autologin_user }} user"
when: not quick_refresh | bool
user:
name: "{{ autologin_user }}"
groups: disk
password: "{{ autologin_password | password_hash('sha512') }}"
shell: /bin/bash
- name: "Initialiaze - ensure {{ autologin_user }} home folder exists"
when: not quick_refresh | bool
file:
path: "/home/{{ autologin_user }}"
state: directory
owner: "{{ autologin_user }}"
group: "{{ autologin_user }}"
mode: '0700'
...

View File

@ -1,14 +1,14 @@
--- ---
# create and configure user account # create and configure user account
- name: Drive health - set up user account - name: Drive health - initialize early steps
include_tasks: user_setup.yaml include_tasks: initialiaze.yaml
# create drive index service # create drive index service
- name: Drive health - drive_index service - name: Drive health - drive_index service
include_tasks: drive_index.yaml include_tasks: drive_index.yaml
# create drive history dashboard # create drive history web dashboard
- name: Drive health - drive history dashboard - name: Drive health - drive history dashboard
include_tasks: dashboard.yaml include_tasks: dashboard.yaml
@ -17,5 +17,25 @@
when: not install_kiosk | bool or not service_only | bool when: not install_kiosk | bool or not service_only | bool
include_tasks: autologin.yaml include_tasks: autologin.yaml
# configure service-mode
- name: Drive health - configure autologin
when: install_kiosk | bool or service_only | bool
include_tasks: service_mode.yaml
# Install chrome kiosk
- name: install chromium kiosk
when: install_kiosk | bool and not service_only | bool
include_role:
name: "chrome_kiosk"
vars:
refresh_special: "{{ quick_refresh }}"
# kiosk_service_templates:
# - chrome_website: "http://0.0.0.0:8088"
# service_name: ssh_dashboard
# service_description: "SSH Health History Dashboard"
# user_data_dir: ""
# extra_service_configs: ""
# extra_chrome_configs: ""
... ...

33
tasks/no_autologin.yaml Normal file
View File

@ -0,0 +1,33 @@
---
- name: autologin - edit logind to reduce vterms to one
lineinfile:
dest: /etc/systemd/logind.conf
regexp: '^#NAutoVTs='
line: 'NAutoVTs=6'
backrefs: yes
- name: autologin - create getty tty1 service folder
file:
path: /etc/systemd/system/getty@tty1.service.d/
state: directory
mode: '0700'
- name: autologin - "delete {{ autologin_user }} .bash_aliases"
shell: "rm /home/{{ autologin_user }}/.bash_aliases"
- name: autologin - remove autologin override to getty tty1 service
shell: "rm /etc/systemd/system/getty@tty1.service.d/override.conf"
- name: autologin - "User setup - allow {{ autologin_user }} to smartctl"
shell: "rm /etc/sudoers.d/smartctl"
- name: autologin - Restart getty@tty1 service
systemd:
name: getty@tty1.service
state: restarted
enabled: true
masked: false
daemon_reload: true
...

44
tasks/service_mode.yaml Normal file
View File

@ -0,0 +1,44 @@
---
# This will run the drive_check.sh script as a service instead of the autologin
- name: Service Mode - set sleep_time to 1
set_fact:
sleep_time: "1"
- name: "Service Mode - template drive_check.sh again"
template:
src: drive_check.sh
dest: "{{ service_folder }}/drive_check.sh"
mode: 0755
owner: "{{ autologin_user }}"
group: "{{ autologin_user }}"
- name: "Service Mode - {{ kiosk_service_name }}.service - stop service if running"
ignore_errors: yes
systemd:
name: "{{ kiosk_service_name }}.service"
state: stopped
- name: "Service Mode - template {{ kiosk_service_name }}.service"
vars:
service_name: "{{ kiosk_service_name }}"
service_working_folder: "{{ service_folder }}"
service_exe: "{{ kiosk_service_exe }}"
template:
src: "service_template.service"
dest: "/etc/systemd/system/{{ kiosk_service_name }}.service"
mode: 0644
- name: "Service Mode - {{ kiosk_service_name }} - daemon reload"
systemd:
daemon_reload: yes
- name: "Service Mode - {{ kiosk_service_name }} - enable and start service api"
systemd:
name: "{{ kiosk_service_name }}.service"
state: started
enabled: yes
- name: Service Mode - remove autologin
include_tasks: no_autologin.yaml
...

View File

@ -1,43 +0,0 @@
---
- name: "User setup - create {{ autologin_user }} user"
when: not quick_refresh | bool
user:
name: "{{ autologin_user }}"
groups: disk
password: "{{ autologin_password | password_hash('sha512') }}"
shell: /bin/bash
- name: "User setup - ensure {{ autologin_user }} home folder exists"
when: not quick_refresh | bool
file:
path: "/home/{{ autologin_user }}"
state: directory
owner: "{{ autologin_user }}"
group: "{{ autologin_user }}"
mode: '0700'
- name: User setup - autologin needed stuff
when: not service_only | bool
block:
- name: User setup - update permissions on smartctl & fdisk
shell: |
chmod 755 /usr/sbin/smartctl
chmod u+s /usr/sbin/smartctl
chmod u+s /usr/sbin/fdisk
- name: User setup - create symlink for smartctl & fdisk
ignore_errors: yes
shell: |
ln /usr/sbin/smartctl /usr/bin/smartctl
ln /usr/sbin/fdisk /usr/bin/fdisk
- name: "User setup - allow {{ autologin_user }} to smartctl"
copy:
dest: /etc/sudoers.d/smartctl
content: |
{{ autologin_user }} ALL=(ALL) NOPASSWD: /usr/sbin/smartctl
{{ autologin_user }} ALL=(ALL) NOPASSWD: /usr/sbin/fdisk
...

View File

@ -27,7 +27,7 @@ while true; do
MODEL=$(echo "$SMART_DATA" | grep "Device Model" | cut -d ":" -f 2 | xargs) MODEL=$(echo "$SMART_DATA" | grep "Device Model" | cut -d ":" -f 2 | xargs)
SMART=$(echo "$SMART_DATA" | grep "self-assessment test result" | cut -d ":" -f 2 | xargs) SMART=$(echo "$SMART_DATA" | grep "self-assessment test result" | cut -d ":" -f 2 | xargs)
FLAVOR="SATA SSD" FLAVOR="SATA SSD"
DRIVE_EXISTS=$(curl -s 0.0.0.0:5000/check?serial_lookup=$SERIAL | jq .serial_number_exists) DRIVE_EXISTS=$(curl -s "http://172.17.0.1:5000/check?serial_lookup=$SERIAL" | jq .serial_number_exists)
# Display drive data # Display drive data
echo "============ $DISK Disk Info - SSD: ============" echo "============ $DISK Disk Info - SSD: ============"
#echo "DRIVE_EXISTS: $DRIVE_EXISTS" #echo "DRIVE_EXISTS: $DRIVE_EXISTS"
@ -50,15 +50,9 @@ while true; do
H_MODEL=$(echo $MODEL | sed 's/ /%20/g') H_MODEL=$(echo $MODEL | sed 's/ /%20/g')
H_FLAVOR=$(echo $FLAVOR | sed 's/ /%20/g') H_FLAVOR=$(echo $FLAVOR | sed 's/ /%20/g')
H_CAPACITY=$(echo $CAPACITY | sed 's/ /%20/g') H_CAPACITY=$(echo $CAPACITY | sed 's/ /%20/g')
curl -s "http://0.0.0.0:5000/add_drive?serial=$SERIAL&model=$H_MODEL&flavor=$H_FLAVOR&capacity=$H_CAPACITY&TBW=$TBW&smart=$SMART" curl -s "http://172.17.0.1:5000/add_drive?serial=$SERIAL&model=$H_MODEL&flavor=$H_FLAVOR&capacity=$H_CAPACITY&TBW=$TBW&smart=$SMART"
# curl -s "http://0.0.0.0:5000/add_drive?serial='${data[0]}'&model='${data[1]}'&flavor='${data[2]}'&capacity='${data[3]}'&TBW='${data[4]}'&smart='${data[5]}'"
# echo "{{ service_folder }}/store_drive.sh -a '$SERIAL,$MODEL,$FLAVOR,$CAPACITY,$TBW,$SMART' -d {{ db_path }}"
# {{ service_folder }}/store_drive.sh -a "$SERIAL,$MODEL,$FLAVOR,$CAPACITY,$TBW,$SMART" -d {{ db_path }}
else else
curl -s "http://0.0.0.0:5000/update_drive?serial=$SERIAL&TBW=$TBW&smart=$SMART" curl -s "http://172.17.0.1:5000/update_drive?serial=$SERIAL&TBW=$TBW&smart=$SMART"
# curl -s "http://0.0.0.0:5000/update_drive?serial='${data[0]}'&TBW='${data[1]}'&smart='${data[2]}"
# echo "{{ service_folder }}/store_drive.sh -u '$SERIAL,$TBW,$SMART' -d {{ db_path }}"
# {{ service_folder }}/store_drive.sh -u "$SERIAL,$TBW,$SMART" -d {{ db_path }}
fi fi
# NVMe Logic # NVMe Logic
elif [ -n "$NVME_CHECK" ] ; then elif [ -n "$NVME_CHECK" ] ; then
@ -71,7 +65,7 @@ while true; do
CAPACITY=$(echo "$SMART_DATA" | grep "amespace 1 Size" | cut -d '[' -f 2 | sed 's/]//g') CAPACITY=$(echo "$SMART_DATA" | grep "amespace 1 Size" | cut -d '[' -f 2 | sed 's/]//g')
SMART=$(echo "$SMART_DATA" | grep "self-assessment test result" | cut -d ":" -f 2 | xargs) SMART=$(echo "$SMART_DATA" | grep "self-assessment test result" | cut -d ":" -f 2 | xargs)
FLAVOR="NVMe" FLAVOR="NVMe"
DRIVE_EXISTS=$(curl -s 0.0.0.0:5000/check?serial_lookup=$SERIAL | jq .serial_number_exists) DRIVE_EXISTS=$(curl -s "http://172.17.0.1:5000/check?serial_lookup=$SERIAL" | jq .serial_number_exists)
# Display Disk Info # Display Disk Info
echo "============ $DISK Disk Info - NVMe: ============" echo "============ $DISK Disk Info - NVMe: ============"
#echo "DRIVE_EXISTS: $DRIVE_EXISTS" #echo "DRIVE_EXISTS: $DRIVE_EXISTS"
@ -90,15 +84,9 @@ while true; do
H_MODEL=$(echo $MODEL | sed 's/ /%20/g') H_MODEL=$(echo $MODEL | sed 's/ /%20/g')
H_FLAVOR=$(echo $FLAVOR | sed 's/ /%20/g') H_FLAVOR=$(echo $FLAVOR | sed 's/ /%20/g')
H_CAPACITY=$(echo $CAPACITY | sed 's/ /%20/g') H_CAPACITY=$(echo $CAPACITY | sed 's/ /%20/g')
curl -s "http://0.0.0.0:5000/add_drive?serial=$SERIAL&model=$H_MODEL&flavor=$H_FLAVOR&capacity=$H_CAPACITY&TBW=$TBW&smart=$SMART" curl -s "http://172.17.0.1:5000/add_drive?serial=$SERIAL&model=$H_MODEL&flavor=$H_FLAVOR&capacity=$H_CAPACITY&TBW=$TBW&smart=$SMART"
# curl -s "http://0.0.0.0:5000/add_drive?serial='${data[0]}'&model='${data[1]}'&flavor='${data[2]}'&capacity='${data[3]}'&TBW='${data[4]}'&smart='${data[5]}'"
# echo "{{ service_folder }}/store_drive.sh -a '$SERIAL,$MODEL,$FLAVOR,$CAPACITY,$TBW,$SMART' -d {{ db_path }}"
# {{ service_folder }}/store_drive.sh -a "$SERIAL,$MODEL,$FLAVOR,$CAPACITY,$TBW,$SMART" -d {{ db_path }}
else else
curl -s "http://0.0.0.0:5000/update_drive?serial=$SERIAL&TBW=$TBW&smart=$SMART" curl -s "http://172.17.0.1:5000/update_drive?serial=$SERIAL&TBW=$TBW&smart=$SMART"
# curl -s "http://0.0.0.0:5000/update_drive?serial='${data[0]}'&TBW='${data[1]}'&smart='${data[2]}"
# echo "{{ service_folder }}/store_drive.sh -u '$SERIAL,$TBW,$SMART' -d {{ db_path }}"
# {{ service_folder }}/store_drive.sh -u "$SERIAL,$TBW,$SMART" -d {{ db_path }}
fi fi
fi fi
else else

View File

@ -7,7 +7,6 @@ After=network.target
User=root User=root
Group=root Group=root
WorkingDirectory={{ service_working_folder }} WorkingDirectory={{ service_working_folder }}
ExecStartPre=/bin/sleep 5
ExecStart={{ service_exe }} ExecStart={{ service_exe }}
Restart=always Restart=always