From 5e48c89c5eee43eee76c6b5c906b720ea986285f Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Mon, 29 Sep 2014 10:41:29 +0200 Subject: Add a CentOS init script --- scripts/init/centos/gogs | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 scripts/init/centos/gogs (limited to 'scripts/init') diff --git a/scripts/init/centos/gogs b/scripts/init/centos/gogs new file mode 100644 index 00000000..41c56d75 --- /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=${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 -- cgit v1.2.3 From d95e7065d95adf2001fc1b0a9ecf114a0d2095fa Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Mon, 29 Sep 2014 10:43:51 +0200 Subject: s/USER/GOGS_USER/g --- scripts/init/centos/gogs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/init') diff --git a/scripts/init/centos/gogs b/scripts/init/centos/gogs index 41c56d75..90469498 100644 --- a/scripts/init/centos/gogs +++ b/scripts/init/centos/gogs @@ -42,7 +42,7 @@ RETVAL=0 DAEMON_OPTS="" # Set additional options, if any -[ ! -z "$GOGS_USER" ] && DAEMON_OPTS="$DAEMON_OPTS --user=${USER}" +[ ! -z "$GOGS_USER" ] && DAEMON_OPTS="$DAEMON_OPTS --user=${GOGS_USER}" start() { cd ${GOGS_HOME} -- cgit v1.2.3 From f7de6d2b86e7e56a46d2763800760ac16ae363d3 Mon Sep 17 00:00:00 2001 From: Danny B Date: Mon, 29 Sep 2014 21:52:45 -0400 Subject: Added "init.d" service script for Debian-based Linux. Compatible with "/etc/default/gogs" configuration file for adding or overwriting values. Based on "/etc/init.d/skeleton" and tested on Raspbian 2014-06-20 (Debian 7.5 [Wheezy] ARM) [TO FIX] For some reason, it's necessary to remove the value of RUN_USER from the app.ini configuration file because the following error occurs: 2014/09/28 18:12:53 [setting.go:182 NewConfigContext()] [E] Expect user(git) but current user is: --- scripts/init/debian/gogs | 129 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 scripts/init/debian/gogs (limited to 'scripts/init') diff --git a/scripts/init/debian/gogs b/scripts/init/debian/gogs new file mode 100644 index 00000000..b82df1de --- /dev/null +++ b/scripts/init/debian/gogs @@ -0,0 +1,129 @@ +#! /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 + +# Prepare the starting daemon command depending on available non-mandatory variables +STARTDEAMONEVALOPTS="" +[ ! -z "$USER" ] && STARTDEAMONEVALOPTS="$STARTDEAMONEVALOPTS --chuid $USER " +[ ! -z "$WORKINGDIR" ] && STARTDEAMONEVALOPTS="$STARTDEAMONEVALOPTS --chdir \"$WORKINGDIR\" " + +# 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 \\ + $STARTDEAMONEVALOPTS --exec $DAEMON -- $DAEMON_ARGS --test > /dev/null \\ + || return 1" + sh -c "start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\ + $STARTDEAMONEVALOPTS --background --exec $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/10/KILL/5 --pidfile $PIDFILE --name $NAME + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + start-stop-daemon --stop --quiet --oknodo --retry=0/10/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 + +: -- cgit v1.2.3 From 98c719c342d796e4e651270ca4a43523df721251 Mon Sep 17 00:00:00 2001 From: Danny B Date: Tue, 30 Sep 2014 21:30:16 -0400 Subject: Debian's Init.d workaround for loading user's environment variables with `start-stop-daemon` command. Implies 2 running child, so the `stop` command usually needs a `KILL` instead of a `TERM` to close properly so I reduced it to 1 second to get quickly with the `KILL` signal. --- scripts/init/debian/gogs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'scripts/init') diff --git a/scripts/init/debian/gogs b/scripts/init/debian/gogs index b82df1de..13e8b8aa 100644 --- a/scripts/init/debian/gogs +++ b/scripts/init/debian/gogs @@ -31,11 +31,6 @@ USER=git # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 -# Prepare the starting daemon command depending on available non-mandatory variables -STARTDEAMONEVALOPTS="" -[ ! -z "$USER" ] && STARTDEAMONEVALOPTS="$STARTDEAMONEVALOPTS --chuid $USER " -[ ! -z "$WORKINGDIR" ] && STARTDEAMONEVALOPTS="$STARTDEAMONEVALOPTS --chdir \"$WORKINGDIR\" " - # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh @@ -54,10 +49,10 @@ do_start() # 1 if daemon was already running # 2 if daemon could not be started sh -c "start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\ - $STARTDEAMONEVALOPTS --exec $DAEMON -- $DAEMON_ARGS --test > /dev/null \\ + --exec $DAEMON -- $DAEMON_ARGS --test > /dev/null \\ || return 1" sh -c "start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\ - $STARTDEAMONEVALOPTS --background --exec $DAEMON -- $DAEMON_ARGS \\ + --background --exec /bin/su -- - $USER -c \"cd \\\"$WORKINGDIR\\\" && $DAEMON -- $DAEMON_ARGS\" \\ || return 2" } @@ -71,10 +66,10 @@ do_stop() # 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/10/KILL/5 --pidfile $PIDFILE --name $NAME + 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/10/KILL/5 --exec $DAEMON + 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 -- cgit v1.2.3