many refinements

This commit is contained in:
2025-11-02 15:20:34 -08:00
parent a9681e2c94
commit 982b7a374d
12 changed files with 169 additions and 170 deletions

View File

@ -19,13 +19,21 @@ container_http_port: "8088"
extra_volumes: "" extra_volumes: ""
# api service vars # api service vars
service_name: "drive_index" api_service_name: "drive_index"
service_folder: "/opt/ssd_health" api_service_folder: "{{ service_folder }}"
api_service_exe: "{{ service_folder }}/venv/bin/python {{ service_folder }}/app.py"
# kiosk service vars
kiosk_service_name: "drive_check"
kiosk_service_exe: "{{ service_folder }}/drive_check.sh"
# other vars # other vars
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 install_kiosk: false
sleep_time: "5"
quick_refresh: false
... ...

View File

@ -28,7 +28,7 @@ function fetchSSDData() {
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h1>SSD Health Dashboard</h1> <button onclick="window.location.reload();" class="title-button"><h1>SSD Health Dashboard</h1></button>
<?php <?php
$i=0; $i=0;
$ssdData = fetchSSDData(); // Fetch data from the API $ssdData = fetchSSDData(); // Fetch data from the API

View File

@ -12,6 +12,18 @@ body {
display: none; display: none;
} }
.title-button {
background-color: #34495e;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.container { .container {
max-width: 800px; max-width: 800px;
margin: 0 auto; margin: 0 auto;

View File

@ -4,14 +4,19 @@ import json
app = Flask(__name__) app = Flask(__name__)
# Function to get all drive records from the database # sqlite query function
def get_all_drive_records(): def query_db(sql_query):
conn = sqlite3.connect('drive_records.db') conn = sqlite3.connect('drive_records.db')
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute("SELECT * FROM drive_records") cursor.execute(sql_query)
rows = cursor.fetchall() rows = cursor.fetchall()
conn.close() conn.close()
return rows
# Function to return all drive records in database
def get_all_drive_records():
get_all_drives = "SELECT * FROM drive_records"
rows = query_db(get_all_drives)
drives = [] drives = []
for row in rows: for row in rows:
drive = { drive = {
@ -28,12 +33,7 @@ def get_all_drive_records():
# Function to check if a serial number exists in the database # Function to check if a serial number exists in the database
def check_serial_exists(serial): def check_serial_exists(serial):
conn = sqlite3.connect('drive_records.db') return bool(query_db("SELECT * FROM drive_records WHERE serial=?", (serial,)))
cursor = conn.cursor()
cursor.execute("SELECT * FROM drive_records WHERE serial=?", (serial,))
row = cursor.fetchone()
conn.close()
return bool(row)
# Route to check if a serial number exists in the database # Route to check if a serial number exists in the database
@app.route('/check', methods=['GET']) @app.route('/check', methods=['GET'])

View File

@ -1,66 +0,0 @@
#!/bin/bash
# Function to display usage information
usage() {
echo "Usage: $0 -a \"serial,model,capacity,TBW,smart\""
exit 1
}
# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
usage
fi
# Parse command-line arguments
while getopts ":a:" opt; do
case ${opt} in
a)
# Extract the comma-separated list of attributes
IFS=',' read -ra ATTRS <<< "$OPTARG"
;;
\?)
echo "Invalid option: $OPTARG" 1>&2
usage
;;
esac
done
shift $((OPTIND -1))
# Check if the database file exists, otherwise create it and initialize the table
DB_FILE="drive_records.db"
if [ ! -f "$DB_FILE" ]; then
sqlite3 "$DB_FILE" <<EOF
CREATE TABLE drive_records (id INTEGER PRIMARY KEY, serial TEXT NOT NULL, model TEXT NOT NULL, capacity TEXT NOT NULL, TBW TEXT NOT NULL, smart TEXT NOT NULL);
EOF
fi
# Read the input data from stdin
while read -r line; do
# Extract values for each attribute and insert into the database
VALUES=()
IFS=' ' read -ra PARTS <<< "$line"
for ((i = 0; i < ${#ATTRS[@]}; i++)); do
case "${ATTRS[i]}" in
serial)
VALUES+=("${PARTS[0]}")
;;
model)
VALUES+=("${PARTS[1]}")
;;
capacity)
VALUES+=("${PARTS[2]}")
;;
TBW)
VALUES+=("${PARTS[3]}")
;;
smart)
VALUES+=("${PARTS[4]}")
;;
esac
done
# Insert the values into the database
sqlite3 "$DB_FILE" <<EOF
INSERT INTO drive_records (serial, model, capacity, TBW, smart) VALUES ('${VALUES[0]}', '${VALUES[1]}', '${VALUES[2]}', '${VALUES[3]}', '${VALUES[4]}');
EOF
done <<< "$(cat -)"

