Last active
December 12, 2024 09:02
-
-
Save supersonictw/007bfb79d6c7bbfc7658549d3c52ab60 to your computer and use it in GitHub Desktop.
To control program in shell script.
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/sh | |
| # control_program.sh - To control program in shell script. | |
| # SPDX-License-Identifier: MIT (https://ncurl.xyz/s/o_o6DVqIR) | |
| # https://gist.github.com/supersonictw/007bfb79d6c7bbfc7658549d3c52ab60 | |
| case $2 in | |
| "start" ) | |
| if [ -f "/tmp/.cp_lock-$1" ]; then | |
| echo "The pidfile already exists." | |
| else | |
| nohup $1 2> /dev/null & | |
| echo $! > /tmp/.cp_lock-$1 | |
| fi | |
| ;; | |
| "stop" ) | |
| if [ -f "/tmp/.cp_lock-$1" ]; then | |
| kill `cat /tmp/.cp_lock-$1` | |
| rm /tmp/.cp_lock-$1 | |
| else | |
| echo "The pidfile does not exists." | |
| fi | |
| ;; | |
| * ) | |
| echo "Usage: sh $0 program (start|stop)" | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment