-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaemon_laucher.sh
58 lines (49 loc) · 893 Bytes
/
daemon_laucher.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
50
51
52
53
54
55
56
57
58
daemon_name=mock_daemon.sh
daemonPID=0
start_daemon() {
get_proc
if [ ! -z "$daemonPID" ]
then
echo " Daemon: $mock_daemon is already running with PID: $daemonPID"
else
echo "Starting Daemon: $daemon_name ..."
(sh $daemon_name &) &
get_proc
echo "Successfully started with PID: $daemonPID"
fi
}
stop_daemon() {
echo "Stopping Daemon"
pkill -f $daemon_name
}
restart_daemon() {
echo "Restarting Mock Daemon"
stop_daemon
run_daemon
}
daemon_status() {
get_proc
echo "Daemon $daemon_name is running with PID $daemonPID"
}
get_proc(){
daemonPID=$(pgrep -f $daemon_name)
}
action="$1" # Action to execute
case "$action" in
start)
start_daemon
;;
stop)
stop_daemon
;;
restart)
restart_daemon
;;
status)
daemon_status
;;
*)
echo "Actions: [start|stop|restart|status|run]"
exit 1
;;
esac