9
9
import datetime
10
10
from base64 import b64encode , urlsafe_b64encode
11
11
import random
12
+ from pathlib import Path
12
13
13
14
app = Flask (__name__ )
14
15
# Load .env settings
@@ -33,6 +34,9 @@ def deploy():
33
34
# Create directory for site
34
35
try :
35
36
dstDir = app .config ['SITES_DIRECTORY' ] + webaddress + '/'
37
+ if Path (dstDir ).exists ():
38
+ print ("Site {} already exists. Exiting..." .format (webaddress ))
39
+ exit ()
36
40
os .mkdir (dstDir )
37
41
file .save (os .path .join (dstDir , filename + '.yaml' ))
38
42
# Rename to jamla.yaml
@@ -127,32 +131,22 @@ def deploy():
127
131
for icon in request .files .getlist ('icons' ):
128
132
iconFilename = secure_filename (icon .filename )
129
133
icon .save (os .path .join (static_folder , iconFilename ))
130
- # Append new site to apache config
131
- vhost = " " .join (["Use VHost" , webaddress , app .config ['APACHE_USER' ], dstDir ])
132
- ssl = " " .join (["Use SSL" , webaddress , '443' , app .config ['APACHE_USER' ], dstDir ])
133
- #Verify Vhost isn't already present
134
- try :
135
- fp = open (app .config ['APACHE_CONF_FILE' ], "a+" )
136
- for line in fp :
137
- if webaddress in line :
138
- fp .close ()
139
- raise
140
134
141
- fp = open (app .config ['APACHE_CONF_FILE' ], "a+" )
142
- fp .write (vhost + "\n " )
143
- fp .write (ssl + "\n " )
144
- fp .close ()
145
- except :
146
- print ("Skipping as " + webaddress + "already exists." )
147
- pass
135
+ # Begin uwsgi vassal config creation
136
+ # Open application skeleton (app.skel) file and append
137
+ # "subscribe-to = <website-hostname>" config entry for the new
138
+ # sites webaddress so that uwsgi's fastrouter can route the hostname.
139
+ curDir = os .path .dirname (os .path .realpath (__file__ ))
140
+ with open (curDir + '/' + 'app.skel' ) as f :
141
+ contents = f .read ()
142
+ # Append uwsgi's subscribe-to line with hostname of new site:
143
+ contents += "\n subscribe-to = /tmp/sock2:" + webaddress + "\n "
144
+ # Writeout app.ini config to file. uwsgi watches for .ini files
145
+ # uwsgi will automatically detect this .ini file and start
146
+ # routing requests to the site
147
+ with open (dstDir + '/' + 'app.ini' , 'w' ) as f :
148
+ f .write (contents )
148
149
149
- try :
150
- # Reload apache with new vhost
151
- subprocess .call ("sudo /etc/init.d/apache2 graceful" , shell = True )
152
- except Exception as e :
153
- print ("Problem reloading apache:" )
154
- print (e )
155
- pass
156
150
login_url = '' .join (['https://' , webaddress , '/#/' , login_token ])
157
151
158
152
return login_url
0 commit comments