From c8c26e3fc9f640fc7261a8b0af0d86ec06299095 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 12 Feb 2025 10:56:29 -0500 Subject: [PATCH 1/2] automated terminal push --- ...5ed8bb34-a0d2-44e6-91c4-9505f99306c1.devvv | 0 .scalingTrash/backupshit | 58 +++++++ .../compose (copy 1).template | 0 compose.yaml => .scalingTrash/compose.yaml | 0 .scalingTrash/cronExtras2.bash | 38 +++++ touch => .scalingTrash/touch | 0 composeScaling.bash => compose.bash | 0 cronfile | 1 + crontabX | 8 + smart-cron-builder.bash | 5 + smart-cron-builder.py | 149 ++++++++++++++++++ 11 files changed, 259 insertions(+) rename 5ed8bb34-a0d2-44e6-91c4-9505f99306c1.devvv => .scalingTrash/5ed8bb34-a0d2-44e6-91c4-9505f99306c1.devvv (100%) create mode 100644 .scalingTrash/backupshit rename compose (copy 1).template => .scalingTrash/compose (copy 1).template (100%) rename compose.yaml => .scalingTrash/compose.yaml (100%) create mode 100644 .scalingTrash/cronExtras2.bash rename touch => .scalingTrash/touch (100%) rename composeScaling.bash => compose.bash (100%) create mode 100644 crontabX create mode 100755 smart-cron-builder.bash create mode 100755 smart-cron-builder.py diff --git a/5ed8bb34-a0d2-44e6-91c4-9505f99306c1.devvv b/.scalingTrash/5ed8bb34-a0d2-44e6-91c4-9505f99306c1.devvv similarity index 100% rename from 5ed8bb34-a0d2-44e6-91c4-9505f99306c1.devvv rename to .scalingTrash/5ed8bb34-a0d2-44e6-91c4-9505f99306c1.devvv diff --git a/.scalingTrash/backupshit b/.scalingTrash/backupshit new file mode 100644 index 0000000..83746ca --- /dev/null +++ b/.scalingTrash/backupshit @@ -0,0 +1,58 @@ + log_file = "/var/log/yankee-downloader.log" + script_path = "/yankee-gnome-fire-consumer/consumer.py" + + return "@@@" + + + + + +import datetime +import subprocess +import socket +import os + +def getMinutes(): + + if current_time is None: + current_time = datetime.datetime.now() + + new_minute = (current_time.minute + 5) % 60 # The % operator performs the wrap-around + new_hour = current_time.hour + (current_time.minute + 5) // 60 # Integer division for hour increment + + # Create a new datetime object with the updated minute and handle hour rollover + try: + new_time = current_time.replace(minute=new_minute, hour=new_hour) + except ValueError: # handles cases where the hour rollover causes day change + new_time = current_time + datetime.timedelta(minutes=5) + + return new_time + + + +def generate_cron_entry(): + + """Generates a cron entry that runs 5 minutes from now and logs server info.""" + + now = datetime.datetime.now() + five_minutes_from_now = now + datetime.timedelta(minutes=5) + + minute = five_minutes_from_now.minute + hour = five_minutes_from_now.hour + day = five_minutes_from_now.day + month = five_minutes_from_now.month + weekday = "*" # Weekday is left as * to run every day of the week. If you need specific weekdays, change this. + + # Get server IP and hostname + try: + server_ip = socket.gethostbyname(socket.gethostname()) + server_hostname = socket.gethostname() + except socket.gaierror: + server_ip = "Unknown IP" + server_hostname = "Unknown Hostname" + + + log_file = "/var/log/yankee-downloader.log" + script_path = "/yankee-gnome-fire-consumer/consumer.py" + +print("getMinutes / ",getMinutes()) diff --git a/compose (copy 1).template b/.scalingTrash/compose (copy 1).template similarity index 100% rename from compose (copy 1).template rename to .scalingTrash/compose (copy 1).template diff --git a/compose.yaml b/.scalingTrash/compose.yaml similarity index 100% rename from compose.yaml rename to .scalingTrash/compose.yaml diff --git a/.scalingTrash/cronExtras2.bash b/.scalingTrash/cronExtras2.bash new file mode 100644 index 0000000..12266e3 --- /dev/null +++ b/.scalingTrash/cronExtras2.bash @@ -0,0 +1,38 @@ + +function recycle{ +start_hour=$(date +%H) + +if (( current_minute + 5 >= 60 )); then + + start_hour=$(( (start_hour + 1) % 24 )) # handle wrap-around at 24 hours + +fi + +start_day=$(date +%d) +start_month=$(date +%m) +start_weekday=$(date +%w) + + +# Get external IP and hostname (using a reliable method) + +external_ip=$(curl -s ifconfig.me) # Or use dig +short myip.opendns.com + +hostname=$(hostname -f) + + +# Construct the cron command with the calculated time and logging +cron_command="$start_minute $start_hour $start_day $start_month $start_weekday python3 /yankee-gnome-fire-consumer/consumer.py >> /var/log/yankee-downloader.log 2>&1" + +# Add IP and hostname to log message *before* the python script runs +log_message="Starting consumer at $(date) from $hostname ($external_ip): " + +# Add the log message to the log file, then run the python script and redirect stderr +# This is done using a subshell to ensure the log message comes before the python script's output. +cron_command_with_log="echo \"$log_message\" >> /var/log/yankee-downloader.log 2>&1; $cron_command" + + +# Add the cron job (using crontab -l to get existing entries, adding the new one, and then setting the crontab) +(crontab -l; echo "$cron_command_with_log") | crontab - + + +echo "Cron job added: $cron_command_with_log" \ No newline at end of file diff --git a/touch b/.scalingTrash/touch similarity index 100% rename from touch rename to .scalingTrash/touch diff --git a/composeScaling.bash b/compose.bash similarity index 100% rename from composeScaling.bash rename to compose.bash diff --git a/cronfile b/cronfile index 8b371dc..7d28491 100644 --- a/cronfile +++ b/cronfile @@ -1,5 +1,6 @@ SHELL=/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + * * * * * python3 /yankee-gnome-fire-consumer/consumer.py >> /var/log/yankee-downloader.log 2>&1 * * * * * /tmp/ping2.bash >> /var/log/cron.log 2>&1 diff --git a/crontabX b/crontabX new file mode 100644 index 0000000..b720184 --- /dev/null +++ b/crontabX @@ -0,0 +1,8 @@ +SHELL=/bin/bash + +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +57 11 * * * python3 /yankee-gnome-fire-consumer/consumer.py >> /tmp/root/Downloads/.logs/yankee-node-96.255.165.82-veneno.log 2>&1 + +* * * * * /tmp/ping2.bash >> /var/log/cron.log 2>&1 + diff --git a/smart-cron-builder.bash b/smart-cron-builder.bash new file mode 100755 index 0000000..2c7761f --- /dev/null +++ b/smart-cron-builder.bash @@ -0,0 +1,5 @@ +reset + +clear + +python3 smart-cron-builder.py \ No newline at end of file diff --git a/smart-cron-builder.py b/smart-cron-builder.py new file mode 100755 index 0000000..f0c8126 --- /dev/null +++ b/smart-cron-builder.py @@ -0,0 +1,149 @@ +import datetime +import subprocess +import socket +import os +import requests + +def buildLogDirectory(): + + return "/tmp/root/Downloads/.logs/" + +def buildLogFileName(): + + logFileDir = buildLogDirectory() + + try: + + response = requests.get("https://api.ipify.org?format=json") # Or another similar service + + response.raise_for_status() # Check for HTTP errors (4xx or 5xx) + + ip_data = response.json() + + server_ip = ip_data['ip'] + + print("server_ip / ",ip_data['ip']) + + server_hostname = socket.gethostname() + + print("server_hostname / ",server_hostname) + + node_id= logFileDir + "yankee-node-" + server_ip + "-" + server_hostname + ".log" + + return node_id + + except socket.gaierror: + + return "!!error!!" + +def buildCronExecuteTime(): + + current_time = datetime.datetime.now() + + new_minute = (current_time.minute + 2) % 60 # The % operator performs the wrap-around + + print("new_minute / ",new_minute) + + new_hour = current_time.hour + (current_time.minute + 5) // 60 # Integer division for hour increment + + print("new_hour / ",new_hour) + + cron = str(new_minute) + " " + str(new_hour) + " " + "* * *" + + return cron + +def buildCronSituation(): + + return buildCronExecuteTime() +" python3 /yankee-gnome-fire-consumer/consumer.py >> " + buildLogFileName() + " 2>&1" + +#### + +cronTiming = buildCronExecuteTime() + +print("cronTiming / ",cronTiming) + +## + +logger = buildLogFileName(); + +print("logger / ",logger) + +## + +cronFile = buildCronSituation(); + +print() +print(cronFile) +print() + + + +def createLogDir(): + + log_dir = buildLogDirectory() + + print("creating log dir",log_dir) + + try: + if not os.path.exists(log_dir): # Check if the directory exists + os.makedirs(log_dir) # Create the directory (and any necessary parent directories) + print(f"Directory '{log_dir}' created successfully.") + else: + print(f"Directory '{log_dir}' already exists.") + return True # Directory exists or was created successfully + + except OSError as e: + print(f"Error creating directory '{log_dir}': {e}") + return False + +## + + +def writeCrontabSituation(): + + file_path ="crontabX" + + crontab_text = """ +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +* * * * * python3 /yankee-gnome-fire-consumer/consumer.py >> /var/log/yankee-downloader.log 2>&1 + +* * * * * /tmp/ping2.bash >> /var/log/cron.log 2>&1""" + + try: + # Check if the file exists and delete if it does + if os.path.exists(file_path): + os.remove(file_path) + + with open(file_path, "w") as f: + + sep="\n" + + f.write("SHELL=/bin/bash") + f.write(sep) + f.write(sep) + + f.write("PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin") + f.write(sep) + f.write(sep) + + f.write(buildCronSituation()) + f.write(sep) + f.write(sep) + + f.write("* * * * * /tmp/ping2.bash >> /var/log/cron.log 2>&1") + f.write(sep) + f.write(sep) + + print(f"Crontab written to '{file_path}' successfully.") + + return True + + except OSError as e: + print(f"Error writing to file '{file_path}': {e}") + return False + +#################### +createLogDir() + +writeCrontabSituation() \ No newline at end of file -- 2.49.1 From 8b91508f3ba01c1f062cc3ce48d8bb1fdb513148 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 12 Feb 2025 14:54:45 -0500 Subject: [PATCH 2/2] automated terminal push --- Dockerfile | 23 ------ compose.template | 0 compose.yaml | 73 +++++++++++++++++ compose1x.bash | 109 +++++++++++++++++++++++++ provision/startup/startup.sh | 7 ++ smart-cron-builder.bash | 5 -- smart-cron-builder.py | 149 ----------------------------------- 7 files changed, 189 insertions(+), 177 deletions(-) mode change 100755 => 100644 compose.template create mode 100644 compose.yaml create mode 100755 compose1x.bash delete mode 100755 smart-cron-builder.bash delete mode 100755 smart-cron-builder.py diff --git a/Dockerfile b/Dockerfile index 427d46a..4d39cb2 100755 --- a/Dockerfile +++ b/Dockerfile @@ -32,26 +32,3 @@ RUN bash installs/cron.bash COPY provision/startup/startup.sh /startup.sh ## - - -#### - -COPY ping.script /tmp/ping.bash - -RUN chmod +x /tmp/ping.bash - -COPY ping2.script /tmp/ping2.bash - -RUN chmod +x /tmp/ping2.bash - -RUN ls -lha /tmp/ - -#### - -COPY cronfile /etc/cron.d/cronfile - -# Give execution rights on the cron job -RUN chmod 0644 /etc/cron.d/cronfile - -# Apply the cron job -RUN crontab -u root /etc/cron.d/cronfile diff --git a/compose.template b/compose.template old mode 100755 new mode 100644 diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..e2c54ae --- /dev/null +++ b/compose.yaml @@ -0,0 +1,73 @@ +services: + + +########################################## +## +## orchestration / yankee-desktop-remix +## +##########################################001 + + yankee-desktop-remix-001: + container_name: yankee-desktop-remix-001 + image: softwareshinobi/yankee-desktop-remix + restart: unless-stopped + build: + context: . + dockerfile: Dockerfile + volumes: + - yankee-nfs-downloads:/root/Downloads + hostname: yankee-desktop-001 + ports: + - "20012:22" + - "20018:80" + - "20019:5900" + environment: + TZ: America/Bogota + USER_UID: 1000 + USER_GID: 1000 + USER: root + PASSWORD: yankee + HTTP_PASSWORD: yankee + + +########################################## +## +## orchestration / yankee-desktop-remix +## +##########################################002 + + yankee-desktop-remix-002: + container_name: yankee-desktop-remix-002 + image: softwareshinobi/yankee-desktop-remix + restart: unless-stopped + build: + context: . + dockerfile: Dockerfile + volumes: + - yankee-nfs-downloads:/root/Downloads + hostname: yankee-desktop-002 + ports: + - "20022:22" + - "20028:80" + - "20029:5900" + environment: + TZ: America/Bogota + USER_UID: 1000 + USER_GID: 1000 + USER: root + PASSWORD: yankee + HTTP_PASSWORD: yankee + +########################################## +## +## volumes / yankee-desktop-remix +## +########################################## + +volumes: + yankee-nfs-downloads: + driver_opts: + type: "nfs" + o: nfsvers=4,addr=osiris.yankee.embanet.online,nolock,hard,rw + device: ":/" + diff --git a/compose1x.bash b/compose1x.bash new file mode 100755 index 0000000..0d2cd27 --- /dev/null +++ b/compose1x.bash @@ -0,0 +1,109 @@ +#!/bin/bash + +## + +set -e + +set -x + +## + +reset + +clear + +## + + +## + +processorCount=`grep -c '^processor' /proc/cpuinfo` + +processorCount=1 + +echo "num cpus / "$processorCount + +for i in $(seq 2 "$processorCount"); do + + echo "Processing unit: $i" + +## + +rm -f compose.yaml + +echo "services:" >> compose.yaml + +## + +for x in $(seq 1 "$processorCount"); do + + i=$(printf "%03d" "$x") + + # Create the service definition + service_def=$(cat <> compose.yaml + +done + + +# Add the volumes section ONCE after the loop (outside) +cat <> compose.yaml + +########################################## +## +## volumes / yankee-desktop-remix +## +########################################## + +volumes: + yankee-nfs-downloads: + driver_opts: + type: "nfs" + o: nfsvers=4,addr=osiris.yankee.embanet.online,nolock,hard,rw + device: ":/" + +EOF + #... your commands to process each unit... + +done +## + +docker compose down --remove-orphans + +docker compose up -d + +docker stats diff --git a/provision/startup/startup.sh b/provision/startup/startup.sh index b65a2fd..a1f7ccf 100755 --- a/provision/startup/startup.sh +++ b/provision/startup/startup.sh @@ -113,6 +113,13 @@ chmod +x *.sh #### +echo "scheduling the cron job" + +bash smart-cron-builder.bash + +echo "cron job scheduled" + +#### exec /bin/tini -- supervisord -n -c /etc/supervisor/supervisord.conf diff --git a/smart-cron-builder.bash b/smart-cron-builder.bash deleted file mode 100755 index 2c7761f..0000000 --- a/smart-cron-builder.bash +++ /dev/null @@ -1,5 +0,0 @@ -reset - -clear - -python3 smart-cron-builder.py \ No newline at end of file diff --git a/smart-cron-builder.py b/smart-cron-builder.py deleted file mode 100755 index f0c8126..0000000 --- a/smart-cron-builder.py +++ /dev/null @@ -1,149 +0,0 @@ -import datetime -import subprocess -import socket -import os -import requests - -def buildLogDirectory(): - - return "/tmp/root/Downloads/.logs/" - -def buildLogFileName(): - - logFileDir = buildLogDirectory() - - try: - - response = requests.get("https://api.ipify.org?format=json") # Or another similar service - - response.raise_for_status() # Check for HTTP errors (4xx or 5xx) - - ip_data = response.json() - - server_ip = ip_data['ip'] - - print("server_ip / ",ip_data['ip']) - - server_hostname = socket.gethostname() - - print("server_hostname / ",server_hostname) - - node_id= logFileDir + "yankee-node-" + server_ip + "-" + server_hostname + ".log" - - return node_id - - except socket.gaierror: - - return "!!error!!" - -def buildCronExecuteTime(): - - current_time = datetime.datetime.now() - - new_minute = (current_time.minute + 2) % 60 # The % operator performs the wrap-around - - print("new_minute / ",new_minute) - - new_hour = current_time.hour + (current_time.minute + 5) // 60 # Integer division for hour increment - - print("new_hour / ",new_hour) - - cron = str(new_minute) + " " + str(new_hour) + " " + "* * *" - - return cron - -def buildCronSituation(): - - return buildCronExecuteTime() +" python3 /yankee-gnome-fire-consumer/consumer.py >> " + buildLogFileName() + " 2>&1" - -#### - -cronTiming = buildCronExecuteTime() - -print("cronTiming / ",cronTiming) - -## - -logger = buildLogFileName(); - -print("logger / ",logger) - -## - -cronFile = buildCronSituation(); - -print() -print(cronFile) -print() - - - -def createLogDir(): - - log_dir = buildLogDirectory() - - print("creating log dir",log_dir) - - try: - if not os.path.exists(log_dir): # Check if the directory exists - os.makedirs(log_dir) # Create the directory (and any necessary parent directories) - print(f"Directory '{log_dir}' created successfully.") - else: - print(f"Directory '{log_dir}' already exists.") - return True # Directory exists or was created successfully - - except OSError as e: - print(f"Error creating directory '{log_dir}': {e}") - return False - -## - - -def writeCrontabSituation(): - - file_path ="crontabX" - - crontab_text = """ -PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - -* * * * * python3 /yankee-gnome-fire-consumer/consumer.py >> /var/log/yankee-downloader.log 2>&1 - -* * * * * /tmp/ping2.bash >> /var/log/cron.log 2>&1""" - - try: - # Check if the file exists and delete if it does - if os.path.exists(file_path): - os.remove(file_path) - - with open(file_path, "w") as f: - - sep="\n" - - f.write("SHELL=/bin/bash") - f.write(sep) - f.write(sep) - - f.write("PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin") - f.write(sep) - f.write(sep) - - f.write(buildCronSituation()) - f.write(sep) - f.write(sep) - - f.write("* * * * * /tmp/ping2.bash >> /var/log/cron.log 2>&1") - f.write(sep) - f.write(sep) - - print(f"Crontab written to '{file_path}' successfully.") - - return True - - except OSError as e: - print(f"Error writing to file '{file_path}': {e}") - return False - -#################### -createLogDir() - -writeCrontabSituation() \ No newline at end of file -- 2.49.1