This repository was archived by the owner on Jul 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDrupal.java
More file actions
162 lines (131 loc) · 6.42 KB
/
Copy pathDrupal.java
File metadata and controls
162 lines (131 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package profile;
import java.util.Vector;
import core.iface.IUnit;
import core.model.NetworkModel;
import core.model.ServerModel;
import core.profile.AStructuredProfile;
import core.unit.SimpleUnit;
import core.unit.fs.FileEditUnit;
import core.unit.pkg.InstalledUnit;
public class Drupal extends AStructuredProfile {
private Nginx webserver;
private PHP php;
private MariaDB db;
public Drupal(ServerModel me, NetworkModel networkModel) {
super("drupal", me, networkModel);
this.webserver = new Nginx(me, networkModel);
this.php = new PHP(me, networkModel);
this.db = new MariaDB(me, networkModel);
this.db.setUsername("drupal");
this.db.setUserPrivileges("SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES");
this.db.setUserPassword("${DRUPAL_PASSWORD}");
this.db.setDb("drupal");
}
protected Vector<IUnit> getInstalled() {
Vector<IUnit> units = new Vector<IUnit>();
units.addAll(webserver.getInstalled());
units.addAll(php.getInstalled());
units.addAll(db.getInstalled());
units.addElement(new InstalledUnit("ca_certificates", "proceed", "ca-certificates"));
units.addElement(new InstalledUnit("composer", "proceed", "composer"));
units.addElement(new InstalledUnit("curl", "proceed", "curl"));
units.addElement(new InstalledUnit("unzip", "proceed", "unzip"));
units.addElement(new InstalledUnit("php_xml", "php_fpm_installed", "php-xml"));
units.addElement(new InstalledUnit("php_gd", "php_fpm_installed", "php-gd"));
units.addElement(new InstalledUnit("php_mysql", "php_fpm_installed", "php-mysql"));
units.addElement(new InstalledUnit("php_common", "php_fpm_installed", "php-common"));
units.addElement(new InstalledUnit("php_mod_curl", "php_fpm_installed", "php-curl"));
units.addElement(new InstalledUnit("php_mbstring", "php_fpm_installed", "php-mbstring"));
units.addAll(((ServerModel)me).getBindFsModel().addDataBindPoint("drush", "composer_installed", "nginx", "nginx", "0750"));
units.addElement(new SimpleUnit("drush_installed", "composer_installed",
"sudo -u nginx bash -c 'composer create-project drush/drush /media/data/drush -n'",
"sudo [ -f /media/data/drush/drush ] && echo pass || echo fail", "pass", "pass",
"Couldn't install drush. The installation of Drupal will fail."));
return units;
}
protected Vector<IUnit> getPersistentConfig() {
Vector<IUnit> units = new Vector<IUnit>();
units.addAll(webserver.getPersistentConfig());
units.addAll(db.getPersistentConfig());
units.addAll(php.getPersistentConfig());
return units;
}
protected Vector<IUnit> getLiveConfig() {
Vector<IUnit> units = new Vector<IUnit>();
String nginxConf = "";
nginxConf += "server {\n";
nginxConf += " listen *:80 default;\n";
nginxConf += " server_name _;\n";
nginxConf += " root /media/data/www;\n";
nginxConf += " index index.php;\n";
nginxConf += " sendfile off;\n";
nginxConf += " default_type text/plain;\n";
nginxConf += " server_tokens off;\n";
nginxConf += " location / {\n";
nginxConf += " try_files \\$uri @rewrite;\n";
nginxConf += " }\n";
nginxConf += " location @rewrite {\n";
nginxConf += " rewrite ^ /index.php;\n";
nginxConf += " }\n";
nginxConf += " error_page 500 502 503 504 /50x.html;\n";
nginxConf += " location = /50x.html {\n";
nginxConf += " root /usr/share/nginx/html;\n";
nginxConf += " }\n";
nginxConf += " location ~ \\.php\\$ {\n";
nginxConf += " fastcgi_split_path_info ^(.+\\.php)(/.+)\\$;\n";
nginxConf += " fastcgi_pass unix:" + php.getSockPath() + ";\n";
nginxConf += " fastcgi_param SCRIPT_FILENAME \\$document_root\\$fastcgi_script_name;\n";
nginxConf += " fastcgi_index index.php;\n";
nginxConf += " fastcgi_read_timeout 300;\n";
nginxConf += " include fastcgi_params;\n";
nginxConf += " }\n";
nginxConf += " location ~/sites/default/files/civicrm/ConfigAndLog {\n";
nginxConf += " deny all;\n";
nginxConf += " }\n";
nginxConf += " location ~/sites/default/files/civicrm/custom/ {\n";
nginxConf += " deny all;\n";
nginxConf += " }\n";
nginxConf += " location ~/sites/default/files/civicrm/templates_c {\n";
nginxConf += " deny all;\n";
nginxConf += " }\n";
nginxConf += " location ~/sites/default/files/civicrm/upload {\n";
nginxConf += " deny all;\n";
nginxConf += " }\n";
nginxConf += " location ~ /\\.ht {\n";
nginxConf += " deny all;\n";
nginxConf += " }\n";
nginxConf += " include /media/data/nginx_custom_conf_d/default.conf;\n";
nginxConf += "}";
webserver.addLiveConfig("default", nginxConf);
units.addAll(webserver.getLiveConfig());
units.addAll(php.getLiveConfig());
units.addAll(db.getLiveConfig());
units.addElement(new SimpleUnit("drupal_mysql_password", "proceed",
"DRUPAL_PASSWORD=`sudo grep \"password\" /media/data/www/sites/default/settings.php 2>/dev/null | grep -v \"[*#]\" | awk '{ print $3 }' | tr -d \"',\"`; [[ -z $DRUPAL_PASSWORD ]] && DRUPAL_PASSWORD=`openssl rand -hex 32`",
"echo $DRUPAL_PASSWORD", "", "fail",
"Couldn't set a password for Drupal's database user. The installation will fail."));
units.addAll(this.db.checkUserExists());
units.addAll(this.db.checkDbExists());
units.addElement(new SimpleUnit("drupal_installed", "drush_installed",
"sudo /media/data/drush/drush -y dl drupal-7 --destination=/media/data --drupal-project-rename=www"
+ " && sudo /media/data/drush/drush -y -r /media/data/www site-install --db-url=mysql://drupal:${DRUPAL_PASSWORD}@localhost:3306/drupal --account-pass=admin",
"sudo /media/data/drush/drush status -r /media/data/www 2>&1 | grep 'Drupal root'", "", "fail",
"Couldn't install Drupal."));
units.addElement(new FileEditUnit("drupal_base_url", "drupal_installed",
"^\\# \\$base_url = 'http:",
"\\$base_url = 'https:",
"/media/data/www/sites/default/settings.php",
"Couldn't set Drupal's URI to https. This could cause issues with hyperlinks in the installation."));
return units;
}
public Vector<IUnit> getNetworking() {
Vector<IUnit> units = new Vector<IUnit>();
me.addRequiredEgress("drupal.org");
me.addRequiredEgress("packagist.org");
me.addRequiredEgress("api.github.com");
me.addRequiredEgress("github.com");
me.addRequiredEgress("codeload.github.com");
units.addAll(webserver.getNetworking());
return units;
}
}