-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock-gen
executable file
·89 lines (78 loc) · 2.41 KB
/
mock-gen
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
#!/usr/bin/env bash
# systemd Service Installer Script
# Directory of this script (absolute path)
DIR=$(dirname $(realpath $0))
service="mock-gen"
# user=$USER # by default run service as user who's installing
user="root" # by default, run service as root (need access to letsencrypt certs and port 443)
# override default user from argument to install command (if supplied)
if [ "$1" == "install" ]; then
[ -n "$2" ] && user=$2
fi
service_file="[Unit]
Description=Mock Generator – Tokens for Climate Care
Documentation=https://github.com/studioprocess/tokens-api-node
After=network.target tokens-api.service
Requires=tokens-api.service
Conflicts=
[Service]
Environment=
Type=simple
User=$user
ExecStart=$DIR/mock-generator.mjs
WorkingDirectory=$DIR
Restart=always
[Install]
WantedBy=multi-user.target
"
usage() {
echo "Usage:"
echo " Install/Uninstall: $0 install [user]|remove|uninstall"
echo " Enable/Disable: $0 enable|disable"
echo " Start/Stop/Restart: $0 start|stop|restart"
echo " Status: $0 status"
echo " Logs: $0 logs"
exit
}
if [ $# -eq 0 ]; then
usage
fi
if [ $1 == "install" ] ; then
echo "[ Installing Script to /usr/local/bin ]"
sudo ln -sf $(realpath $0) /usr/local/bin/$(basename $0)
echo "[ Installing Service File ]"
sudo echo "$service_file" > /etc/systemd/system/${service}.service
echo "[ Enabling Service ]"
sudo systemctl enable $service
echo "Important: Service will be run as user: $user"
elif [ $1 == "remove" ] || [ $1 == "uninstall" ]; then
echo "[ Disabling Service ]"
sudo systemctl disable $service
echo "[ Removing Service File ]"
sudo rm -f /etc/systemd/system/${service}.service
echo "[ Removing Script from /usr/local/bin ]"
sudo rm /usr/local/bin/$(basename $0)
elif [ $1 == "enable" ] ; then
echo "[ Enabling Service ]"
sudo systemctl enable $service
elif [ $1 == "disable" ] ; then
echo "[ Disabling Service ]"
sudo systemctl disable $service
elif [ $1 == "start" ] ; then
echo "[ Starting Service ]"
sudo systemctl start $service
elif [ $1 == "stop" ] ; then
echo "[ Stopping Service ]"
sudo systemctl stop $service
elif [ $1 == "restart" ] ; then
echo "[ Restarting Service ]"
sudo systemctl restart $service
elif [ $1 == "status" ] ; then
echo "[ Service Service ]"
sudo systemctl status $service
elif [ $1 == "logs" ] ; then
echo "[ Service Logs ]"
sudo journalctl -u ${service}.service -e
else
usage
fi