Go daemon
https://github.com/fiorix/go-daemon
Installation
#git clone https://github.com/fiorix/go-daemon
#cd ./go-daemon/
#make
#make install
Example for building service with go daemon
#touch /etc/init.d/AirAdsGoAPI
#vim /etc/init.d/AirAdsGoAPI
#!/bin/sh
#
# chkconfig: - 85 15
# description: Qubot Golang Stati API
# processname: qubot-go-api
# config: /usr/share/nginx/html/go/src/AirAdsGoAPI/conf/app.conf
# pidfile: /var/run/qubot-go-api.pid
#
#
GOPATH=/usr/share/nginx/html/go/
NAME=AirAdsGoAPI
RUNDIR=/usr/share/nginx/html/go/src/AirAdsGoAPI/
SCRIPTNAME=/etc/init.d/$NAME
SERVICE_LOG_FILE=/var/log/$NAME.log-$(date +"%Y%m%d")
PIDFILE=/var/run/$NAME.pid
USER=root
COMMAND_START="god -n -l $SERVICE_LOG_FILE -p $PIDFILE -u $USER -r $RUNDIR ./$NAME "
COMMAND_STOP="kill $(cat $PIDFILE)"
pidfile=${PIDFILE-/var/run/$NAME.pid}
log(){
timenow=`date +%Y-%m-%dT%H:%M:%S.%N`
echo "$timenow: $1"
echo "$timenow: $1" >> $SERVICE_LOG_FILE
}
error_exit(){
log "$1"
exit 1
}
do_start()
{
log "Starting $NAME"
export GOPATH=$GOPATH
$COMMAND_START $DAEMON_START_ARGS || error_exit "Failed in starting $NAME service"
}
do_stop()
{
log "Stopping $NAME"
$COMMAND_STOP $DAEMON_STOP_ARGS || error_exit "Failed in stopping $NAME service"
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
status)
if [ -f /proc/$(cat $PIDFILE)/exe ]; then
echo "$NAME (pid $(cat $PIDFILE)) is running..."
fi
RETVAL=$?
;;
restart|force-reload)
do_stop
do_start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:
#service AirAdsGoAPI start
#service AirAdsGoAPI stop