Created
May 1, 2021 18:37
-
-
Save austonpramodh/0c259692bd2854124a9e314940de125f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| function get_pid { | |
| local PID="$(cat /tmp/pi-fancontrol-bash.pid 2>/dev/null)" | |
| echo $PID | |
| } | |
| function d_start ( ) | |
| { | |
| # check if already started | |
| local pid="$(get_pid)" | |
| if [ ! -z $pid ]; then | |
| echo "service is running; Please stop the service before starting" | |
| exit 1 | |
| fi | |
| echo "Pi Fan Control Bash: starting service" | |
| ./fancontrol-service.sh & | |
| _pid=$! | |
| echo "$_pid" > /tmp/pi-fancontrol-bash.pid | |
| echo "PID is $(cat /tmp/pi-fancontrol-bash.pid)" | |
| } | |
| function d_stop ( ) | |
| { | |
| local pid="$(get_pid)" | |
| if [ -z $pid ]; then | |
| echo "service is not running; Please start the service before stoping" | |
| exit 1 | |
| fi | |
| echo "Pi Fan Control Bash: stopping Service (PID = $(cat /tmp/pi-fancontrol-bash.pid))" | |
| kill $(cat /tmp/pi-fancontrol-bash.pid) | |
| rm /tmp/pi-fancontrol-bash.pid | |
| } | |
| function d_status ( ) | |
| { | |
| ps -ef | grep fancontrol-service.sh | grep -v grep | |
| echo "PID indicate indication file $(cat /tmp/pi-fancontrol-bash.pid 2> /dev/null)" | |
| } | |
| # Management instructions of the service box | |
| case "$1" in | |
| start) | |
| d_start;; | |
| stop) | |
| d_stop;; | |
| status) | |
| d_status;; | |
| *) | |
| echo "Usage: $0 {start | stop | status}" | |
| exit 1;; | |
| esac | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment