-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathservice-status
104 lines (67 loc) · 1.81 KB
/
service-status
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
100
101
102
103
#https://askubuntu.com/questions/919054/how-do-i-run-a-single-command-at-startup-using-systemd
OS= Ubuntu-18 lts
Place it in /etc/systemd/system folder with say a name of myfirst.service
[Unit]
Description=Spark service
[Service]
ExecStart=/path/to/spark/sbin/start-all.sh
[Install]
WantedBy=multi-user.target
Make that your script executable with:
chmod u+x /path/to/spark/sbin/start-all.sh
Start it:
sudo systemctl start myfirst
Enable it to run at boot:
sudo systemctl enable myfirst
Stop it:
###Service###
#!/bin/bash
#Aurthur="Muhammad Asim"
#Purpose="Jira service stops, when an AMI is taken, to avoid delays restart automation of Jira is done"
ACTIVE=`systemctl status jira | grep -w active | awk '{print $2}'`
START=`systemctl start jira`
echo "$ACTIVE" > /dev/null
if [ "$ACTIVE" = "active" ]
then
#echo $?
echo "Jira is running" > /dev/null
else
echo "$START"
fi
#END
######
Note: Cron-Job you can set for min 5 minutes, but here I want to check the status of service every 5 seconds, so while loop is mentioned below.
#!/bin/bash
while true
do
sleep 5
/root/bash/jira.sh
done
#END
For Centos 7
https://www.writebash.com/advanced-tutorial/make-bash-script-run-as-a-service-in-centos-7-259.html
[Unit]
Description=Getload service - WriteBash demo service in CentOS 7.x
After=network.target
[Service]
Type=simple
PIDFile=/var/run/getload.pid
ExecStart=/bin/sh -c "/opt/getload.sh >>/var/log/getload.log 2>&1"
TimeoutStartSec=0
Restart=on-failure
[Install]
WantedBy=default.target
########################
jira example
[Unit]
Description=Jira Service By Muhammad Asim
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
PIDFile=/var/run/getload.pid
ExecStart=/bin/sh -c "/root/bash/while.sh"
TimeoutStartSec=0
Restart=on-failure
[Install]
WantedBy=multi-user.target