-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmcma
99 lines (95 loc) · 1.93 KB
/
mcma
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
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
# /etc/init.d/mcma
# version 0.5
### BEGIN INIT INFO
# Provides: mcma
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: McMyAdmin server
# Description: Starts the McMyAdmin server
### END INIT INFO
#Settings
#You should only have to edit the username
#I added the others just in case you wanted to
#change something or add startup options such as -nostart.
#NOTE: Under the OPTIONS heading, do not delete the ""
#put the options in them like "-nostart -whatever -else"
#Dont edit above here
USERNAME=minecraft
MCPATH=/home/$USERNAME/McMyAdmin
NAME=McMa
SERVICE=MCMA2_Linux_x86_64
OPTIONS=""
#Dont edit below here
ME=`whoami`
as_user() {
if [ $ME == $USERNAME ] ; then
bash -c "$1"
else
su - $USERNAME -c "$1"
fi
}
mc_start() {
if pgrep -u $USERNAME -f $SERVICE > /dev/null
then
echo "$NAME is already running!"
else
echo "Starting $NAME 10 seconds..."
cd $MCPATH
as_user "cd $MCPATH && screen -dmS $NAME ./$SERVICE $OPTIONS"
sleep 7
if pgrep -u $USERNAME -f $SERVICE > /dev/null
then
echo "$NAME is now running."
else
echo "Error! Could not start $NAME !"
fi
fi
}
mc_stop() {
if pgrep -u $USERNAME -f $SERVICE > /dev/null
then
echo "Stopping $NAME 25 seconds..."
as_user "screen -p 0 -S $NAME -X eval 'stuff \"say SERVER SHUTTING DOWN IN 10 SECONDS. Saving map...\"\015'"
sleep 10
as_user "screen -p 0 -S $NAME -X eval 'stuff \"stop\"\015'"
sleep 5
as_user "screen -p 0 -s $NAME -X eval 'stuff \"/quit\"\015'"
sleep 10
else
echo "$NAME was not running."
fi
if pgrep -u $USERNAME -f $SERVICE > /dev/null
then
echo "Error! $NAME could not be stopped."
else
echo "$NAME is stopped."
fi
}
case "$1" in
start)
mc_start
;;
stop)
mc_stop
;;
restart)
mc_stop
mc_start
;;
status)
if pgrep -u $USERNAME -f $SERVICE > /dev/null
then
echo "$NAME is running."
else
echo "$NAME is not running."
fi
;;
*)
echo "Usage: service mcma {start|stop|status|restart}"
exit 1
;;
esac
exit 0