summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--linux/deb/02-fs-spring-boot-kamal/.gitignore1
-rw-r--r--linux/deb/02-fs-spring-boot-kamal/README39
-rwxr-xr-xlinux/deb/02-fs-spring-boot-kamal/build.sh36
-rw-r--r--linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/conffiles1
-rw-r--r--linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/control8
-rwxr-xr-xlinux/deb/02-fs-spring-boot-kamal/package/DEBIAN/postinst47
-rwxr-xr-xlinux/deb/02-fs-spring-boot-kamal/package/DEBIAN/preinst8
-rw-r--r--linux/deb/02-fs-spring-boot-kamal/package/etc/fs-spring-boot-kamal/application.yaml6
-rw-r--r--linux/deb/02-fs-spring-boot-kamal/package/etc/fs-spring-boot-kamal/environment.env2
-rw-r--r--linux/deb/02-fs-spring-boot-kamal/package/etc/systemd/system/fs-spring-boot-kamal.service12
-rw-r--r--linux/deb/02-fs-spring-boot-kamal/package/opt/fs-spring-boot-kamal/app/.gitignore1
11 files changed, 161 insertions, 0 deletions
diff --git a/linux/deb/02-fs-spring-boot-kamal/.gitignore b/linux/deb/02-fs-spring-boot-kamal/.gitignore
new file mode 100644
index 0000000..c00df13
--- /dev/null
+++ b/linux/deb/02-fs-spring-boot-kamal/.gitignore
@@ -0,0 +1 @@
+*.deb
diff --git a/linux/deb/02-fs-spring-boot-kamal/README b/linux/deb/02-fs-spring-boot-kamal/README
new file mode 100644
index 0000000..aaf92bc
--- /dev/null
+++ b/linux/deb/02-fs-spring-boot-kamal/README
@@ -0,0 +1,39 @@
+This directory contains everything to build a deb package that bundles a Spring Boot app that starts a web server.
+
+The Spring Boot application has not been bundled with this. You need to build it seperately and put it in the correct directory (run build.sh for further details).
+
+To build, run the following command:
+
+ ./build.sh
+
+To install the build deb package run the following commands replacing the package.deb with the correct name of the deb file.
+
+ cp package.deb /tmp
+ cd /tmp
+ apt install ./package.deb
+
+The above "apt install" will download dependencies if needed. Otherwise, dpkg command can just be used to install or upgrade the package:
+
+ dpkg -i package.deb
+
+After installing the package, update the configuration file /etc/fs-spring-boot-kamal/application.yaml .
+
+Enable service to start at boot time:
+
+ systemctl enable fs-spring-boot-kamal
+
+Start service:
+
+ systemctl start fs-spring-boot-kamal
+
+View service log:
+
+ journalctl -u fs-spring-boot-kamal -f
+
+ (Press CTRL+C to terminate log viewing)
+
+Access the service:
+
+ http://server-ip-or-hostname:8085/
+
+ (Instead of 8085, use the port configured in application.yaml file)
diff --git a/linux/deb/02-fs-spring-boot-kamal/build.sh b/linux/deb/02-fs-spring-boot-kamal/build.sh
new file mode 100755
index 0000000..bd2fc95
--- /dev/null
+++ b/linux/deb/02-fs-spring-boot-kamal/build.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# Define a function that sends messages to stderr.
+errcho() {
+ echo "$@" 1>&2;
+}
+
+# Check if fakeroot command is available
+if ! command -v fakeroot > /dev/null 2>&1; then
+ errcho "[ERROR] fakeroot command not found. Install the fakeroot package.";
+ exit 1
+fi
+
+# Check if dpkg-deb command is available
+if ! command -v dpkg-deb > /dev/null 2>&1; then
+ errcho "[ERROR] dpkg-deb command not found. dpkg package contains it. Are you not running this script on a Debian based system?";
+ exit 1
+fi
+
+# Get the directory of this script
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+# Check if the spring boot jar is in the correct location
+if [ ! -f $DIR/package/opt/fs-spring-boot-kamal/app/fs-spring-boot-kamal.jar ]; then
+ errcho "[ERROR] Jar file missing: $DIR/package/opt/fs-spring-boot-kamal/app/fs-spring-boot-kamal.jar"
+ errcho "[ERROR] Run this build script only after placing the jar file in that location."
+ exit 1
+fi
+
+# Remove the deb files found inside DIR. Prompt the user before deleting.
+if ls $DIR/*.deb 1> /dev/null 2>&1; then
+ rm -i $DIR/*.deb
+fi
+
+# Build the deb package
+fakeroot dpkg-deb --build $DIR/package $DIR
diff --git a/linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/conffiles b/linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/conffiles
new file mode 100644
index 0000000..5c70b47
--- /dev/null
+++ b/linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/conffiles
@@ -0,0 +1 @@
+/etc/fs-spring-boot-kamal/application.yaml
diff --git a/linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/control b/linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/control
new file mode 100644
index 0000000..ffeee3f
--- /dev/null
+++ b/linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/control
@@ -0,0 +1,8 @@
+Package: fs-spring-boot-kamal
+Version: 1.0.0-1
+Section: httpd
+Priority: optional
+Architecture: all
+Depends: openjdk-25-jre | temurin-25-jre | openjdk-25-jdk | temurin-25-jdk
+Maintainer: Kamal Wickramanayake <info@software.lk>
+Description: A demo Debian package that bundles a Spring Boot application.
diff --git a/linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/postinst b/linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/postinst
new file mode 100755
index 0000000..19eec59
--- /dev/null
+++ b/linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/postinst
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# Stop on error
+set -e
+
+if [ "$1" == "configure" ] && [ -z "$2" ]; then
+ # Code here executes only during package install (but not during upgrade)
+
+ # Create a system user
+ # -r: System user
+ # -s /sbin/nologin: Prevent the user from logging into the system interactively
+ # -d /var/lib/fs-spring-boot-kamal: Set home directory of user
+ # fs-spring-boot-kamal: Username
+ useradd -r -s /sbin/nologin -d /var/lib/fs-spring-boot-kamal fs-spring-boot-kamal || true
+
+fi
+
+# Set directory ownership and permissions - Application jar file not to be read by other system users
+chown -R root:fs-spring-boot-kamal /opt/fs-spring-boot-kamal
+chmod 750 /opt/fs-spring-boot-kamal
+chmod 750 /opt/fs-spring-boot-kamal/app
+chmod 640 /opt/fs-spring-boot-kamal/app/fs-spring-boot-kamal.jar
+
+# Set directory ownership and permissions - Config files not to be read by other system users
+chown -R root:fs-spring-boot-kamal /etc/fs-spring-boot-kamal
+chmod 750 /etc/fs-spring-boot-kamal
+chmod 640 /etc/fs-spring-boot-kamal/application.yaml
+chmod 640 /etc/fs-spring-boot-kamal/environment.env
+
+# Reload systemd service configurations
+systemctl daemon-reload
+
+# Enable service as boot time
+#systemctl enable fs-spring-boot-kamal
+
+# Restart service
+#systemctl restart fs-spring-boot-kamal
+
+echo "[INFO] fs-spring-boot-kamal service installed."
+echo "[INFO] Update /etc/fs-spring-boot-kamal/application.yaml to update the configuration."
+echo "[INFO] By default, TCP port 8085 is used by the installed server."
+echo "[INFO] To enable service start at boot time:"
+echo "[INFO] systemctl enable fs-spring-boot-kamal"
+echo "[INFO] To start the service if not running:"
+echo "[INFO] systemctl start fs-spring-boot-kamal"
+echo "[INFO] To allow access from remote systems, you may have to enable firewall for example by running:"
+echo "[INFO] ufw allow 8085/tcp"
diff --git a/linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/preinst b/linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/preinst
new file mode 100755
index 0000000..61c2587
--- /dev/null
+++ b/linux/deb/02-fs-spring-boot-kamal/package/DEBIAN/preinst
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+set -e
+
+# Put commands that should execute before the pckage is installed.
+
+# Example: Just print a message
+echo "preinst script running..."
diff --git a/linux/deb/02-fs-spring-boot-kamal/package/etc/fs-spring-boot-kamal/application.yaml b/linux/deb/02-fs-spring-boot-kamal/package/etc/fs-spring-boot-kamal/application.yaml
new file mode 100644
index 0000000..772cbcc
--- /dev/null
+++ b/linux/deb/02-fs-spring-boot-kamal/package/etc/fs-spring-boot-kamal/application.yaml
@@ -0,0 +1,6 @@
+server:
+ address: 0.0.0.0
+ port: 8085
+
+# Configurations like database connection details can follow.
+
diff --git a/linux/deb/02-fs-spring-boot-kamal/package/etc/fs-spring-boot-kamal/environment.env b/linux/deb/02-fs-spring-boot-kamal/package/etc/fs-spring-boot-kamal/environment.env
new file mode 100644
index 0000000..5423533
--- /dev/null
+++ b/linux/deb/02-fs-spring-boot-kamal/package/etc/fs-spring-boot-kamal/environment.env
@@ -0,0 +1,2 @@
+# Which Spring profile should be active?
+#SPRING_PROFILES_ACTIVE=prod
diff --git a/linux/deb/02-fs-spring-boot-kamal/package/etc/systemd/system/fs-spring-boot-kamal.service b/linux/deb/02-fs-spring-boot-kamal/package/etc/systemd/system/fs-spring-boot-kamal.service
new file mode 100644
index 0000000..58a592c
--- /dev/null
+++ b/linux/deb/02-fs-spring-boot-kamal/package/etc/systemd/system/fs-spring-boot-kamal.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=fs-spring-boot-kamal
+
+[Service]
+User=fs-spring-boot-kamal
+EnvironmentFile=/etc/fs-spring-boot-kamal/environment.env
+ExecStart=/usr/bin/java -Dspring.config.import=optional:file:/etc/fs-spring-boot-kamal/application.yaml -jar /opt/fs-spring-boot-kamal/app/fs-spring-boot-kamal.jar
+Restart=always
+RestartSec=30
+
+[Install]
+WantedBy=multi-user.target
diff --git a/linux/deb/02-fs-spring-boot-kamal/package/opt/fs-spring-boot-kamal/app/.gitignore b/linux/deb/02-fs-spring-boot-kamal/package/opt/fs-spring-boot-kamal/app/.gitignore
new file mode 100644
index 0000000..d392f0e
--- /dev/null
+++ b/linux/deb/02-fs-spring-boot-kamal/package/opt/fs-spring-boot-kamal/app/.gitignore
@@ -0,0 +1 @@
+*.jar