-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathService_Install.sh
49 lines (44 loc) · 1.32 KB
/
Service_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
# Variables
SERVICE_NAME="NameOfTheService"
SERVICE_PATH="$PWD/NewService"
REQUIRED_PKG="packageName"
installService() {
# Check if service is active
IS_ACTIVE=$(sudo systemctl is-active $SERVICE_NAME)
if [ "$IS_ACTIVE" == "active" ]; then
# Restart the service
echo "Service is running"
echo "Restarting service"
sudo systemctl restart $SERVICE_NAME
echo "Service restarted"
else
# Create service file
echo "Creating service file"
sudo cat > /etc/systemd/system/${SERVICE_NAME}.service << EOF
[Unit]
Description=$SERVICE_NAME service
[Service]
Type=notify
WorkingDirectory=$PWD
ExecStart=$SERVICE_PATH
[Install]
WantedBy=multi-user.target
EOF
# Restart daemon, enable and start service
sudo chmod +x $SERVICE_PATH
echo "Reloading daemon and enabling service"
sudo systemctl daemon-reload
sudo systemctl enable ${SERVICE_NAME//'.service'/} # remove the extension
sudo systemctl start ${SERVICE_NAME//'.service'/} # remove the extension
echo "Service Started"
fi
}
if [[ $1 != "" && $1 == "-f" ]]; then
installService
else
echo "Please install the $REQUIRED_PKG package with the available package manager (like apt, yum etc.)"
read -n 1 -s -r -p "Press any key to continue or run this installer with -f argument to bypass this message"
echo ""
installService
fi
exit 0