-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path101-manage_my_process
More file actions
executable file
·42 lines (38 loc) · 1.29 KB
/
Copy path101-manage_my_process
File metadata and controls
executable file
·42 lines (38 loc) · 1.29 KB
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
#!/usr/bin/env bash
# Manages the script manage_my_process.
# When passed the argument `start`:
# 1. Starts manage_my_process
# 2. Creates a file containings its PID in /var/run/my_process.pid
# 3. Displays "manage_my_process started"
# When passed the argument `stop`:
# 1. Stops manage_my_process
# 2. Deletes the file /var/run/my_process.pid
# 3. Displays "manage_my_process stopped"
# When passed the argument `restart`:
# 1. Stops manage_my_process
# 2. Deletes the file /var/run/my_process.pid
# 3. Starts manage_my_process
# 4. Creates a file containing its PID in /var/run/my_process.pid
# 5. Displays "manage_my_process restarted"
# If any other or no arguments are passed, displays
#+ "Usage: manage_my_process {start|stop|restart}"
if [ "$1" == "start" ]
then
./manage_my_process &
echo $$ > /var/run/my_process.pid
echo "manage_my_process started"
elif [ "$1" == "stop" ]
then
kill "$(pgrep -f /manage_my_process)"
rm /var/run/my_process.pid
echo "manage_my_process stopped"
elif [ "$1" == "restart" ]
then
kill "$(pgrep -f /manage_my_process)"
rm /var/run/my_process.pid
./manage_my_process &
echo $$ > /var/run/my_process.pid
echo "manage_my_process restarted"
else
echo "Usage: manage_my_process {start|stop|restart}"
fi