Merge pull request #10 from grufwub/development

remove example gophor-run script
master
Kim 4 years ago committed by GitHub
commit 1f9dae642c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,8 +10,6 @@ I'm unemployed and work on open-source projects like this and many others for
free. If you would like to help support my work that would be hugely
appreciated 💕 https://liberapay.com/grufwub/
`gophor-run` is an example script to help with automation of gophor.
WARNING: the development branch is filled with lava, fear and capitalism.
# Usage

@ -1,193 +0,0 @@
#!/bin/sh
PIDFILE='/tmp/gophor.pid'
GOPHOR='./gophor'
LOGDIR='/var/log/gophor'
BINDADDR=''
PORT=70
HOSTNAME=''
RUNUSER=''
ROOTDIR=''
CACHESIZE='100'
CACHEFILEMAXMB='1'
CACHECHECKFREQ='1s'
PAGEWIDTH=80
FOOTERTEXT='Running Gophor, a Gopher server in Go.'
usage() {
echo 'Usage: gophor-run start|stop|status'
}
start() {
local exec_flags
if [ "$LOGDIR" = '' ]; then
# If log dir not set, disable logging
exec_flags="$exec_flags -log-type 1"
else
# Add log file paths
exec_flags="$exec_flags -system-log "${LOGDIR}/system.log" -access-log "${LOGDIR}/access.log""
# If log dir doesn't exist, try make it!
if [ ! -d "$LOGDIR" ] && !(mkdir "$LOGDIR" > /dev/null 2>&1) && !(sudo mkdir "$LOGDIR" > /dev/null 2>&1); then
echo "Log file directory does not exist, and failed to create: $LOGDIR"
exit 1
fi
fi
# Add bind addr (no worries if empty)
if [ "$BINDADDR" != '' ]; then
exec_flags="$exec_flags -bind-addr "${BINDADDR}""
fi
# Add port, don't worry if not
if [ "$PORT" != '' ]; then
exec_flags="$exec_flags -port "${PORT}""
fi
# Try to add hostname
if [ "$HOSTNAME" != '' ]; then
exec_flags="$exec_flags -hostname "${HOSTNAME}""
else
echo 'HOSTNAME variable must not be empty!'
echo 'This is used to generate Gopher directory entries.'
exit 1
fi
# Add user to run under (no worries if empty)
if [ "$RUNUSER" != '' ]; then
exec_flags="$exec_flags -user "${RUNUSER}""
fi
# Add root dir (no worries if empty)
if [ "$ROOTDIR" != '' ]; then
exec_flags="$exec_flags -root "${ROOTDIR}""
fi
# Add page width, don't worry if not
if [ "$PAGEWIDTH" != '' ]; then
exec_flags="$exec_flags -page-width "${PAGEWIDTH}""
fi
# Add footer text (no worries if empty)
if [ "$FOOTER" != '' ]; then
exec_flags="$exec_flags -footer "${FOOTERTEXT}""
fi
# If cache size 0 or empty, disable cache. Else, set
if [ "$CACHESIZE" = '' ] || [ "$CACHESIZE" -eq 0 ]; then
exec_flags="$exec_flags -disable-cache"
else
exec_flags="$exec_flags -cache-size "${CACHESIZE}""
# Add file size max in megabytes (no worries if empty)
if [ "$CACHEFILEMAXMB" != '' ]; then
exec_flags="$exec_flags -cache-file-max "${CACHEFILEMAXMB}""
fi
# Add cache staleness check frequency (no worries if empty)
if [ "$CACHECHECKFREQ" != '' ]; then
exec_flags="$exec_flags -cache-check "${CACHECHECKFREQ}""
fi
fi
# If logfiles provided, in background. Else, front!
echo -n 'Gophor server starting...'
sudo "$GOPHOR" $exec_flags & > /dev/null 2>&1
local pid="$!"
sleep 1
if (sudo kill -0 "$pid" > /dev/null 2>&1); then
echo ' Successful!'
sudo sh -c "echo "$pid" > "$PIDFILE""
sudo chmod 0644 "$PIDFILE"
exit 0
else
echo ' Failed!'
exit 1
fi
}
stop() {
if [ ! -f "$PIDFILE" ]; then
if (ps -ax | grep -v 'grep' | grep -q 'openvpn'); then
echo 'Gophor is running, but no PID file exists. Was this started without gophor-run?'
else
echo 'Gophor is not running!'
fi
return 1
fi
if (sudo kill "$(cat "$PIDFILE")" > /dev/null 2>&1); then
echo 'Successfully stopped gophor'
sudo rm -f "$PIDFILE"
return 0
else
if ! (sudo kill -0 "$(cat "$PIDFILE")" > /dev/null 2>&1); then
echo 'Gophor not running!'
return 1
else
echo 'Unable to stop gophor process'
return 1
fi
fi
}
status() {
if [ -f "$PIDFILE" ]; then
if (sudo kill -0 "$(cat "$PIDFILE")" > /dev/null 2>&1); then
echo 'Gophor is running!'
return 0
else
echo 'Gophor is not running'
sudo rm -f "$PIDFILE"
return 1
fi
else
if (ps -ax | grep -v 'grep' | grep -q 'openvpn'); then
echo 'Gophor is running but not at expected PID. Was this started without gophor-run?'
return 1
else
echo 'Gophor is not running'
return 1
fi
fi
}
if [ $# -ne 1 ]; then
usage
exit 0
fi
if [ $(id -u) -eq 0 ]; then
echo 'Please do not run this script as root! Root permissions will be requested when necessary'
exit 1
fi
echo 'This is an example script to ease automation of running gophor.'
echo 'Not recommended for use in production environments.'
echo ''
case "$1" in
'start')
start
;;
'stop')
stop
;;
'status')
status
;;
*)
usage
;;
esac
Loading…
Cancel
Save