Skip to content

Instantly share code, notes, and snippets.

@hinst
Last active July 2, 2017 13:07
Show Gist options
  • Save hinst/d401626cd7256a850927eff6747aec1a to your computer and use it in GitHub Desktop.
Save hinst/d401626cd7256a850927eff6747aec1a to your computer and use it in GitHub Desktop.
Linux: start, stop executable file as service
#!/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
#!/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