Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [ci skip] add debian/ubuntu init script. #210

Merged
merged 1 commit into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions contrib/init/debian/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Run gorush in Debian/Ubuntu

## Installation

Put `gorush` binary into `/usr/bin` folder.

```sh
cp gorush /usr/bin/
chmod +x /usr/bin/gorush
```

put `gorush` init script into `/etc/rc.d`

```sh
cp contrib/init/debian/gorush /etc.rc.d/
```

install and remove System-V style init script links

```sh
update-rc.d gorush start 20 2 3 4 5 . stop 80 0 1 6 .
```

## Start service

create gorush configuration file.

```sh
mkdir -p /etc/gorush
cp config/config.yml /etc/gorush/
```

start gorush service.

```sh
/etc/init.d/gorush start
```
87 changes: 87 additions & 0 deletions contrib/init/debian/gorush
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/sh

### BEGIN INIT INFO
# Provides: gorush
# Required-Start: $syslog $network
# Required-Stop: $syslog $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the gorush web server
# Description: starts gorush using start-stop-daemon
### END INIT INFO

# Original Author: Bo-Yi Wu (appleboy)

# Do NOT "set -e"
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="the gorush web server"
NAME=gorush
DAEMON=$(which gorush)

DAEMONUSER=www-data
PIDFILE=/var/run/$NAME.pid
CONFIGFILE=/etc/gorush/config.yml
DAEMONOPTS="-c $CONFIGFILE"

USERBIND="setcap cap_net_bind_service=+ep"
STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/5/KILL/5}"

# 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

# Set the ulimits
ulimit -n 8192

do_start()
{
$USERBIND $DAEMON
sh -c "USER=$DAEMONUSER start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
--background --chuid $DAEMONUSER --exec $DAEMON -- $DAEMONOPTS"
}

do_stop()
{
start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PIDFILE --name $NAME --oknodo
rm -f $PIDFILE
}

do_status()
{
if [ -f $PIDFILE ]; then
if kill -0 $(cat "$PIDFILE"); then
echo "$NAME is running, PID is $(cat $PIDFILE)"
else
echo "$NAME process is dead, but pidfile exists"
fi
else
echo "$NAME is not running"
fi
}

case "$1" in
start)
echo "Starting $DESC" "$NAME"
do_start
;;
stop)
echo "Stopping $DESC" "$NAME"
do_stop
;;
status)
do_status
;;
restart)
echo "Restarting $DESC" "$NAME"
do_stop
do_start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
exit 2
;;
esac

exit 0