Last active
July 2, 2017 13:07
-
-
Save hinst/d401626cd7256a850927eff6747aec1a to your computer and use it in GitHub Desktop.
Linux: start, stop executable file as service
This file contains 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 | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
cd $DIR | |
target="caddy" | |
path=$(realpath $target) | |
echo "$target control: $1" | |
if [ "$1" = "start" ] | |
then | |
nohup $path 2>>error-log.txt 1>>output-log.txt & | |
fi | |
if [ "$1" == "stop" ] | |
then | |
pid=$(pidof $path) | |
if [[ $? == 0 ]] | |
then | |
kill -s SIGINT $pid | |
while kill -s 0 $pid | |
do | |
sleep 1 | |
done | |
echo stopped | |
else | |
echo probably not running | |
fi | |
fi |
This file contains 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 | |
### BEGIN INIT INFO | |
# Provides: caddy | |
# Required-Start: $local_fs $network | |
# Required-Stop: $local_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: caddy | |
# Description: Caddy Go Web server | |
### END INIT INFO | |
/sbin/runuser hinst -s /bin/bash -c "/bin/bash /home/hinst/ufd/App/caddy/assuming-control.sh $1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment