-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·100 lines (76 loc) · 2.56 KB
/
install.sh
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
# Variables (customize these)
SERVICE_NAME="ppman" # Replace with your service name
EXECUTABLE_PATH="" # Replace with the absolute path to your executable
USER="" # Replace with the user to run the service
GROUP="nogroup" # Replace with the group to run the service
# Check if the script is run as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root. Exiting."
exit 1
fi
# Create the systemd service file
SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service"
echo "Creating systemd service file at $SERVICE_FILE..."
cat <<EOF > "$SERVICE_FILE"
[Unit]
Description=$SERVICE_NAME
After=network.target
[Service]
ExecStart=$EXECUTABLE_PATH
Restart=always
User=$USER
Group=$GROUP
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=$(dirname "$EXECUTABLE_PATH")
[Install]
WantedBy=multi-user.target
EOF
# Set permissions for the service file
chmod 644 "$SERVICE_FILE"
echo "Systemd service file created successfully."
# Reload systemd configuration
systemctl daemon-reload
# Enable the service to start on boot
systemctl enable "$SERVICE_NAME"
echo "Service $SERVICE_NAME enabled to start on boot."
# Start the service
systemctl start "$SERVICE_NAME"
echo "Service $SERVICE_NAME started."
# Check service status
systemctl status "$SERVICE_NAME" --no-pager
# #!/bin/bash
# # BROKEN DO NOT USE UNTIL FIXED :)
# # Get the current directory of the script
# SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# # Determine the execution path based on the existence of the binary, favour release if found.
# if [ -f "$SCRIPT_DIR/target/release/ppman-daemon" ]; then
# EXEC_PATH="$SCRIPT_DIR/target/release/ppman-daemon"
# elif [ -f "$SCRIPT_DIR/target/debug/ppman-daemon" ]; then
# EXEC_PATH="$SCRIPT_DIR/target/debug/ppman-daemon"
# else
# echo "Error: ppman-daemon binary not found in target/release or target/debug."
# exit 1
# fi
# SERVICE_FILE_CONTENT="[Unit]
# Description=PPMan Daemon
# After=network.target
# [Service]
# ExecStart=$EXEC_PATH
# Restart=always
# User=nobody
# Group=nogroup
# Environment=RUST_LOG=info
# StandardOutput=file:/var/log/ppman.log
# StandardError=file:/var/log/ppman.log
# [Install]
# WantedBy=multi-user.target"
# # Create the systemd service file
# echo "$SERVICE_FILE_CONTENT" | sudo tee /etc/systemd/system/ppman.service > /dev/null
# # Reload systemd to recognize the new service file
# sudo systemctl daemon-reload
# # Enable the service to start on boot
# sudo systemctl enable ppman.service
# # Start the service
# sudo systemctl start ppman.service