Commit f206b9f4e7561e1d4fd067af3cadc068bd1c0112
1 parent
517cf132
TB-65: Unix install/upgrade scripts.
Showing
9 changed files
with
270 additions
and
4 deletions
@@ -57,6 +57,21 @@ ospackage { | @@ -57,6 +57,21 @@ ospackage { | ||
57 | into "bin" | 57 | into "bin" |
58 | } | 58 | } |
59 | 59 | ||
60 | + // Copy the install files | ||
61 | + from("target/bin/install/install.sh") { | ||
62 | + fileMode 0775 | ||
63 | + into "bin/install" | ||
64 | + } | ||
65 | + | ||
66 | + from("target/bin/install/upgrade.sh") { | ||
67 | + fileMode 0775 | ||
68 | + into "bin/install" | ||
69 | + } | ||
70 | + | ||
71 | + from("target/bin/install/logback.xml") { | ||
72 | + into "bin/install" | ||
73 | + } | ||
74 | + | ||
60 | // Copy the config files | 75 | // Copy the config files |
61 | from("target/conf") { | 76 | from("target/conf") { |
62 | exclude "${pkgName}.conf" | 77 | exclude "${pkgName}.conf" |
@@ -376,6 +376,29 @@ | @@ -376,6 +376,29 @@ | ||
376 | </configuration> | 376 | </configuration> |
377 | </execution> | 377 | </execution> |
378 | <execution> | 378 | <execution> |
379 | + <id>copy-install</id> | ||
380 | + <phase>process-resources</phase> | ||
381 | + <goals> | ||
382 | + <goal>copy-resources</goal> | ||
383 | + </goals> | ||
384 | + <configuration> | ||
385 | + <outputDirectory>${project.build.directory}/bin/install</outputDirectory> | ||
386 | + <resources> | ||
387 | + <resource> | ||
388 | + <directory>src/main/scripts/install</directory> | ||
389 | + <includes> | ||
390 | + <include>**/*.sh</include> | ||
391 | + <include>**/*.xml</include> | ||
392 | + </includes> | ||
393 | + <filtering>true</filtering> | ||
394 | + </resource> | ||
395 | + </resources> | ||
396 | + <filters> | ||
397 | + <filter>src/main/filters/unix.properties</filter> | ||
398 | + </filters> | ||
399 | + </configuration> | ||
400 | + </execution> | ||
401 | + <execution> | ||
379 | <id>copy-windows-control</id> | 402 | <id>copy-windows-control</id> |
380 | <phase>process-resources</phase> | 403 | <phase>process-resources</phase> |
381 | <goals> | 404 | <goals> |
@@ -395,7 +418,7 @@ | @@ -395,7 +418,7 @@ | ||
395 | </configuration> | 418 | </configuration> |
396 | </execution> | 419 | </execution> |
397 | <execution> | 420 | <execution> |
398 | - <id>copy-data-cql</id> | 421 | + <id>copy-data</id> |
399 | <phase>process-resources</phase> | 422 | <phase>process-resources</phase> |
400 | <goals> | 423 | <goals> |
401 | <goal>copy-resources</goal> | 424 | <goal>copy-resources</goal> |
@@ -404,9 +427,13 @@ | @@ -404,9 +427,13 @@ | ||
404 | <outputDirectory>${project.build.directory}/data</outputDirectory> | 427 | <outputDirectory>${project.build.directory}/data</outputDirectory> |
405 | <resources> | 428 | <resources> |
406 | <resource> | 429 | <resource> |
430 | + <directory>src/main/data</directory> | ||
431 | + </resource> | ||
432 | + <resource> | ||
407 | <directory>../dao/src/main/resources</directory> | 433 | <directory>../dao/src/main/resources</directory> |
408 | <includes> | 434 | <includes> |
409 | <include>**/*.cql</include> | 435 | <include>**/*.cql</include> |
436 | + <include>**/*.sql</include> | ||
410 | </includes> | 437 | </includes> |
411 | <filtering>false</filtering> | 438 | <filtering>false</filtering> |
412 | </resource> | 439 | </resource> |
1 | +-- | ||
2 | +-- Copyright © 2016-2017 The Thingsboard Authors | ||
3 | +-- | ||
4 | +-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | +-- you may not use this file except in compliance with the License. | ||
6 | +-- You may obtain a copy of the License at | ||
7 | +-- | ||
8 | +-- http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | +-- | ||
10 | +-- Unless required by applicable law or agreed to in writing, software | ||
11 | +-- distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | +-- See the License for the specific language governing permissions and | ||
14 | +-- limitations under the License. | ||
15 | +-- | ||
16 | + | ||
1 | DROP MATERIALIZED VIEW IF EXISTS thingsboard.device_by_tenant_and_name; | 17 | DROP MATERIALIZED VIEW IF EXISTS thingsboard.device_by_tenant_and_name; |
2 | DROP MATERIALIZED VIEW IF EXISTS thingsboard.device_by_tenant_and_search_text; | 18 | DROP MATERIALIZED VIEW IF EXISTS thingsboard.device_by_tenant_and_search_text; |
3 | DROP MATERIALIZED VIEW IF EXISTS thingsboard.device_by_tenant_by_type_and_search_text; | 19 | DROP MATERIALIZED VIEW IF EXISTS thingsboard.device_by_tenant_by_type_and_search_text; |
@@ -39,7 +39,7 @@ public class ThingsboardInstallService { | @@ -39,7 +39,7 @@ public class ThingsboardInstallService { | ||
39 | @Value("${install.upgrade:false}") | 39 | @Value("${install.upgrade:false}") |
40 | private Boolean isUpgrade; | 40 | private Boolean isUpgrade; |
41 | 41 | ||
42 | - @Value("${install.upgrade.form_version:1.2.3}") | 42 | + @Value("${install.upgrade.from_version:1.2.3}") |
43 | private String upgradeFromVersion; | 43 | private String upgradeFromVersion; |
44 | 44 | ||
45 | @Value("${install.data_dir}") | 45 | @Value("${install.data_dir}") |
application/src/main/java/org/thingsboard/server/service/install/CassandraDatabaseSchemaService.java
@@ -35,6 +35,7 @@ import java.util.List; | @@ -35,6 +35,7 @@ import java.util.List; | ||
35 | @Slf4j | 35 | @Slf4j |
36 | public class CassandraDatabaseSchemaService implements DatabaseSchemaService { | 36 | public class CassandraDatabaseSchemaService implements DatabaseSchemaService { |
37 | 37 | ||
38 | + private static final String CASSANDRA_DIR = "cassandra"; | ||
38 | private static final String SCHEMA_CQL = "schema.cql"; | 39 | private static final String SCHEMA_CQL = "schema.cql"; |
39 | 40 | ||
40 | @Value("${install.data_dir}") | 41 | @Value("${install.data_dir}") |
@@ -47,7 +48,7 @@ public class CassandraDatabaseSchemaService implements DatabaseSchemaService { | @@ -47,7 +48,7 @@ public class CassandraDatabaseSchemaService implements DatabaseSchemaService { | ||
47 | public void createDatabaseSchema() throws Exception { | 48 | public void createDatabaseSchema() throws Exception { |
48 | log.info("Installing Cassandra DataBase schema..."); | 49 | log.info("Installing Cassandra DataBase schema..."); |
49 | 50 | ||
50 | - Path schemaFile = Paths.get(this.dataDir, SCHEMA_CQL); | 51 | + Path schemaFile = Paths.get(this.dataDir, CASSANDRA_DIR, SCHEMA_CQL); |
51 | loadCql(schemaFile); | 52 | loadCql(schemaFile); |
52 | 53 | ||
53 | } | 54 | } |
@@ -22,20 +22,44 @@ import org.springframework.context.annotation.Profile; | @@ -22,20 +22,44 @@ import org.springframework.context.annotation.Profile; | ||
22 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
23 | import org.thingsboard.server.dao.util.SqlDao; | 23 | import org.thingsboard.server.dao.util.SqlDao; |
24 | 24 | ||
25 | +import java.nio.charset.Charset; | ||
26 | +import java.nio.file.Files; | ||
27 | +import java.nio.file.Path; | ||
28 | +import java.nio.file.Paths; | ||
29 | +import java.sql.Connection; | ||
30 | +import java.sql.DriverManager; | ||
31 | + | ||
25 | @Service | 32 | @Service |
26 | @Profile("install") | 33 | @Profile("install") |
27 | @Slf4j | 34 | @Slf4j |
28 | @SqlDao | 35 | @SqlDao |
29 | public class SqlDatabaseSchemaService implements DatabaseSchemaService { | 36 | public class SqlDatabaseSchemaService implements DatabaseSchemaService { |
30 | 37 | ||
38 | + private static final String SQL_DIR = "sql"; | ||
39 | + private static final String SCHEMA_SQL = "schema.sql"; | ||
40 | + | ||
31 | @Value("${install.data_dir}") | 41 | @Value("${install.data_dir}") |
32 | private String dataDir; | 42 | private String dataDir; |
33 | 43 | ||
44 | + @Value("${spring.datasource.url}") | ||
45 | + private String dbUrl; | ||
46 | + | ||
47 | + @Value("${spring.datasource.username}") | ||
48 | + private String dbUserName; | ||
49 | + | ||
50 | + @Value("${spring.datasource.password}") | ||
51 | + private String dbPassword; | ||
52 | + | ||
34 | @Override | 53 | @Override |
35 | public void createDatabaseSchema() throws Exception { | 54 | public void createDatabaseSchema() throws Exception { |
36 | 55 | ||
37 | log.info("Installing SQL DataBase schema..."); | 56 | log.info("Installing SQL DataBase schema..."); |
38 | - //TODO: | 57 | + |
58 | + Path schemaFile = Paths.get(this.dataDir, SQL_DIR, SCHEMA_SQL); | ||
59 | + try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) { | ||
60 | + String sql = new String(Files.readAllBytes(schemaFile), Charset.forName("UTF-8")); | ||
61 | + conn.createStatement().execute(sql); | ||
62 | + } | ||
39 | 63 | ||
40 | } | 64 | } |
41 | 65 |
1 | +#!/bin/bash | ||
2 | +# | ||
3 | +# Copyright © 2016-2017 The Thingsboard Authors | ||
4 | +# | ||
5 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | +# you may not use this file except in compliance with the License. | ||
7 | +# You may obtain a copy of the License at | ||
8 | +# | ||
9 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | +# | ||
11 | +# Unless required by applicable law or agreed to in writing, software | ||
12 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | +# See the License for the specific language governing permissions and | ||
15 | +# limitations under the License. | ||
16 | +# | ||
17 | + | ||
18 | +while [[ $# -gt 0 ]] | ||
19 | +do | ||
20 | +key="$1" | ||
21 | + | ||
22 | +case $key in | ||
23 | + --loadDemo) | ||
24 | + LOAD_DEMO=true | ||
25 | + shift # past argument | ||
26 | + ;; | ||
27 | + *) | ||
28 | + # unknown option | ||
29 | + ;; | ||
30 | +esac | ||
31 | +shift # past argument or value | ||
32 | +done | ||
33 | + | ||
34 | +if [ "$LOAD_DEMO" == "true" ]; then | ||
35 | + loadDemo=true | ||
36 | +else | ||
37 | + loadDemo=false | ||
38 | +fi | ||
39 | + | ||
40 | +CONF_FOLDER=${pkg.installFolder}/conf | ||
41 | +configfile=${pkg.name}.conf | ||
42 | +jarfile=${pkg.installFolder}/bin/${pkg.name}.jar | ||
43 | +installDir=${pkg.installFolder}/data | ||
44 | + | ||
45 | +source "${CONF_FOLDER}/${configfile}" | ||
46 | + | ||
47 | +run_user=${pkg.name} | ||
48 | + | ||
49 | +su -s /bin/sh -c "java -cp ${jarfile} $JAVA_OPTS -Dloader.main=org.thingsboard.server.ThingsboardInstallApplication \ | ||
50 | + -Dinstall.data_dir=${installDir} \ | ||
51 | + -Dinstall.load_demo=${loadDemo} \ | ||
52 | + -Dspring.jpa.hibernate.ddl-auto=none \ | ||
53 | + -Dinstall.upgrade=false \ | ||
54 | + -Dlogging.config=${pkg.installFolder}/bin/install/logback.xml \ | ||
55 | + org.springframework.boot.loader.PropertiesLauncher" "$run_user" | ||
56 | + | ||
57 | +if [ $? -ne 0 ]; then | ||
58 | + echo "ThingsBoard installation failed!" | ||
59 | +else | ||
60 | + echo "ThingsBoard installed successfully!" | ||
61 | +fi | ||
62 | + | ||
63 | +exit $? |
1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
2 | +<!-- | ||
3 | + | ||
4 | + Copyright © 2016-2017 The Thingsboard Authors | ||
5 | + | ||
6 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
7 | + you may not use this file except in compliance with the License. | ||
8 | + You may obtain a copy of the License at | ||
9 | + | ||
10 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
11 | + | ||
12 | + Unless required by applicable law or agreed to in writing, software | ||
13 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
15 | + See the License for the specific language governing permissions and | ||
16 | + limitations under the License. | ||
17 | + | ||
18 | +--> | ||
19 | +<!DOCTYPE configuration> | ||
20 | +<configuration> | ||
21 | + | ||
22 | + <appender name="fileLogAppender" | ||
23 | + class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
24 | + <file>${pkg.logFolder}/install.log</file> | ||
25 | + <rollingPolicy | ||
26 | + class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> | ||
27 | + <fileNamePattern>${pkg.logFolder}/install.%d{yyyy-MM-dd}.%i.log</fileNamePattern> | ||
28 | + <maxFileSize>100MB</maxFileSize> | ||
29 | + <maxHistory>30</maxHistory> | ||
30 | + <totalSizeCap>3GB</totalSizeCap> | ||
31 | + </rollingPolicy> | ||
32 | + <encoder> | ||
33 | + <pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
34 | + </encoder> | ||
35 | + </appender> | ||
36 | + | ||
37 | + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
38 | + <encoder> | ||
39 | + <pattern>%msg%n</pattern> | ||
40 | + </encoder> | ||
41 | + </appender> | ||
42 | + | ||
43 | + <logger name="org.thingsboard.server.install" level="INFO"> | ||
44 | + <appender-ref ref="STDOUT" /> | ||
45 | + </logger> | ||
46 | + | ||
47 | + <logger name="org.thingsboard.server.service.install" level="INFO"> | ||
48 | + <appender-ref ref="STDOUT" /> | ||
49 | + </logger> | ||
50 | + | ||
51 | + <logger name="org.thingsboard.server" level="INFO" /> | ||
52 | + <logger name="akka" level="INFO" /> | ||
53 | + | ||
54 | + <root level="INFO"> | ||
55 | + <appender-ref ref="fileLogAppender"/> | ||
56 | + </root> | ||
57 | + | ||
58 | +</configuration> |
1 | +#!/bin/bash | ||
2 | +# | ||
3 | +# Copyright © 2016-2017 The Thingsboard Authors | ||
4 | +# | ||
5 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | +# you may not use this file except in compliance with the License. | ||
7 | +# You may obtain a copy of the License at | ||
8 | +# | ||
9 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | +# | ||
11 | +# Unless required by applicable law or agreed to in writing, software | ||
12 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | +# See the License for the specific language governing permissions and | ||
15 | +# limitations under the License. | ||
16 | +# | ||
17 | + | ||
18 | +for i in "$@" | ||
19 | +do | ||
20 | +case $i in | ||
21 | + --fromVersion=*) | ||
22 | + FROM_VERSION="${i#*=}" | ||
23 | + shift | ||
24 | + ;; | ||
25 | + *) | ||
26 | + # unknown option | ||
27 | + ;; | ||
28 | +esac | ||
29 | +done | ||
30 | + | ||
31 | +if [[ -z "${FROM_VERSION// }" ]]; then | ||
32 | + echo "--fromVersion parameter is invalid or unspecified!" | ||
33 | + echo "Usage: upgrade.sh --fromVersion={VERSION}" | ||
34 | + exit 1 | ||
35 | +else | ||
36 | + fromVersion="${FROM_VERSION// }" | ||
37 | +fi | ||
38 | + | ||
39 | +CONF_FOLDER=${pkg.installFolder}/conf | ||
40 | +configfile=${pkg.name}.conf | ||
41 | +jarfile=${pkg.installFolder}/bin/${pkg.name}.jar | ||
42 | +installDir=${pkg.installFolder}/data | ||
43 | + | ||
44 | +source "${CONF_FOLDER}/${configfile}" | ||
45 | + | ||
46 | +run_user=${pkg.name} | ||
47 | + | ||
48 | +su -s /bin/sh -c "java -cp ${jarfile} $JAVA_OPTS -Dloader.main=org.thingsboard.server.ThingsboardInstallApplication \ | ||
49 | + -Dinstall.data_dir=${installDir} \ | ||
50 | + -Dspring.jpa.hibernate.ddl-auto=none \ | ||
51 | + -Dinstall.upgrade=true \ | ||
52 | + -Dinstall.upgrade.from_version=${fromVersion} \ | ||
53 | + -Dlogging.config=${pkg.installFolder}/bin/install/logback.xml \ | ||
54 | + org.springframework.boot.loader.PropertiesLauncher" "$run_user" | ||
55 | + | ||
56 | +if [ $? -ne 0 ]; then | ||
57 | + echo "ThingsBoard upgrade failed!" | ||
58 | +else | ||
59 | + echo "ThingsBoard upgraded successfully!" | ||
60 | +fi | ||
61 | + | ||
62 | +exit $? |