-
Notifications
You must be signed in to change notification settings - Fork 1
/
service.sh
executable file
·49 lines (38 loc) · 1.05 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
set -evu
if [ $# -ne 2 ]; then
echo "USAGE: $0 name command"
exit 1
fi
ubuntu_home=/home/ubuntu
# Set the service name
service_name=$1
# Set the command
service_command=$2
# Setting runit to run $service_name...
mkdir -p /etc/service/$service_name/log
cat <<EOS > /etc/service/$service_name/run
#!/bin/sh
exec 2>&1
. /etc/profile
. $ubuntu_home/.profile
exec $service_command
EOS
chmod +x /etc/service/$service_name/run
# Setting up runit logging...
mkdir -p $ubuntu_home/logs/$service_name
cat <<EOS > /etc/service/$service_name/log/run
#!/bin/sh
exec svlogd -tt $ubuntu_home/logs/$service_name
EOS
chmod +x /etc/service/$service_name/log/run
# Waiting for runit to recognize the new service...
while [ ! -d /etc/service/$service_name/supervise ]; do
sleep 5 && echo "waiting..."
done
sleep 1
# Turning off the server until the first deploy...
sv stop $service_name
> $ubuntu_home/logs/$service_name/current
# Giving the ubuntu user the ability to control the service...
chown -R ubuntu /etc/service/$service_name/supervise
chown -R ubuntu $ubuntu_home/logs