-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-service
executable file
·62 lines (47 loc) · 1.62 KB
/
install-service
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
#!/bin/bash
# Link, enable and start systemd service unit file for bedrock server instance
# Usage: ./install-service <instance name>
#
# <instance name>
# Name of the instance that will be installed. This argument
# will be converted to lowercase and it's whitespace trimmed.
# Script arguments.
instance_name=$1
# Abort if script is not running as root.
if ! [ $(id -u) = 0 ]; then
echo "This script must be run as root."
exit 1
fi
# Abort if sytemd service unit file is not present.
instance_name="$(echo "$instance_name" | awk '{print tolower($0)}')"
instance_name="$(echo -e "${instance_name}" | tr -d '[[:space:]]')"
unit_file="instances/${instance_name}/mcbs-${instance_name}.service"
if [ ! -f $unit_file ]; then
echo "Unit file is not present, cannot install service."
exit 1
fi
# Stop and disable service if /etc/systemd/system/mcbs-<instance_name>.service exists
service_name="mcbs-${instance_name}"
unit_file_destiny="/etc/systemd/system/${service_name}.service"
if [ -f $unit_file_destiny ]; then
systemctl stop $service_name
systemctl disable $service_name
fi
# Copy systemd unit file to /etc/systemd/system/
cp --remove-destination $unit_file $unit_file_destiny
echo "Copied mcbs-${instance_name}.service to /etc/systemd/system/"
echo ""
echo "Bedrock Server instance service install completed."
echo ""
echo "To start the service, run:"
echo ""
echo " systemctl start ${service_name}"
echo ""
echo "To enable the service(to start on boot), run:"
echo ""
echo " systemctl enable ${service_name}"
echo ""
echo "To verify the service status, run:"
echo ""
echo " systemctl status ${service_name}"
echo ""