Skip to content

Commit

Permalink
fixing install + init.d
Browse files Browse the repository at this point in the history
  • Loading branch information
seryoni committed Apr 26, 2017
1 parent 796c9b2 commit b11843f
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 11 deletions.
19 changes: 8 additions & 11 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if [ -f /etc/lsb-release ]; then
OS=$(awk '/DISTRIB_ID=/' /etc/*-release | sed 's/DISTRIB_ID=//' | tr '[:upper:]' '[:lower:]')
fi

if [OS="ubuntu"]; then
if [ $OS = "ubuntu" ]; then
[[ `initctl` =~ -\.mount ]] || ( echo "init.d is required but it's not running. Aborting." >&2; exit 1 )
else
# Check for systemd
Expand All @@ -36,7 +36,7 @@ SERVICE_NAME=jumper-agent

if ! command -v virtualenv --version >/dev/null 2>&1; then
echo Installing virtualenv...
yes w | python2.7 -m pip --isolated -qq install virtualenv
yes w | python2.7 -m pip -qq install virtualenv
fi

if id -u ${SERVICE_USER} >/dev/null 2>&1; then
Expand Down Expand Up @@ -78,13 +78,12 @@ EOFSU
# Setup the jumper agent service
echo Setting up service ${SERVICE_NAME}...

if [OS="ubuntu"]; then
SERVICE_FILE=/etc/init.d/${SERVICE_NAME}.sh
if [ $OS = "ubuntu" ]; then
SERVICE_FILE=/etc/init.d/${SERVICE_NAME}

cp ${SCRIPT_DIR}/jumper.template ${SERVICE_FILE}
echo "${DEST_DIR}/venv/bin/python2.7 ${DEST_DIR}/agent_main.py" >> ${SERVICE_FILE}
echo "User=${SERVICE_USER}" >> ${SERVICE_FILE}
ln -fs ${SERVICE_FILE} /etc/systemd/system/${SERVICE_NAME}.service

chmod 755 ${SERVICE_FILE}

# Start the jumper agent service
update-rc.d ${SERVICE_NAME} defaults
Expand All @@ -93,10 +92,8 @@ if [OS="ubuntu"]; then

sleep 1

if [[ "`service ${SERVICE_NAME} status`" -ne "active" ]]; then
if [[ "`service ${SERVICE_NAME} status`" -ne "Running" ]]; then
echo "Error: Service ${SERVICE_NAME} is not running. Status information: " >&2
echo "" >&2
systemctl status ${SERVICE_NAME} >&2
exit 1
fi
else
Expand All @@ -122,4 +119,4 @@ else
fi


echo Success! Jumper logging agent is now installed and running.
echo Success! Jumper logging agent is now installed and running.
88 changes: 88 additions & 0 deletions jumper.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,91 @@
# Description: Start Jumper Logging Agent
### END INIT INFO
# Author: Roy Razon <roy@jumper.io>

dir="/opt/jumper_logging_agent"
cmd="/opt/jumper_logging_agent/venv/bin/python2.7 /opt/jumper_logging_agent/agent_main.py"
user="jumperagent"

name=`basename $0`
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"
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 "$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

0 comments on commit b11843f

Please sign in to comment.