First commit of the new Insider version on docker
This commit is contained in:
95
setup.py
Normal file
95
setup.py
Normal file
@@ -0,0 +1,95 @@
|
||||
import json
|
||||
import os
|
||||
from getpass import getpass
|
||||
|
||||
setup_file_path = '/home/cdn-app/setup.json' # Specify the full path for setup.json
|
||||
|
||||
setup_data = {}
|
||||
|
||||
def print_with_color(text, color):
|
||||
colors = {
|
||||
'reset': '\033[0m',
|
||||
'green': '\033[92m',
|
||||
'yellow': '\033[93m',
|
||||
'cyan': '\033[96m',
|
||||
'bold': '\033[1m'
|
||||
}
|
||||
print(f"{colors[color]}{text}{colors['reset']}")
|
||||
|
||||
def create_service():
|
||||
service_name = 'cdn.service'
|
||||
# Create the service file
|
||||
service_file_path = f'/etc/systemd/system/{service_name}'
|
||||
with open(service_file_path, 'w') as service_file:
|
||||
service_file.write(f'''
|
||||
[Unit]
|
||||
Description=CDN-APP, dinawoSR Inc
|
||||
Documentation=https://cdn-app.dinawo.fr
|
||||
|
||||
[Service]
|
||||
ExecStart=/root/.nvm/versions/node/v16.9.0/bin/node /home/cdn-app/server.js
|
||||
Restart=always
|
||||
User=root
|
||||
Environment=PATH=/usr/bin:/usr/local/bin:/root/.nvm/versions/node/v16.9.0/bin
|
||||
Environment=NODE_ENV=production
|
||||
WorkingDirectory=/home/cdn-app
|
||||
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
''')
|
||||
|
||||
# Restart systemd to acknowledge the new service
|
||||
os.system('systemctl daemon-reload')
|
||||
os.system('systemctl enable cdn.service')
|
||||
os.system('systemctl start cdn.service')
|
||||
|
||||
print_with_color(f"Service {service_name} created successfully.", 'green')
|
||||
|
||||
# Loader
|
||||
print_with_color("Welcome to server configuration script.", 'cyan')
|
||||
|
||||
# Change the current working directory to /home/cdn-app
|
||||
os.chdir('/home/cdn-app')
|
||||
|
||||
# LDAP information input
|
||||
setup_data['ldap'] = {
|
||||
'url': input("LDAP server URL (ldap://your-ip): "),
|
||||
'baseDN': input("Base DN (DC=DINAWOSRINC,DC=LAN): "),
|
||||
'username': input("Username (Account Sync): "),
|
||||
'password': getpass("Password (Password Account Sync): ")
|
||||
}
|
||||
|
||||
# Prompt for domain name
|
||||
setup_data['domain'] = input("Enter the domain name (cdn.domain.com): ")
|
||||
|
||||
# Prompt for uptime link
|
||||
setup_data['uptime'] = input("Enter the uptime link (uptime.domain.com): ")
|
||||
|
||||
# Check Node.js version
|
||||
node_version = os.popen('node -v').read().strip()
|
||||
required_node_version = 'v16.9.0'
|
||||
if node_version != required_node_version:
|
||||
print_with_color(f"Error: Incorrect Node.js version. Required: {required_node_version}, Found: {node_version}.", 'yellow')
|
||||
exit(1)
|
||||
|
||||
|
||||
# Update npm packages with proper permissions
|
||||
os.system('npm install')
|
||||
|
||||
|
||||
# Set full permissions for /home/cdn-app
|
||||
os.system('chown -R root:root /home/cdn-app')
|
||||
os.system('chmod -R 777 /home/cdn-app')
|
||||
|
||||
# Check and modify file permissions
|
||||
os.system('chmod +x /home/cdn-app/server.js')
|
||||
|
||||
# Save information in the setup.json file
|
||||
with open(setup_file_path, 'w') as file:
|
||||
json.dump(setup_data, file)
|
||||
|
||||
print_with_color(f"Configuration saved in the {setup_file_path} file.", 'green')
|
||||
|
||||
# Create the service
|
||||
create_service()
|
||||
Reference in New Issue
Block a user