View File

@ -36,6 +36,7 @@
# create hello_there ASCII art # create hello_there ASCII art
- name: autologin - generate hello_there.txt for the lulz - name: autologin - generate hello_there.txt for the lulz
when: not quick_refresh | bool
include_tasks: hello_there.yaml include_tasks: hello_there.yaml
- name: autologin - Restart getty@tty1 service - name: autologin - Restart getty@tty1 service

View File

@ -32,6 +32,7 @@
############################################### ###############################################
- name: start drive history dashboard - name: start drive history dashboard
when: not quick_refresh | bool
block: block:
- name: service_control_website - template config - name: service_control_website - template config

View File

@ -1,7 +1,7 @@
--- ---
- name: Drive Index - Install Packages - name: Drive Index - Install Packages
when: not quick_refresh | bool
apt: apt:
name: name:
- "{{ ssd_health_packages_item }}" - "{{ ssd_health_packages_item }}"
@ -10,86 +10,129 @@
loop_control: loop_control:
loop_var: ssd_health_packages_item loop_var: ssd_health_packages_item
# Create Service Folder - name: Drive Index - file and folder handler
- name: Drive Index - create ssd_check service folder block:
file:
path: "{{ service_folder }}"
state: directory
owner: "{{ autologin_user }}"
group: "{{ autologin_user }}"
mode: '0755'
- name: Drive Index - copy script files - name: Drive Index - create ssd_check service folder
copy: file:
src: scripts/ path: "{{ service_folder }}"
dest: "{{ service_folder }}/" state: directory
owner: "{{ autologin_user }}" owner: "{{ autologin_user }}"
group: "{{ autologin_user }}" group: "{{ autologin_user }}"
mode: 0755 mode: '0755'
- name: Drive Index - copy script files
copy:
src: scripts/
dest: "{{ service_folder }}/"
owner: "{{ autologin_user }}"
group: "{{ autologin_user }}"
mode: 0755
- name: Drive Index - initialize db
shell: "{{ service_folder }}/store_drive.sh -i -d {{ db_path }}"
- name: "Drive Index - template drive_check.sh"
template:
src: drive_check.sh
dest: "{{ service_folder }}/drive_check.sh"
mode: 0755
owner: "{{ autologin_user }}"
group: "{{ autologin_user }}"
# Create python service venv # Create python service venv
- name: Drive Index - create python venv requirement file - name: Drive Index - Python venv handler
copy: when: not quick_refresh | bool
dest: "{{ service_folder }}/requirements.txt" block:
content: |
flask
pytz
requests
opencv-python
owner: "{{ autologin_user }}"
group: "{{ autologin_user }}"
mode: 0644
# build venv - name: Drive Index - create python venv requirement file
- name: Drive Index - build python venv copy:
pip: dest: "{{ service_folder }}/requirements.txt"
virtualenv: "{{ service_folder }}/venv" content: |
requirements: "{{ service_folder }}/requirements.txt" flask
virtualenv_command: python3 -m venv pytz
state: present requests
opencv-python
owner: "{{ autologin_user }}"
group: "{{ autologin_user }}"
mode: 0644
# stop service - name: Drive Index - build python venv
- name: "Drive Index - {{ service_name }} api - stop api service if running" pip:
ignore_errors: yes virtualenv: "{{ service_folder }}/venv"
systemd: requirements: "{{ service_folder }}/requirements.txt"
name: "{{ service_name }}.service" virtualenv_command: python3 -m venv
state: stopped state: present
# Create service_control api service - name: Drive Index - api service handler
- name: "Drive Index - template {{ service_name }}.service" block:
template:
src: drive_index.service
dest: /etc/systemd/system/drive_index.service
mode: 0644
# Create drive_check.sh - name: "Drive Index - {{ api_service_name }} - stop service if running"
- name: "Drive Index - template drive_check.sh" ignore_errors: yes
template: systemd:
src: drive_check.sh name: "{{ api_service_name }}.service"
dest: "{{ service_folder }}/drive_check.sh" state: stopped
mode: 0755
owner: "{{ autologin_user }}"
group: "{{ autologin_user }}"
# daemon reload - name: "Drive Index - template {{ api_service_name }}.service"
- name: "Drive Index - {{ service_name }} api - daemon reload" vars:
systemd: service_name: "{{ api_service_name }}"
daemon_reload: yes service_working_folder: "{{ api_service_folder }}"
service_exe: "{{ api_service_exe }}"
template:
src: "service_template.service"
dest: "/etc/systemd/system/{{ api_service_name }}.service"
mode: 0644
# Enable and start - name: "Drive Index - {{ api_service_name }} - daemon reload"
- name: "Drive Index - {{ service_name }} api - enable and start service api" systemd:
systemd: daemon_reload: yes
name: "{{ service_name }}.service"
state: started
enabled: yes
- name: "Drive Index - {{ service_name }} api - enable and start service timeoue api" - name: "Drive Index - {{ api_service_name }} - enable and start service"
systemd: systemd:
name: "{{ service_name }}.service" name: "{{ api_service_name }}.service"
state: started state: started
enabled: yes enabled: yes
- name: Drive Index - initialize db - name: Drive Index - kiosk mode handler
shell: "{{ service_folder }}/store_drive.sh -i -d {{ db_path }}" when: install_kiosk | 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
... ...

