dskaggs / vagrant-centos-lucee

Vagrant box for local development with CFML and Java
MIT License
17 stars 13 forks source link

Add fakeSMTP server to install #9

Closed dskaggs closed 7 years ago

dskaggs commented 8 years ago

Ref: https://github.com/Ortus-Solutions/vagrant-centos-lucee/blob/master/vagrant/provisioners/install-fakesmtp.sh

dswitzer commented 8 years ago

I like maildev a lot. Here's what I'm using in another CentOS Vagrant project:

#!/bin/sh
#
# from: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-a-centos-7-server
echo "Installing NodeJS..."

# install EPEL (Extra Packages for Enterprise Linux) repository, which has the nodejs package
yum -y install epel-release
# install NodeJS
yum -y install nodejs

echo "Installing NPM..."

# install NPM
yum -y install npm

echo "... finished!"

# from: http://djfarrelly.github.io/MailDev/
echo "Installing MailDev..."

# install MailDev
npm install --loglevel error -g maildev > /dev/null

# install "forever" to run NodeJS apps in the background
npm install --loglevel error -g forever > /dev/null

# copy the init.d script
\cp --force /vagrant/.vagrant-files/files/os/etc/init.d/maildev /etc/init.d/maildev

# make the init script executable
chmod 0755 /etc/init.d/maildev

# ad the script to start up on reboot
/sbin/chkconfig --level 345 maildev on
# start the service
/etc/init.d/maildev start

echo "... finished!"
dskaggs commented 8 years ago

@dswitzer Thanks for the suggestion. I'll definitely check that out for my development workflow. I've been looking for something to run locally on my Mac and this might be it. I'll try it out there and then see about getting it into the Vagrant project.

dswitzer commented 8 years ago

It's very slick. It's been pretty rock solid in my experience. Nice UI and just works. You can download the EML file if you want to view it in another mail client or see exactly what the message source looks like.

dswitzer commented 8 years ago

Oh, and here's the /etc/init.d/maildev script:

#!/bin/bash
#
# from: https://www.exratione.com/2011/07/running-a-nodejs-server-as-a-service-using-forever/
#
# Service script for a Node.js application running under Forever.
#
# This is suitable for Fedora, Red Hat, CentOS and similar distributions.
# It will not work on Ubuntu or other Debian-style distributions!
#
# There is some perhaps unnecessary complexity going on in the relationship between
# Forever and the server process. See: https://github.com/indexzero/forever
#
# 1) Forever starts its own watchdog process, and keeps its own configuration data
# in /var/run/forever.
#
# 2) If the process dies, Forever will restart it: if it fails but continues to run,
# it won't be restarted.
#
# 3) If the process is stopped via this script, the pidfile is left in place; this
# helps when issues happen with failed stop attempts.
#
# 4) Which means the check for running/not running is complex, and involves parsing
# of the Forever list output.
#
# chkconfig: 345 80 20
# description: my application description
# processname: my_application_name
# pidfile: /var/run/my_application_name.pid
# logfile: /var/log/my_application_name.log
#

# Source function library.
. /etc/init.d/functions

NAME=maildev
SOURCE_DIR=/usr/lib/node_modules/maildev/bin/
SOURCE_FILE=maildev
OPTIONS="--smtp 25 --web 1080 --outgoing-secure"

user=vagrant
pidfile=/var/run/$NAME.pid
logfile=/var/log/$NAME.log
forever_dir=/usr/bin/forever

node=node
forever=forever
sed=sed

export PATH=$PATH:/home/node/local/node/bin
export NODE_PATH=$NODE_PATH:/home/node/local/node/lib/node_modules

start() {
  echo "Starting $NAME node instance: "

  if [ "$foreverid" == "" ]; then
    # Create the log and pid files, making sure that
    # the target use has access to them
    touch $logfile
    chown $user $logfile

    touch $pidfile
    chown $user $pidfile

    # Launch the application
    daemon --user=root \
      $forever start -p $forever_dir --pidFile $pidfile -l $logfile \
      -a -d $SOURCE_DIR/$SOURCE_FILE $OPTIONS
    RETVAL=$?
  else
    echo "Instance already running"
    RETVAL=0
  fi
}

stop() {
  echo -n "Shutting down $NAME node instance : "
  read id < $pidfile

  if [ "$id" != "" ]; then
    $forever stop $id
  else
    echo "Instance is not running";
  fi
  RETVAL=$?
}

if [ -f $pidfile ]; then
  read pid < $pidfile
else
  pid=""
fi

if [ "$pid" != "" ]; then
  # Gnarly sed usage to obtain the foreverid.
  sed1="/$pid]/p"
  sed2="s/.*[([0-9]+)].*s$pid.*/1/g"
  foreverid=`$forever list -p $forever_dir | $sed -n $sed1 | $sed $sed2`
else
  foreverid=""
fi

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status -p ${pidfile}
    ;;
  *)
    echo "Usage:  {start|stop|status}"
    exit 1
    ;;
esac
exit $RETVAL