Skip to content

Instantly share code, notes, and snippets.

@socketz
Last active January 12, 2019 12:02
Show Gist options
  • Save socketz/b370bfe0331f868b6bd9e6a878096575 to your computer and use it in GitHub Desktop.
Save socketz/b370bfe0331f868b6bd9e6a878096575 to your computer and use it in GitHub Desktop.
Service configuration for Mailcatcher Daemon (https://github.com/sj26/mailcatcher) on systemd and init.d path. Put files in /etc/systemd/system/mailcatcher.service and /etc/init.d/mailcatcher. If you choose the mailcatcher.conf option, do not need other files, put this file in /etc/init/mailcatcher.conf.
#!/bin/sh
# Start/stop the mailcatcher daemon.
#
### BEGIN INIT INFO
# Provides: mailcatcher
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Should-Start: $local_fs $remote_fs $network $syslog $named
# Should-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Black hole mail server
# Description: Catches mail and serves it through a dream.
# MailCatcher runs a super simple SMTP server which catches
# any message sent to it to display in a web interface.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="mailcatcher daemon"
NAME=mailcatcher
DAEMON=/usr/sbin/mailcatcher
PIDFILE=/var/run/mailcatcherd.pid
SCRIPTNAME=/etc/init.d/"$NAME"
test -f $DAEMON || exit 0
. /lib/lsb/init-functions
case "$1" in
start) log_daemon_msg "Starting mailcatcher" "mailcatcher"
start_daemon -p $PIDFILE $DAEMON $EXTRA_OPTS
log_end_msg $?
;;
stop) log_daemon_msg "Stopping mailcatcher" "mailcatcher"
killproc -p $PIDFILE $DAEMON
RETVAL=$?
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
log_end_msg $RETVAL
;;
restart) log_daemon_msg "Restarting mailcatcher" "mailcatcher"
$0 stop
$0 start
;;
status)
status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
;;
*) log_action_msg "Usage: /etc/init.d/mailcatcher {start|stop|status|restart}"
exit 2
;;
esac
exit 0
description "Mailcatcher"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/bin/env $(which mailcatcher) --foreground --http-ip=0.0.0.0
[Unit]
Description=mailcatcher daemon
After=network.target auditd.service
[Service]
Environment=IP='0.0.0.0' SMTP_PORT='1025' HTTP_PORT='1080'
ExecStart = /usr/sbin/mailcatcher --foreground --no-quit --ip $IP --smtp-port $SMTP_PORT --http-port $HTTP_PORT
ExecStop = /bin/kill -TERM $MAINPID
KillMode=process
Type=simple
[Install]
WantedBy=multi-user.target
Alias=mailcatcherd.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment