-
Notifications
You must be signed in to change notification settings - Fork 6
/
service.sh
executable file
·61 lines (57 loc) · 1.59 KB
/
service.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
#!/bin/bash
SERVICE_NAME=katalon-agent
USER_NAME=katalon-agent
CURRENT_DIR="$(cd "$(dirname "$BASH_SOURCE")"; pwd -P)"
if [[ $2 ]]; then
SERVICE_NAME=$2
fi
case `arch` in
*64*) BIN="cli-linux-x64";;
*) BIN="cli-linux-x86";;
esac
if [[ ${SUDO_USER} ]]; then
USER_NAME=${SUDO_USER}
else
USER_NAME=`whoami`
fi
if [[ $1 == "uninstall" || $1 == "remove" ]]; then
echo Uninstalling Katalon Agent service...
set -x +e
systemctl stop ${SERVICE_NAME}
systemctl disable ${SERVICE_NAME}
rm /etc/systemd/system/${SERVICE_NAME}.service
systemctl daemon-reload
systemctl reset-failed
set +x -e
elif [[ $1 == "install" ]]; then
echo Installing Katalon Agent service...
#useradd -r -m -U -d /opt/${USER_NAME} -s /bin/false ${USER_NAME} || echo "User '${USER_NAME}' already exists."
chown ${USER_NAME}:${USER_NAME} -R ${CURRENT_DIR}
cat >/etc/systemd/system/${SERVICE_NAME}.service <<EOF
[Unit]
Description=Katalon Agent
After=network.target
[Service]
Type=simple
User=${USER_NAME}
ExecStart=${CURRENT_DIR}/${BIN} --service start-agent
UMask=0007
RestartSec=10
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start ${SERVICE_NAME}
systemctl status ${SERVICE_NAME}
systemctl enable ${SERVICE_NAME}
elif [[ $1 == "start" ]]; then
systemctl start ${SERVICE_NAME}
systemctl status ${SERVICE_NAME}
elif [[ $1 == "stop" ]]; then
systemctl stop ${SERVICE_NAME}
systemctl status ${SERVICE_NAME}
else
echo "Command not found"
echo "Usage: service.sh install/remove/start/stop [service_name]"
fi