Env setup creation (#5)
* add env check * Create Ward.run.xml * enable one port and theme fixes * fix edge case * env setup * remove unnecessary check * update docs 2.1.0
This commit is contained in:
parent
b583bbb661
commit
f9a153c5fd
|
@ -2,4 +2,5 @@
|
|||
.idea/
|
||||
target/
|
||||
*.iml
|
||||
.vscode/
|
||||
.vscode/
|
||||
setup.ini
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Ward" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
|
||||
<module name="ward" />
|
||||
<option name="SPRING_BOOT_MAIN_CLASS" value="dev.leons.ward.Ward" />
|
||||
<option name="ALTERNATIVE_JRE_PATH" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
19
README.md
19
README.md
|
@ -8,7 +8,7 @@
|
|||
|
||||
## Docker
|
||||
|
||||
* `docker run --restart unless-stopped -it -d --name ward -p 4000:4000 -p <application port>:<application port> --privileged antonyleons/ward`
|
||||
* `docker run --restart unless-stopped -it -d --name ward -p 4000:4000 -e WARD_PORT=4000 -e WARD_THEME=dark --privileged antonyleons/ward`
|
||||
* Go to localhost:4000 in web browser, input the same application port
|
||||
* If you get error after being redirected to application port try hitting refresh
|
||||
|
||||
|
@ -153,14 +153,18 @@ Ward works nice on all popular operating systems, because it uses [OSHI](https:/
|
|||
|
||||
### Config
|
||||
|
||||
If you want to change Ward's configuration, you can edit `setup.ini`. When using Docker, this file is located within the container at `/`. `setup.ini` is generated once you navigate to Ward's webpage and complete the initial setup. You can also make this file yourself before starting Ward and it will use your configuration.
|
||||
If you want to change Ward's configuration, you can edit `setup.ini`. When using Docker, use the environment variables `WARD_NAME`,`WARD_THEME`, `WARD_PORT` to automatically regenerate this file at startup. Using any environment variable listed will enable the defaults below and immediately start Ward without the GUI setup.
|
||||
|
||||
|
||||
|
||||
| Setting | Description | Default |
|
||||
|------------|------------------------------|---------|
|
||||
| serverName | Name shown in the interface. | |
|
||||
| theme | Either `light` or `dark`. | |
|
||||
| serverName | Name shown in the interface. | Ward |
|
||||
| theme | Either `light` or `dark`. | light |
|
||||
| port | Port to listen on. | 4000 |
|
||||
|
||||
Environment variables take priority and will regenerate this file with your variables. If no environment variables are set, `setup.ini` is generated once you navigate to Ward's webpage and complete the initial setup. You can also make this file yourself before starting Ward, and place it in the same directory.
|
||||
|
||||
For example:
|
||||
```ini
|
||||
[setup]
|
||||
|
@ -168,10 +172,3 @@ serverName = my-server
|
|||
theme = dark
|
||||
port = 8200
|
||||
```
|
||||
|
||||
If you're using Docker and you want to avoid the initial setup or have Ward listen on a different port right away, you could create a `setup.ini` on the host and copy it to the container:
|
||||
```bash
|
||||
docker cp setup.ini ward:/setup.ini
|
||||
```
|
||||
|
||||
Then, just make sure you `docker restart ward`.
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -4,7 +4,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>dev.leons</groupId>
|
||||
<artifactId>ward</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<version>2.1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<!-- parent pom -->
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.leons.ward;
|
||||
|
||||
import dev.leons.ward.services.SetupService;
|
||||
import lombok.Getter;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
@ -16,8 +17,7 @@ import java.io.File;
|
|||
* @version 1.0.4
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class Ward extends SpringBootServletInitializer
|
||||
{
|
||||
public class Ward extends SpringBootServletInitializer {
|
||||
/**
|
||||
* Constant for determine settings file name
|
||||
*/
|
||||
|
@ -44,14 +44,16 @@ public class Ward extends SpringBootServletInitializer
|
|||
*
|
||||
* @param args Spring Boot application arguments
|
||||
*/
|
||||
public static void main(final String[] args)
|
||||
{
|
||||
public static void main(final String[] args) {
|
||||
|
||||
isFirstLaunch = true;
|
||||
configurableApplicationContext = SpringApplication.run(Ward.class, args);
|
||||
|
||||
File setupFile = new File(Ward.SETUP_FILE_PATH);
|
||||
if (setupFile.exists())
|
||||
{
|
||||
|
||||
if (System.getenv("WARD_NAME") != null || (System.getenv("WARD_THEME") != null) || (System.getenv("WARD_PORT") != null)) {
|
||||
SetupService.envSetup();
|
||||
} else if (setupFile.exists()) {
|
||||
restart();
|
||||
}
|
||||
}
|
||||
|
@ -59,8 +61,7 @@ public class Ward extends SpringBootServletInitializer
|
|||
/**
|
||||
* Restarts application
|
||||
*/
|
||||
public static void restart()
|
||||
{
|
||||
public static void restart() {
|
||||
isFirstLaunch = false;
|
||||
ApplicationArguments args = configurableApplicationContext.getBean(ApplicationArguments.class);
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@ import java.io.IOException;
|
|||
* @version 1.0.2
|
||||
*/
|
||||
@Service
|
||||
public class SetupService
|
||||
{
|
||||
public class SetupService {
|
||||
/**
|
||||
* Constant, that providing setup section name
|
||||
*/
|
||||
|
@ -27,12 +26,11 @@ public class SetupService
|
|||
/**
|
||||
* Puts new data in ini file
|
||||
*
|
||||
* @param file ini file
|
||||
* @param file ini file
|
||||
* @param optionName option in section
|
||||
* @throws IOException if file does not exists
|
||||
*/
|
||||
private void putInIniFile(final File file, final String optionName, final String value) throws IOException
|
||||
{
|
||||
private static void putInIniFile(final File file, final String optionName, final String value) throws IOException {
|
||||
Ini ini = new Ini(file);
|
||||
ini.put(SECTION_NAME, optionName, value);
|
||||
ini.store();
|
||||
|
@ -45,30 +43,52 @@ public class SetupService
|
|||
* @return ResponseEntityWrapperAsset filled with ResponseDto
|
||||
* @throws IOException IoException if file is fot found, and cant be created
|
||||
*/
|
||||
public ResponseDto postSetup(final SetupDto setupDto) throws IOException, ApplicationAlreadyConfiguredException
|
||||
{
|
||||
if (Ward.isFirstLaunch())
|
||||
{
|
||||
public ResponseDto postSetup(final SetupDto setupDto) throws IOException, ApplicationAlreadyConfiguredException {
|
||||
if (Ward.isFirstLaunch()) {
|
||||
File file = new File(Ward.SETUP_FILE_PATH);
|
||||
|
||||
if (file.createNewFile())
|
||||
{
|
||||
if (file.createNewFile()) {
|
||||
putInIniFile(file, "serverName", setupDto.getServerName());
|
||||
putInIniFile(file, "theme", setupDto.getTheme());
|
||||
putInIniFile(file, "port", setupDto.getPort());
|
||||
|
||||
Ward.restart();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new IOException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new ApplicationAlreadyConfiguredException();
|
||||
}
|
||||
|
||||
return new ResponseDto("Settings saved correctly");
|
||||
}
|
||||
|
||||
public static ResponseDto envSetup() {
|
||||
if (Ward.isFirstLaunch()) {
|
||||
try {
|
||||
File file = new File(Ward.SETUP_FILE_PATH);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
if (file.createNewFile()) {
|
||||
String servername = (System.getenv("WARD_NAME") != null) ? System.getenv("WARD_NAME") : "Ward";
|
||||
String theme = (System.getenv("WARD_THEME") != null) ? System.getenv("WARD_THEME").toLowerCase() : "light";
|
||||
String port = (System.getenv("WARD_PORT") != null) ? System.getenv("WARD_PORT") : "4000";
|
||||
|
||||
putInIniFile(file, "serverName", servername);
|
||||
putInIniFile(file, "theme", theme);
|
||||
putInIniFile(file, "port", port);
|
||||
|
||||
Ward.restart();
|
||||
} else {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return new ResponseDto("Settings saved correctly");
|
||||
}
|
||||
}
|
|
@ -107,12 +107,12 @@ html[theme = "dark"]
|
|||
--color-logo: var(--white);
|
||||
--color-logo-description: var(--white);
|
||||
--color-label-main-settings: var(--white);
|
||||
--color-main-settings-input: var(--grey);
|
||||
--color-main-settings-input: var(--white);
|
||||
--color-main-settings-input-placeholder: var(--grey-light);
|
||||
--color-label-additional-settings: var(--grey-light);
|
||||
--color-label-additional-settings: var(--white);
|
||||
--color-theme-buttons-input: var(--grey);
|
||||
--color-port: var(--white);
|
||||
--color-port-placeholder: var(--white);
|
||||
--color-port-placeholder: var(--grey-light);
|
||||
--color-submit: var(--white);
|
||||
--color-hw-type: var(--white);
|
||||
--color-hw-name: var(--white);
|
||||
|
|
|
@ -120,18 +120,6 @@ function sendSetupRequest()
|
|||
"port": port.value
|
||||
}
|
||||
|
||||
if (port.value != 4000)
|
||||
{
|
||||
setupXHR.send(JSON.stringify(data));
|
||||
}
|
||||
else
|
||||
{
|
||||
let message =
|
||||
{
|
||||
text: "Choose other port",
|
||||
type: ("")
|
||||
}
|
||||
|
||||
dhtmlx.message(message);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue