-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsap
91 lines (77 loc) · 2.25 KB
/
sap
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
#!/bin/sh
### BEGIN INIT INFO
# Provides: sap
# Required-Start: sapinit
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Description: Starts SAP on this system, when restarting or after shutdown
### END INIT INFO
# Script variables
# TODO: Add check if user exists
SAPADMIN="<your user here>"
# Functions
# Starts SAP and initializes logging
startsap() {
# If /var/lock/sap.lock exists, then SAP has been already started or is starting
# Throw message and exit with return code 0
# TODO: Add check if SAP is listening on certain ports
if [ -f /var/lock/sap.lock ]; then
echo "Sap is already starting or has been started, please take a look at /var/log/SAPStart log!"
exit 0
fi
# Initialize log with actual date/time
date > /var/log/SAPStart
# Launch command under SAP admin user and return, because when booting up
# we don't want to wait for SAP to start
su $SAPADMIN -c "startsap >> /var/log/SAPStart" &
# Create the file lock
# TODO: Check return code of previous command
touch /var/lock/sap.lock
}
stopsap() {
# If /var/lock/sap.lock doesn't exist, then SAP has been already stopped
# Throw message and exit with return code 0
# TODO: Add check if SAP is listening on certain ports or not
if [ ! -f /var/lock/sap.lock ]; then
echo "Sap is already stopped, please take a look at /var/log/SAPStop log!"
exit 0
fi
# Initialize log
date > /var/log/SAPStop
# Execute command under SAP admin user and log, we have no problem in waiting for command to finish
su $SAPADMIN -c "stopsap >> /var/log/SAPStop"
# Remove the file lock
# TODO: Check return code of previous command
rm -f /var/lock/sap.lock
}
# Main service
case "$1" in
'restart')
# Check if file exists or not, when exists, do only sapstart function, otherwise do both
if [ ! -f /var/lock/sap.lock ]; then
echo "SAP is not running, starting now!"
startsap
else
echo "Stopping SAP..."
stopsap
echo "Starting SAP..."
startsap
fi
;;
'start')
echo "Starting SAP..."
startsap
;;
'status')
# TODO: Port check
if [ -f /var/lock/sap.lock ]; then
echo "SAP is running!"
else
echo "SAP is NOT running!"
fi
;;
'stop')
echo "Stopping SAP..."
stopsap
;;
esac