summaryrefslogtreecommitdiff
path: root/microservices/03-resource-server/linux/deb/package/DEBIAN/postinst
blob: 247d43040ccb87eda2d1e66e923fb03d453591f1 (plain)
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
#!/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/ceit-fs-resource-server: Set home directory of user
  # ceit-fs-resource-server: Username
  useradd -r -s /sbin/nologin -d /var/lib/ceit-fs-resource-server ceit-fs-resource-server || true

fi

# Set directory ownership and permissions - Application jar file not to be read by other system users
chown -R root:ceit-fs-resource-server /opt/ceit/ceit-fs-resource-server
chmod 755 /opt/ceit
chmod 750 /opt/ceit/ceit-fs-resource-server
chmod 750 /opt/ceit/ceit-fs-resource-server/app
chmod 640 /opt/ceit/ceit-fs-resource-server/app/ceit-fs-resource-server.jar

# Set directory ownership and permissions - Config files not to be read by other system users
chown -R root:ceit-fs-resource-server /etc/ceit-fs-resource-server
chmod 750 /etc/ceit-fs-resource-server
chmod 640 /etc/ceit-fs-resource-server/application.yaml
chmod 640 /etc/ceit-fs-resource-server/environment.env

if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
        if [ -d /run/systemd/system ]; then
                # Reload systemd service configurations
                systemctl daemon-reload > /dev/null || true

                if [ -n "$2" ]; then
			# Upgrade
                        # Restart service
			if systemctl is-enabled ceit-fs-resource-server > /dev/null; then
                              systemctl start ceit-fs-resource-server
			fi
                else
			# First install (not upgrade)
                        # Enable service to start at boot time 
                        systemctl enable ceit-fs-resource-server
			# Start service
                        systemctl start ceit-fs-resource-server
                fi
        fi
fi

if [ "$1" == "configure" ] && [ -z "$2" ]; then
        # Code here executes only during package install (but not during upgrade)
        echo "[INFO] ceit-fs-resource-server service installed."
        echo "[INFO] Update /etc/ceit-fs-resource-server/application.yaml to update the configuration."
        echo "[INFO] By default, TCP port 8085 is used by the installed server."
        echo "[INFO] To allow access from remote systems, you may have to enable firewall for example by running:"
        echo "[INFO]   ufw allow 8085/tcp"
fi