Skip to content

Commit cbea37d

Browse files
committed
Initial commit
0 parents  commit cbea37d

File tree

5 files changed

+157
-0
lines changed

5 files changed

+157
-0
lines changed

build-rascal2.py

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/python
2+
3+
import os
4+
import pip
5+
import subprocess
6+
import sys
7+
import threading
8+
9+
INSTALLATION_TOOLS = [
10+
'sh'
11+
]
12+
13+
PYTHON_MODULES_TO_INSTALL = [
14+
'gevent',
15+
'gevent-websocket',
16+
'Flask-uWSGI-WebSocket',
17+
'redis',
18+
'uwsgi',
19+
'pytronics',
20+
'bitstring',
21+
'webcolors',
22+
'Flask-Login'
23+
]
24+
25+
DEBIAN_PACKAGES_TO_INSTALL = [
26+
'nginx',
27+
'python-flask',
28+
'supervisor',
29+
'zsh'
30+
]
31+
32+
DEBIAN_PACKAGES_TO_REMOVE = [
33+
'apache2',
34+
'apache2-mpm-worker',
35+
'apache2-utils',
36+
'apache2.2-bin',
37+
'apache2.2-common',
38+
'nodejs',
39+
'xscreensaver',
40+
'xscreensaver-data',
41+
'xserver-xorg-core',
42+
'xserver-common'
43+
'libgtk2.0-common', # probably breaks OpenCV
44+
'libgtk-3-common' # removes Gstreamer and Numpy
45+
]
46+
47+
BONESCRIPT_SERVICES = [
48+
'cloud9.service',
49+
'gateone.service',
50+
'gdm.service',
51+
'bonescript.service',
52+
'bonescript.socket',
53+
'bonescript-autorun.service'
54+
]
55+
56+
class RepeatingTimer(threading._Timer):
57+
def run(self):
58+
while True:
59+
self.finished.wait(self.interval)
60+
if self.finished.is_set():
61+
return
62+
else:
63+
self.function(*self.args, **self.kwargs)
64+
65+
def status():
66+
sys.stdout.write('* ')
67+
sys.stdout.flush()
68+
69+
def install_tools():
70+
for module in INSTALLATION_TOOLS:
71+
pip.main(['install', module])
72+
73+
def install_python_modules():
74+
for module in PYTHON_MODULES_TO_INSTALL:
75+
pip.main(['install', module])
76+
77+
def install_debian_packages():
78+
for package in DEBIAN_PACKAGES_TO_INSTALL:
79+
timer = RepeatingTimer(1.0, status)
80+
timer.daemon = True # Allows program to exit if only the thread is alive
81+
timer.start()
82+
proc = subprocess.Popen('apt-get install -y '+ package, shell=True, stdin=None, stdout=open(os.devnull,"wb"), stderr=STDOUT, executable="/bin/bash")
83+
proc.wait()
84+
timer.cancel()
85+
86+
def disable_bonescript():
87+
print "Disabling Bonescript . . ."
88+
for service in BONESCRIPT_SERVICES:
89+
sh.systemctl('disable', service)
90+
91+
def remove_unneeded_debian_packages():
92+
for package in DEBIAN_PACKAGES_TO_REMOVE:
93+
timer = RepeatingTimer(1.0, status)
94+
timer.daemon = True # Allows program to exit if only the thread is alive
95+
timer.start()
96+
proc = subprocess.Popen('apt-get remove -y '+ package, shell=True, stdin=None, stdout=open(os.devnull,"wb"), stderr=STDOUT, executable="/bin/bash")
97+
proc.wait()
98+
timer.cancel()
99+
# then apt-get autoremove?
100+
101+
def install_rascal_software():
102+
sh.git.clone('https://github.com/rascalmicro/red.git', '/var/www/editor')
103+
sh.git.clone('https://github.com/rascalmicro/demos.git', '/var/www/public')
104+
sh.touch('/var/log/uwsgi/public.log')
105+
sh.touch('/var/log/uwsgi/emperor.log')
106+
sh.touch('/var/log/uwsgi/editor.log')
107+
sh.chown('-R', 'www-data', '/var/log/uwsgi')
108+
sh.chgrp('-R', 'www-data', '/var/log/uwsgi')
109+
110+
sh.rm('rf', '/var/www/editor/static/codemirror')
111+
sh.wget('https://github.com/marijnh/CodeMirror/archive/4.2.0.tar.gz')
112+
sh.tar('xzvf', '4.2.0.tar.gz')
113+
sh.mv('CodeMirror-4.2.0/', '/var/www/editor/static/codemirror')
114+
115+
sh.systemctl('enable', 'nginx.service')
116+
117+
def main():
118+
install_tools()
119+
import sh
120+
disable_bonescript()
121+
remove_unneeded_debian_packages()
122+
install_debian_packages()
123+
install_python_modules()
124+
install_rascal_software()

editor.ini

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[uwsgi]
2+
socket = 127.0.0.1:5001
3+
logto = /var/log/uwsgi/editor.log
4+
processes = 1
5+
env = PYTHONPATH=$PYTHONPATH:/var/www
6+
wsgi-file = /var/www/editor
7+
callable = editor

emperor.ini

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[uwsgi]
2+
emperor = /etc/uwsgi/vassals
3+
logto = /var/log/uwsgi/emperor.log
4+
uid = www-data
5+
gid = www-data

public.ini

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[uwsgi]
2+
socket = 127.0.0.1:5000
3+
logto = /var/log/uwsgi/public.log
4+
processes = 1
5+
env = PYTHONPATH=$PYTHONPATH:/var/www
6+
wsgi-file = /var/www/public
7+
callable = public
8+
catch-exceptions = True

uwsgi.service

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=uWSGI Emperor
3+
After=syslog.target
4+
5+
[Service]
6+
ExecStart=/usr/local/bin/uwsgi --ini /etc/uwsgi/emperor.ini
7+
Restart=always
8+
KillSignal=SIGQUIT
9+
Type=notify
10+
NotifyAccess=main
11+
12+
[Install]
13+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)