View File

@ -2,6 +2,7 @@
# create and configure user account # create and configure user account
- name: Drive health - set up user account - name: Drive health - set up user account
when: not quick_refresh | bool
include_tasks: user_setup.yaml include_tasks: user_setup.yaml
# create drive index service # create drive index service

View File

@ -85,7 +85,7 @@ while true; do
echo "Skipping $DISK, not SATA SSD or NVMe" echo "Skipping $DISK, not SATA SSD or NVMe"
fi fi
done done
# wait 15 seconds, loop again # wait {{ sleep_time }} seconds, loop again
echo "Sleeping 15 seconds so you can read this" echo "Sleeping {{ sleep_time }} seconds"
sleep 15 sleep {{ sleep_time }}
done done

View File

@ -1,16 +0,0 @@
[Unit]
Description={{ service_name }}
git remote add origin git@gitea.matt-cloud.com:matt/ssd_health.gitAPI
After=network.target
[Service]
User=root
Group=root
WorkingDirectory={{ service_folder }}
ExecStartPre=/bin/sleep 5
ExecStart={{ service_folder }}/venv/bin/python {{ service_folder }}/app.py
Restart=always
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,15 @@
[Unit]
Description={{ service_name }}
After=network.target
[Service]
User=root
Group=root
WorkingDirectory={{ service_working_folder }}
ExecStartPre=/bin/sleep 5
ExecStart={{ service_exe }}
Restart=always
[Install]
WantedBy=multi-user.target