|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Manages the script manage_my_process. |
| 3 | +# When passed the argument `start`: |
| 4 | +# 1. Starts manage_my_process |
| 5 | +# 2. Creates a file containings its PID in /var/run/my_process.pid |
| 6 | +# 3. Displays "manage_my_process started" |
| 7 | +# When passed the argument `stop`: |
| 8 | +# 1. Stops manage_my_process |
| 9 | +# 2. Deletes the file /var/run/my_process.pid |
| 10 | +# 3. Displays "manage_my_process stopped" |
| 11 | +# When passed the argument `restart`: |
| 12 | +# 1. Stops manage_my_process |
| 13 | +# 2. Deletes the file /var/run/my_process.pid |
| 14 | +# 3. Starts manage_my_process |
| 15 | +# 4. Creates a file containing its PID in /var/run/my_process.pid |
| 16 | +# 5. Displays "manage_my_process restarted" |
| 17 | +# If any other or no arguments are passed, displays |
| 18 | +#+ "Usage: manage_my_process {start|stop|restart}" |
| 19 | + |
| 20 | +if [ "$1" == "start" ] |
| 21 | +then |
| 22 | + ./manage_my_process & |
| 23 | + echo $$ > /var/run/my_process.pid |
| 24 | + echo "manage_my_process started" |
| 25 | + |
| 26 | +elif [ "$1" == "stop" ] |
| 27 | +then |
| 28 | + kill "$(pgrep -f /manage_my_process)" |
| 29 | + rm /var/run/my_process.pid |
| 30 | + echo "manage_my_process stopped" |
| 31 | + |
| 32 | +elif [ "$1" == "restart" ] |
| 33 | +then |
| 34 | + kill "$(pgrep -f /manage_my_process)" |
| 35 | + rm /var/run/my_process.pid |
| 36 | + ./manage_my_process & |
| 37 | + echo $$ > /var/run/my_process.pid |
| 38 | + echo "manage_my_process restarted" |
| 39 | + |
| 40 | +else |
| 41 | + echo "Usage: manage_my_process {start|stop|restart}" |
| 42 | +fi |
0 commit comments