Skip to content

Instantly share code, notes, and snippets.

@supersonictw
Last active April 26, 2024 12:22
Show Gist options
  • Save supersonictw/007bfb79d6c7bbfc7658549d3c52ab60 to your computer and use it in GitHub Desktop.
Save supersonictw/007bfb79d6c7bbfc7658549d3c52ab60 to your computer and use it in GitHub Desktop.
To control program in shell
#!/bin/sh
# control_program.sh
# To control program in shell
# License: MIT (https://ncurl.xyz/s/RD0Yl5fSg)
# 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