Last active
August 2, 2017 19:59
-
-
Save mechastorm/ff4add694afada6ff6b4647aa2cb5797 to your computer and use it in GitHub Desktop.
Teleport Upstart Script
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/rc.d/init.d/teleport | |
# | |
# Daemonize the teleport agent. | |
# | |
# chkconfig: 2345 95 20 | |
# description: SSH Infrastructure for clusters and teams # processname: teleport | |
# pidfile: /var/run/teleport/pidfile | |
# Source function library. | |
. /etc/init.d/functions | |
TELEPORT=/usr/local/bin/teleport | |
CONFIG={{ teleport_config_dir }}/config.yaml | |
PID_FILE=/var/run/teleport/teleport.pid | |
LOG_FILE={{ teleport_log_path }} | |
[ -e /etc/sysconfig/teleport ] && . /etc/sysconfig/teleport | |
export GOMAXPROCS=${GOMAXPROCS:-2} | |
mkrundir() { | |
[ ! -d /var/run/teleport ] && mkdir -p /var/run/teleport | |
} | |
# | |
# Create a PID file if it doesn't already exist, for clean upgrades | |
# from previous init-script controlled daemons. | |
# | |
KILLPROC_OPT="-p ${PID_FILE}" | |
mkpidfile() { | |
# Create PID file if it didn't exist | |
mkrundir | |
[ ! -f $PID_FILE ] && pidofproc $TELEPORT > $PID_FILE | |
if [ $? -ne 0 ] ; then | |
rm $PID_FILE | |
KILLPROC_OPT="" | |
fi | |
} | |
start() { | |
echo -n "Starting teleport: " | |
mkrundir | |
[ -f $PID_FILE ] && rm $PID_FILE | |
daemon --pidfile="$PID_FILE" \ | |
"$TELEPORT" start --config="$CONFIG" >> "$LOG_FILE" | |
retcode=$? | |
sleep 1 # Give teleport a change to start before writing PID | |
PID=$(pgrep teleport) | |
echo $PID >> $PID_FILE | |
touch /var/lock/subsys/teleport | |
return $retcode | |
} | |
stop() { | |
DELAY=5 # seconds maximum to wait for a leave | |
echo -n "Shutting down teleport: " | |
mkpidfile | |
killproc $KILLPROC_OPT $TELEPORT | |
retcode=$? | |
rm -f /var/lock/subsys/teleport $PID_FILE | |
return $retcode | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status -p $PID_FILE teleport | |
;; | |
restart) | |
stop | |
start | |
;; | |
reload) | |
mkpidfile | |
killproc $KILLPROC_OPT $TELEPORT -HUP | |
;; | |
condrestart) | |
[ -f /var/lock/subsys/teleport ] && restart || : | |
;; | |
*) | |
echo "Usage: teleport {start|stop|status|reload|restart}" | |
exit 1 | |
;; | |
esac | |
retcode=$? | |
# Don't let the [OK] get stomped on. | |
echo | |
exit $retcode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example taken from https://github.com/jaxxstorm/puppet-teleport/blob/master/templates/teleport.init.erb