Working on python version
This commit is contained in:
parent
9ae0c66f73
commit
f69fea4256
|
@ -0,0 +1,4 @@
|
|||
deploy.sh
|
||||
secret*
|
||||
secret_files*
|
||||
ssh.sh
|
26
README.md
26
README.md
|
@ -1,2 +1,24 @@
|
|||
# peach-vps
|
||||
# simple-ansible-template
|
||||
# peach-vps config
|
||||
|
||||
Code for configuring the peachcloud vps for various hosting and automation
|
||||
- debian repository of microservices
|
||||
- mdbook builder for devdocs
|
||||
|
||||
|
||||
# setup
|
||||
```
|
||||
apt update
|
||||
apt install git python python3-pip rsync
|
||||
git clone https://github.com/peachcloud/peach-vps.git
|
||||
cd peach-vps
|
||||
pip3 install -r requirements.txt
|
||||
python peach_vps_scripts/setup_vps.py
|
||||
```
|
||||
|
||||
|
||||
# update
|
||||
(for more frequent updates that don't involve the whole initial setup)
|
||||
```
|
||||
cd peach-vps
|
||||
python peach_vps_scripts/update_vps.py
|
||||
```
|
|
@ -1,39 +0,0 @@
|
|||
from peach_vps_scripts.utils import render_template, cargo_install
|
||||
from peach_vps_scripts.vars import VARS
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
|
||||
print("[ UPDATING OPERATING SYSTEM ]")
|
||||
subprocess.call(["apt-get", "update", "-y"])
|
||||
subprocess.call(["apt-get", "upgrade", "-y"])
|
||||
|
||||
print("[ INSTALLING SYSTEM REQUIREMENTS ]")
|
||||
subprocess.call(["apt-get", "install", "git", "nginx", "curl", "build-essential", "mosh"])
|
||||
|
||||
print("[ CREATING SYSTEM GROUPS ]")
|
||||
subprocess.call(["/usr/sbin/groupadd", "peach"])
|
||||
|
||||
print("[ ADDING SYSTEM USER ]")
|
||||
users = ["notplants", "glyph"]
|
||||
for user in users:
|
||||
subprocess.call(["/usr/sbin/adduser", user])
|
||||
subprocess.call(["usermod", "-aG", "sudo", user])
|
||||
subprocess.call(["/usr/sbin/usermod", "-a", "-G", user, "peach"])
|
||||
|
||||
print("[ CREATING DIRECTORIES ]")
|
||||
folders = [VARS["src_dir"], VARS["www_dir"], VARS["debian_repo_dir"]]
|
||||
for folder in folders:
|
||||
if not os.path.exists(folder):
|
||||
os.makedirs(folder)
|
||||
|
||||
print("[ INSTALLING RUST ]")
|
||||
subprocess.call(["curl", "https://sh.rustup.rs", "-sSf", "|", "sh", "-s", "--", "-y"])
|
||||
|
||||
print("[ INSTALLING CARGO PACKAGES ]")
|
||||
cargo_install("cargo-deb")
|
||||
|
||||
render_template(src='nginx/nginx.conf', dest='/etc/nginx/nginx.conf')
|
||||
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
from utils import render_template, cargo_install
|
||||
from vars import VARS
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
import pwd
|
||||
import grp
|
||||
|
||||
|
||||
print("[ UPDATING OPERATING SYSTEM ]")
|
||||
subprocess.check_call(["apt-get", "update", "-y"])
|
||||
subprocess.check_call(["apt-get", "upgrade", "-y"])
|
||||
|
||||
print("[ INSTALLING SYSTEM REQUIREMENTS ]")
|
||||
subprocess.check_call(["apt-get", "install", "git", "nginx", "curl", "build-essential", "mosh"])
|
||||
|
||||
print("[ CREATING SYSTEM GROUPS ]")
|
||||
group = 'peach'
|
||||
try:
|
||||
grp.getgrnam(group)
|
||||
# if group exists
|
||||
except KeyError:
|
||||
# if group doesn't eixst
|
||||
subprocess.check_call(["/usr/sbin/groupadd", "peach"])
|
||||
|
||||
print("[ ADDING SYSTEM USER ]")
|
||||
users = ["notplants", "glyph"]
|
||||
for user in users:
|
||||
try:
|
||||
# if user exists
|
||||
pwd.getpwnam(user)
|
||||
except:
|
||||
# if user does not exist
|
||||
subprocess.check_call(["/usr/sbin/adduser", user])
|
||||
subprocess.check_call(["usermod", "-aG", "sudo", user])
|
||||
subprocess.check_call(["/usr/sbin/usermod", "-a", "-G", user, "peach"])
|
||||
|
||||
print("[ CREATING DIRECTORIES ]")
|
||||
folders = [VARS["src_dir"], VARS["web_dir"], VARS["debian_rep_dir"]]
|
||||
for folder in folders:
|
||||
if not os.path.exists(folder):
|
||||
os.makedirs(folder)
|
||||
|
||||
print("[ INSTALLING RUST ]")
|
||||
if os.path.exists('/root/.cargo/bin/rustc'):
|
||||
first_command = subprocess.Popen(["curl", "https://sh.rustup.rs", "-sSf"], stdout=subprocess.PIPE)
|
||||
output = subprocess.check_output(["sh", "-s", "--", "-y"], stdin=first_command.stdout)
|
||||
first_command.wait()
|
||||
|
||||
print("[ INSTALLING CARGO PACKAGES ]")
|
||||
cargo_install("cargo-deb")
|
||||
|
||||
render_template(src='nginx/nginx.conf', dest='/etc/nginx/nginx.conf')
|
||||
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
from peach_vps_scripts.vars import VARS
|
||||
from vars import VARS
|
||||
|
||||
import os
|
||||
import jinja2
|
||||
import subprocess
|
||||
|
||||
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
|
||||
PROJECT_PATH = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||
print('PROJECT_PATH: {}'.format(PROJECT_PATH))
|
||||
|
||||
template_path = os.path.join(PROJECT_PATH, 'templates')
|
||||
template_path = os.path.join(PROJECT_PATH, 'conf/templates')
|
||||
template_loader = jinja2.FileSystemLoader(searchpath=template_path)
|
||||
template_env = jinja2.Environment(loader=template_loader)
|
||||
|
||||
|
@ -19,7 +20,10 @@ def render_template(src, dest, template_vars=None):
|
|||
:return: None
|
||||
"""
|
||||
template = template_env.get_template(src)
|
||||
template_vars.update(VARS)
|
||||
if template_vars:
|
||||
template_vars.update(VARS)
|
||||
else:
|
||||
template_vars = VARS
|
||||
output_text = template.render(template_vars=template_vars)
|
||||
if os.path.exists(dest):
|
||||
os.remove(dest)
|
Loading…
Reference in New Issue