SysV - Forego
Updated at 2016-12-10 00:50
# install Go
go get -u github.com/ddollar/forego
# check that forego is in path
which forego
touch /etc/init.d/forego && vim /etc/init.d/forego
chmod +x /etc/init.d/forego
ln /home/ec2-user/.gopath/bin/forego /usr/bin/forego
service forego start
chkconfig --add forego
chkconfig --levels 0126 forego off
chkconfig --levels 345 forego on
chkconfig --list forego
/etc/init.d/forego
#!/bin/sh
### BEGIN INIT INFO
# Provides:
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
DIR="/home/ec2-user"
CMD="forego start"
USER="ec2-user"
NAME=forego
PID_FILE="/var/run/$NAME.pid"
STDOUT_LOG="/var/log/$NAME.log"
STDERR_LOG="/var/log/$NAME.err"
get_pid() {
cat "$PID_FILE"
}
is_running() {
[ -f "$PID_FILE" ] && ps `get_pid` > /dev/null 2>&1
}
case "$1" in
start)
if is_running; then
echo "Already started"
else
echo "Starting $NAME"
cd "$DIR"
# ipcluster doens't know how to remove it's own pids for some reason
rm /home/ec2-user/.ipython/profile_default/pid/*
if [ -z "$USER" ]; then
sudo $CMD >> "$STDOUT_LOG" 2>> "$STDERR_LOG" &
else
sudo -u "$USER" $CMD >> "$STDOUT_LOG" 2>> "$STDERR_LOG" &
fi
echo $! > "$PID_FILE"
if ! is_running; then
echo "Unable to start, see $STDOUT_LOG and $STDERR_LOG"
exit 1
fi
fi
;;
stop)
if is_running; then
echo -n "Stopping $NAME.."
kill `get_pid`
for i in {1..10}
do
if ! is_running; then
break
fi
echo -n "."
sleep 1
done
echo
if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
if [ -f "$PID_FILE" ]; then
rm /home/ec2-user/.ipython/profile_default/pid/*
rm "$PID_FILE"
fi
fi
else
echo "Not running"
fi
;;
restart)
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
status)
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0