aboutsummaryrefslogtreecommitdiff
path: root/scripts/init
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/init')
-rw-r--r--scripts/init/centos/gogs92
-rw-r--r--scripts/init/debian/gogs124
2 files changed, 216 insertions, 0 deletions
diff --git a/scripts/init/centos/gogs b/scripts/init/centos/gogs
new file mode 100644
index 00000000..90469498
--- /dev/null
+++ b/scripts/init/centos/gogs
@@ -0,0 +1,92 @@
+#!/bin/sh
+#
+# /etc/rc.d/init.d/gogs
+#
+# Runs the Gogs Go Git Service.
+#
+#
+# chkconfig: - 85 15
+#
+
+### BEGIN INIT INFO
+# Provides: gogs
+# Required-Start: $remote_fs $syslog
+# Required-Stop: $remote_fs $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Start gogs at boot time.
+# Description: Control gogs.
+### END INIT INFO
+
+# Source function library.
+. /etc/init.d/functions
+
+# Default values
+
+NAME=gogs
+GOGS_HOME=/home/git/gogs
+GOGS_PATH=${GOGS_HOME}/$NAME
+GOGS_USER=git
+SERVICENAME="Gogs Go Git Service"
+PID=/var/run/$NAME.pid
+LOCKFILE=/var/lock/subsys/gogs
+LOGFILE=${GOGS_HOME}/log/gogs.log
+RETVAL=0
+
+# Read configuration from /etc/sysconfig/gogs to override defaults
+[ -r /etc/sysconfig/$NAME ] && ./etc/sysconfig/$NAME
+
+# Don't do anything if nothing is installed
+[ -x ${GOGS_PATH} ] || exit 0
+
+DAEMON_OPTS=""
+
+# Set additional options, if any
+[ ! -z "$GOGS_USER" ] && DAEMON_OPTS="$DAEMON_OPTS --user=${GOGS_USER}"
+
+start() {
+ cd ${GOGS_HOME}
+ echo -n "Starting ${SERVICENAME}: "
+ daemon $DAEMON_OPTS --pidfile=${PID} "${GOGS_PATH} web 2>&1 > ${LOGFILE} &"
+ echo $! > ${PID}
+ RETVAL=$?
+ echo
+ [ $RETVAL = 0 ] && touch ${LOCKFILE}
+
+ return $RETVAL
+}
+
+stop() {
+ cd ${GOGS_HOME}
+ echo -n "Shutting down ${SERVICENAME}: "
+ killproc -p ${PID} ${NAME}
+ RETVAL=$?
+ echo
+ [ $RETVAL = 0 ] && rm -f ${LOCKFILE} ${PID}
+}
+
+case "$1" in
+ start)
+ status ${NAME} > /dev/null 2>&1 && exit 0
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ status)
+ status -p ${PID} ${NAME}
+ ;;
+ restart)
+ stop
+ start
+ ;;
+ reload)
+ stop
+ start
+ ;;
+ *)
+ echo "Usage: ${NAME} {start|stop|status|restart}"
+ exit 1
+ ;;
+esac
+exit $RETVAL
diff --git a/scripts/init/debian/gogs b/scripts/init/debian/gogs
new file mode 100644
index 00000000..13e8b8aa
--- /dev/null
+++ b/scripts/init/debian/gogs
@@ -0,0 +1,124 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides: gogs
+# Required-Start: $syslog $network
+# Required-Stop: $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: A self-hosted Git service written in Go.
+# Description: A self-hosted Git service written in Go.
+### END INIT INFO
+
+# Author: Danny Boisvert
+
+# Do NOT "set -e"
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="Go Git Service"
+NAME=gogs
+SERVICEVERBOSE=yes
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+WORKINGDIR=/home/git/gogs
+DAEMON=$WORKINGDIR/$NAME
+DAEMON_ARGS="web"
+USER=git
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
+# and status_of_proc is working.
+. /lib/lsb/init-functions
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+ # Return
+ # 0 if daemon has been started
+ # 1 if daemon was already running
+ # 2 if daemon could not be started
+ sh -c "start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
+ --exec $DAEMON -- $DAEMON_ARGS --test > /dev/null \\
+ || return 1"
+ sh -c "start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
+ --background --exec /bin/su -- - $USER -c \"cd \\\"$WORKINGDIR\\\" && $DAEMON -- $DAEMON_ARGS\" \\
+ || return 2"
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+ # Return
+ # 0 if daemon has been stopped
+ # 1 if daemon was already stopped
+ # 2 if daemon could not be stopped
+ # other if a failure occurred
+ start-stop-daemon --stop --quiet --retry=TERM/1/KILL/5 --pidfile $PIDFILE --name $NAME
+ RETVAL="$?"
+ [ "$RETVAL" = 2 ] && return 2
+ start-stop-daemon --stop --quiet --oknodo --retry=0/1/KILL/5 --exec $DAEMON
+ [ "$?" = 2 ] && return 2
+ # Many daemons don't delete their pidfiles when they exit.
+ rm -f $PIDFILE
+ return "$RETVAL"
+}
+
+
+case "$1" in
+ start)
+ [ "$SERVICEVERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+ do_start
+ case "$?" in
+ 0|1) [ "$SERVICEVERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$SERVICEVERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+ stop)
+ [ "$SERVICEVERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1) [ "$SERVICEVERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$SERVICEVERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+ status)
+ status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
+ ;;
+ restart|force-reload)
+ log_daemon_msg "Restarting $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1)
+ do_start
+ case "$?" in
+ 0) log_end_msg 0 ;;
+ 1) log_end_msg 1 ;; # Old process is still running
+ *) log_end_msg 1 ;; # Failed to start
+ esac
+ ;;
+ *)
+ # Failed to stop
+ log_end_msg 1
+ ;;
+ esac
+ ;;
+ *)
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+ exit 3
+ ;;
+esac
+
+: