init scripts

This commit is contained in:
2024-09-03 00:11:09 -05:00
parent 2a141b6735
commit 51944a626c
2 changed files with 122 additions and 0 deletions

51
update-rbl.py Normal file
View File

@@ -0,0 +1,51 @@
import shutil
import subprocess
import signal
import os
def update_and_reload():
"""Copies the VPN list, restarts rbldnsd (finding PID using ps aux), and logs the process."""
# Copy the VPN list
try:
shutil.copy('/root/vpnlist.txt', '/etc/vpnlist.txt')
print("VPN list copied successfully.")
except shutil.Error as e:
print(f"Error copying VPN list: {e}")
return # Exit if copy fails
# Find the PID of rbldnsd using ps aux
try:
output = subprocess.check_output(["ps", "aux"]).decode()
for line in output.splitlines():
if "rbldnsd" in line:
pid = int(line.split()[1])
break
else:
raise ValueError("rbldnsd process not found in ps aux output.")
print(f"Found rbldnsd process with PID: {pid}")
except (subprocess.CalledProcessError, ValueError) as e:
print(f"Error finding rbldnsd PID: {e}")
return
# Stop rbldnsd
try:
os.kill(pid, signal.SIGTERM) # Send a termination signal
print("Sent termination signal to rbldnsd.")
except ProcessLookupError:
print("Error: rbldnsd process not found (might have already stopped).")
return
# Start rbldnsd (make sure this matches your actual rbldnsd command)
try:
subprocess.run(["rbldnsd", "-4", "-b", "0.0.0.0/5553", "-l", "/var/log/rbldnsd.log",
"dnsbl.rizon.net:ip4set:/etc/rbldnsd.db",
"dnsbl.rizon.net:ip4set:/etc/vpnlist.txt"], check=True)
print("rbldnsd restarted successfully.")
except subprocess.CalledProcessError as e:
print(f"Error restarting rbldnsd: {e}")
print("VPN list updated and rbldnsd restarted successfully.")
if __name__ == "__main__":
update_and_reload()