Skip to content

Commit

Permalink
Add init.d script for Debian. Requires dpkg >= 1.16.5.
Browse files Browse the repository at this point in the history
This init.d script has configurable parameters. The way I configured
it requires 3 things:

1. A system user called nodejs which has its own group and homedir.
2. A system user called redis-commander which belongs to the nodejs
   group and uses the nodejs homedir.
3. The nodejs homedir MUST have g+w permission so redis-commander
   have permision to write as well.

Below is a step-by-step to get it up and running:

	# useradd --system -m -s /bin/false nodejs
	# useradd --system -d /home/nodejs -G nodejs -s /bin/false \
	  redis-commander
	# chmod g+w /home/nodejs/
	# cp dist/debian/init.d/redis-commander /etc/init.d/
	# chmod +x /etc/init.d/redis-commander
	# update-rc.d redis-commander defaults
	# service redis-commander start
  • Loading branch information
jweyrich committed Jul 1, 2013
1 parent 7ac51d7 commit 02d4c48
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions dist/debian/init.d/redis-commander
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/sh
#
# Written by Jardel Weyrich <jweyrich at gmail dot com>
#
### BEGIN INIT INFO
# Provides: redis-commander
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start Redis Commander (redis-commander)
### END INIT INFO

# Defaults
RUN_MODE="daemons"

# Reads config file (will override defaults above)
#[ -r /etc/default/redis-commander ] && . /etc/default/redis-commander

NAME="redis-commander"
USER="redis-commander"
GROUP="nodejs"
DESC="Redis Commander"
DAEMON="/usr/local/bin/redis-commander"
DAEMONOPTS=""
PIDDIR="/var/run/$NAME"
PIDFILE="$PIDDIR/$NAME.pid"
LOGDIR="/var/log/$NAME"
LOGFILE="$LOGDIR/$NAME.log"

# clear conflicting settings from the environment
unset TMPDIR

# See if the daemons are there
test -x $DAEMON || exit 0

. /lib/lsb/init-functions

case "$1" in
start)
log_daemon_msg "Starting $DESC"
# Make sure we have our PIDDIR and LOGDIR, even if they're on a tmpfs.
install -o root -g root -m 755 -d $PIDDIR
install -o root -g root -m 755 -d $LOGDIR

if [ "$RUN_MODE" != "inetd" ]; then
log_progress_msg "$NAME"
if ! start-stop-daemon --start --quiet --oknodo --chuid "$USER:$GROUP" --background --make-pidfile --pidfile $PIDFILE --no-close --startas $DAEMON -- $DAEMONOPTS >> $LOGFILE 2>&1; then
log_end_msg 1
exit 1
fi
# Change the log permissions.
chown -R $USER:adm /var/log/redis-commander
fi

log_end_msg 0
;;
stop)
log_daemon_msg "Stopping $DESC"

if [ "$RUN_MODE" != "inetd" ]; then
log_progress_msg "$NAME"
start-stop-daemon --stop --quiet --oknodo --retry 10 --pidfile $PIDFILE

# Wait a little and remove stale PID file
sleep 1
if [ -f $PIDFILE ] && ! ps h `cat $PIDFILE` > /dev/null
then
# Stale PID file (process was succesfully stopped).
rm -f $PIDFILE
fi
fi

log_end_msg 0
;;
reload)
if [ "$RUN_MODE" != "inetd" ]; then
log_daemon_msg "Reloading $DESC"

start-stop-daemon --stop --quiet --signal HUP --pidfile $PIDFILE

log_end_msg 0
fi
;;
restart|force-reload)
$0 stop
sleep 1
$0 start
;;
status)
status="0"
if [ "$RUN_MODE" != "inetd" ]; then
status_of_proc -p $PIDFILE $DAEMON $NAME || status=$?
fi
exit $status
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload|status}"
exit 1
;;
esac

exit 0

0 comments on commit 02d4c48

Please sign in to comment.