Skip to content

Instantly share code, notes, and snippets.

@bunam
Forked from Bouhnosaure/mailcatcher.sh
Last active March 30, 2016 15:14
Show Gist options
  • Save bunam/ec2ad6353786555c5b01c791630507ca to your computer and use it in GitHub Desktop.
Save bunam/ec2ad6353786555c5b01c791630507ca to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# mailcatcher This shell script takes care of starting and stopping
# the mailcatcher fake/dev mail server.
# -> adduser mailcatcher
# -> chkconfig mailcatcher on
# chkconfig: - 64 36
# description: stop and start mailcatcher fake mail server
# processname: mailcatcher
# config: /etc/mailcatcher.cnf
# pidfile: /var/run/mysqld/mysqld.pid
### BEGIN INIT INFO
# Provides: mailcatcher
# Required-Start: $local_fs $remote_fs $network $named $syslog $time
# Required-Stop: $local_fs $remote_fs $network $named $syslog $time
# Short-Description: stop and start mailcatcher fake mail server
# Description: mailcatcher fake/dev mail server
### END INIT INFO
# Source function library.
. /etc/init.d/functions
. /etc/sysconfig/network
# Check that networking is configured.
[ ${NETWORKING} = "no" ] && exit 0
base=${0##*/}
NAME=mailcatcher
PROG="/usr/bin/env mailcatcher"
USER=mailcatcher
GROUP=mailcatcher
HTTP_PORT=1080
SMTP_PORT=1025
[ -e /etc/mailcatcher.cnf ] && . /etc/mailcatcher.cnf
getPID () {
PID=`ps --no-headers -eo "%p%a" | grep -e '[0-9]*[ ]ruby[ ].*mailcatcher' | awk '{print $1}'`
if [ "$PID" != "" ] ; then
return 0
fi
return 1
}
start() {
echo -n $"Starting $base"
getPID
RETVAL=$?
if [ $RETVAL = 0 ]; then
echo " : already running."
exit 1
fi
su - $USER -s /bin/bash -c "$PROG --http-ip=0.0.0.0 --http-port=$HTTP_PORT --smtp-port=$SMTP_PORT &> /dev/null"
RETVAL=$?
if [ $RETVAL = 0 ]; then
success $"$base startup"
else
failure $"$base startup"
fi
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $base"
getPID
RETVAL=$?
if [ $RETVAL = 0 ]; then
kill $PID
RETVAL=$?
success $""
else
failure $""
fi
echo
return $?
}
restart() {
stop
sleep 1
start
}
status () {
echo -n $"$base is : "
getPID
RETVAL=$?
if [ $RETVAL = 0 ]; then
echo $"started"
else
echo $"stoped"
fi
return $?
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment