generated from NAMEER242/application-manager-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init
executable file
·66 lines (50 loc) · 1.89 KB
/
init
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
#!/usr/bin/env bash
set -e
# Get the directory of the project (application-manager)
APPLICATION_MANAGER_DIR="$(dirname "$(readlink -f "$0")")"
# Load the configuration and common files
. "$APPLICATION_MANAGER_DIR/config.env"
. "$APPLICATION_MANAGER_DIR/common"
# Path to the monitor script
MANAGER_SCRIPT="$APPLICATION_MANAGER_DIR/manager"
# Path to the application linker script
APPLICATION_LINKER="$APPLICATION_MANAGER_DIR/apps_linker"
# systemd service file name and directory
SERVICE_FILE="applications-manager.service"
SERVICE_FILE_DIR="/etc/systemd/system/$SERVICE_FILE"
# Check if the monitor script exists
if [ ! -f "$MANAGER_SCRIPT" ]; then
log "Monitor script not found at $MANAGER_SCRIPT. Please create the script first."
exit 1
fi
# Check if the application linker script exists
if [ ! -f "$APPLICATION_LINKER" ]; then
log "Application linker script not found at $APPLICATION_LINKER. Please create the script first."
exit 1
fi
# Ensure the application-manager folder scripts are executable recursively
sudo chmod +x "$APPLICATION_MANAGER_DIR"
log "Creating systemd service file at $SERVICE_FILE_DIR..."
# Create the systemd service file
echo "================================================="
cat <<EOF | sudo tee "$SERVICE_FILE_DIR"
[Unit]
Description=Monitor applications-manager Directory for Changes and Execute applications manager script on change.
[Service]
ExecStart=$MANAGER_SCRIPT
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
echo "================================================="
# Reload systemd to recognize the new service
sudo systemctl daemon-reload
# Enable and start the service
sudo systemctl enable $SERVICE_FILE
sudo systemctl start $SERVICE_FILE
log "Service $SERVICE_FILE created, enabled, and started."
# run the application linker script
log "running the linker script for the first time..."
sudo $APPLICATION_LINKER
log "Setup complete."