Skip to content

Instantly share code, notes, and snippets.

@ScottDillman
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ScottDillman/0ea7978442a372aa36c9 to your computer and use it in GitHub Desktop.
Save ScottDillman/0ea7978442a372aa36c9 to your computer and use it in GitHub Desktop.
Debian init script for Gogs
#!/bin/bash
#/etc/init.d/gogs-service
#
### BEGIN INIT INFO
# Provides: gogs-service
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Gogs service
# Description: init.d script for Gogs service
### END INIT INFO
# XXX - edit these
GOGS_USER="git"
GOGS_USER_HOME="/home/$GOGS_USER"
GOGS_DIR="$GOGS_USER_HOME/go/src/github.com/gogits/gogs"
GOGS_START_SCRIPT="$GOGS_DIR/gogs web"
GOGS_LOG_DIR="$GOGS_DIR/log"
mkdir -p $GOGS_LOG_DIR
start_gogs() {
echo "Starting gogs..."
su - $GOGS_USER -c "nohup $GOGS_START_SCRIPT > $GOGS_LOG_DIR/gogs.log 2>&1 &"
}
# Gogs needs a home path.
export HOME=$GOGS_USER_HOME
# commands
case "$1" in
start)
ps aux | grep 'gogs' | grep -v grep | grep -vq start
if [ $? = 0 ]; then
echo "Gogs is already running."
else
start_gogs
fi
;;
stop)
ps aux | grep 'gogs' | grep -v grep | grep -vq stop
if [ $? = 0 ]; then
echo "Stopping Gogs."
kill `ps -ef | grep 'gogs' | grep -v grep | awk '{print $2}'`
else
echo "Gogs is already stopped."
fi
;;
restart)
ps aux | grep 'gogs' | grep -v grep | grep -vq restart
if [ $? = 0 ]; then
kill `ps -ef | grep 'gogs' | grep -v grep | awk '{print $2}'`
fi
start_gogs
;;
status)
ps aux | grep 'gogs' | grep -v grep | grep -vq status
if [ $? = 0 ]; then
echo "Gogs is running."
else
echo "Gogs is stopped."
fi
;;
*)
echo "Usage: /etc/init.d/gogs-service {start|stop|restart|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment