Gophish As a Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# RENAME to gophish.sh | |
# /root/gophish.sh | |
# | |
GOPHISH_LOG_FILE=gophish.log | |
GOPHISH_ERR_FILE=gophish.err | |
check_bin_path() { | |
if [[ -z "$GOPHISH_BIN_PATH" ]]; then | |
exit 1 | |
fi | |
} | |
check_log_path() { | |
if [[ -z "$GOPHISH_LOG_PATH" ]]; then | |
exit 2 | |
fi | |
} | |
create_new_log_err() { | |
GOPHISH_STAMP=`date +%Y%m%d%H%M%S-%N` | |
if [[ -e $GOPHISH_LOG_PATH$GOPHISH_LOG_FILE ]]; then | |
mv $GOPHISH_LOG_PATH$GOPHISH_LOG_FILE $GOPHISH_LOG_PATH$GOPHISH_LOG_FILE-$GOPHISH_STAMP | |
fi | |
if [[ -e $GOPHISH_LOG_PATH$GOPHISH_ERR_FILE ]]; then | |
mv $GOPHISH_LOG_PATH$GOPHISH_ERR_FILE $GOPHISH_LOG_PATH$GOPHISH_ERR_FILE-$GOPHISH_STAMP | |
fi | |
touch $GOPHISH_LOG_PATH$GOPHISH_LOG_FILE | |
touch $GOPHISH_LOG_PATH$GOPHISH_ERR_FILE | |
} | |
launch_gophish() { | |
cd $GOPHISH_BIN_PATH | |
./gophish >> $GOPHISH_LOG_PATH$GOPHISH_LOG_FILE 2>> $GOPHISH_LOG_PATH$GOPHISH_ERR_FILE | |
} | |
check_bin_path | |
check_log_path | |
create_new_log_err | |
launch_gophish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /lib/systemd/system/gophish.service | |
# | |
# | |
[Unit] | |
Description=Gophish service | |
After=network-online.target | |
[Service] | |
Environment="GOPHISH_BIN_PATH=/opt/gophish/" | |
Environment="GOPHISH_LOG_PATH=/var/log/" | |
ExecStart=/bin/bash /root/gophish.sh | |
RestartSec=1 | |
Restart=on-failure | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# /etc/init.d/gophish | |
# initialization file for stop/start of gophish application server | |
# | |
# chkconfig: - 64 36 | |
# description: stops/starts gophish application server | |
# processname:gophish | |
# config:/opt/goapps/src/github.com/gophish/gophish/config.json | |
# define script variables | |
processName=Gophish | |
process=gophish | |
appDirectory=/opt/goapps/src/github.com/gophish/gophish | |
logfile=/var/log/gophish/gophish.log | |
errfile=/var/log/gophish/gophish.error | |
start() { | |
echo 'Starting '${processName}'...' | |
cd ${appDirectory} | |
nohup ./$process >>$logfile 2>>$errfile & | |
sleep 1 | |
} | |
stop() { | |
echo 'Stopping '${processName}'...' | |
pid=$(/usr/sbin/pidof ${process}) | |
kill ${pid} | |
sleep 1 | |
} | |
status() { | |
pid=$(/usr/sbin/pidof ${process}) | |
if [[ "$pid" != "" ]]; then | |
echo ${processName}' is running...' | |
else | |
echo ${processName}' is not running...' | |
fi | |
} | |
case $1 in | |
start|stop|status) "$1" ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment