Skip to content

Instantly share code, notes, and snippets.

@navotera
Created December 7, 2024 23:44
Show Gist options
  • Save navotera/98f9c32d873cb73dd9e27dbce2e32403 to your computer and use it in GitHub Desktop.
Save navotera/98f9c32d873cb73dd9e27dbce2e32403 to your computer and use it in GitHub Desktop.
create pamin service
import os
import subprocess
# Step 1: Install and setup phpMyAdmin
commands = [
"cd /etc && wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip",
"unzip /etc/phpMyAdmin-latest-all-languages.zip -d /etc/",
"mv /etc/phpMyAdmin-* /etc/pamin"
]
for command in commands:
subprocess.run(command, shell=True, check=True)
# Step 2: Create a service for phpMyAdmin
service_file_content = """
[Unit]
Description=pamin phpMyAdmin Service
After=network.target
[Service]
ExecStart=/usr/bin/php -S 0.0.0.0:9292 -t /etc/pamin
Restart=always
[Install]
WantedBy=multi-user.target
"""
service_file_path = "/etc/systemd/system/pamin.service"
with open(service_file_path, "w") as service_file:
service_file.write(service_file_content)
# Reload systemd and enable the service
os.system("systemctl daemon-reload")
os.system("systemctl enable pamin")
# Step 3: Create a crontab to stop the service every 2 hours
crontab_command = "0 */2 * * * /bin/systemctl stop pamin"
current_crontab = subprocess.run(["crontab", "-l"], capture_output=True, text=True).stdout
# Check if the crontab already exists to avoid duplicates
if crontab_command not in current_crontab:
with open("temp_cron", "w") as cron_file:
cron_file.write(current_crontab)
cron_file.write(f"{crontab_command}\n")
os.system("crontab temp_cron")
os.remove("temp_cron")
print("Setup complete. Start the service using 'service pamin start' ")
print("Access it with and access it with https://IP_ADRESS:9292")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment