Skip to content

Instantly share code, notes, and snippets.

@tblobaum
Created April 13, 2012 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tblobaum/8717fb0d65ced13db772 to your computer and use it in GitHub Desktop.
Save tblobaum/8717fb0d65ced13db772 to your computer and use it in GitHub Desktop.
#!/bin/bash
SET_USER="node"
SET_NODE_VERSION="v0.6.14"
SET_DRONE_HUB="localhost:1024"
SET_DRONE_SECRET="beepboop"
[ -d /etc/node ] || mkdir /etc/node
cat > /etc/node/fleet-drone.conf <<EOT
node_path=/home/$SET_USER/.nvm/$SET_NODE_VERSION/bin
hub=$SET_DRONE_HUB
secret=$SET_DRONE_SECRET
EOT
cat > /etc/init.d/fleet-drone <<EOT
#!/bin/sh
#
# fleet-drone
#
# chkconfig: - 85 15
# description:
# processname: fleet-drone
# config: /etc/node/fleet-drone.conf
# pidfile: /var/run/fleet-drone.pid
# Source function library.
source /etc/rc.d/init.d/functions
# Source networking configuration.
source /etc/sysconfig/network
# Check that networking is up.
[ "\$NETWORKING" = "no" ] && exit 0
# Source fleet-drone configuration.
source /etc/node/fleet-drone.conf
exec="\$node_path/node \$node_path/fleet-drone"
prog=\$(basename \$exec)
PATH=$node_path:$PATH
[ -e /etc/sysconfig/\$prog ] && source /etc/sysconfig/\$prog
lockfile=/var/lock/subsys/fleet-drone
start() {
echo -n \$"Starting \$prog: "
[ -d /opt/fleet-drone ] || mkdir /opt/fleet-drone
cd /opt/fleet-drone
# start it up here, usually something like "daemon \$exec"
daemon \$exec --hub \$hub --secret \$secret &
echo \$! > /var/run/fleet-drone.pid
retval=\$?
echo
[ \$retval -eq 0 ] && touch \$lockfile
return \$retval
}
stop() {
echo -n \$"Stopping \$prog: "
# stop it here, often "killproc \$prog"
killproc \$prog
retval=\$?
echo
[ \$retval -eq 0 ] && rm -f \$lockfile
return \$retval
}
restart() {
stop
start
}
force_reload() {
restart
}
fdr_status() {
status \$prog
}
case "\$1" in
start|stop|restart)
\$1
;;
status)
fdr_status
;;
condrestart|try-restart)
[ ! -f \$lockfile ] || restart
;;
*)
echo \$"Usage: \$0 {start|stop|status|restart|try-restart}"
exit 2
esac
EOT
chmod 755 /etc/init.d/fleet-drone
#!/bin/bash
SET_USER="node"
SET_NODE_VERSION="v0.6.14"
SET_HUB_PORT="1024"
SET_HUB_SECRET="beepboop"
[ -d /etc/node ] || mkdir /etc/node
cat > /etc/node/fleet-hub.conf <<EOT
node_path=/home/$SET_USER/.nvm/$SET_NODE_VERSION/bin
hub_port=$SET_HUB_PORT
hub_secret=$SET_HUB_SECRET
EOT
cat > /etc/init.d/fleet-hub <<EOT
#!/bin/sh
#
# fleet-hub
#
# chkconfig: - 85 15
# description:
# processname: fleet-hub
# config: /etc/node/fleet-hub.conf
# pidfile: /var/run/fleet-hub.pid
# Source function library.
source /etc/rc.d/init.d/functions
# Source networking configuration.
source /etc/sysconfig/network
# Check that networking is up.
[ "\$NETWORKING" = "no" ] && exit 0
# Source fleet-hub configuration.
source /etc/node/fleet-hub.conf
exec="\$node_path/node \$node_path/fleet-hub"
prog=\$(basename \$exec)
PATH=$node_path:$PATH
[ -e /etc/sysconfig/\$prog ] && source /etc/sysconfig/\$prog
lockfile=/var/lock/subsys/fleet-hub
start() {
echo -n \$"Starting \$prog: "
[ -d /opt/fleet-hub ] || mkdir /opt/fleet-hub
cd /opt/fleet-hub
# start it up here, usually something like "daemon \$exec"
daemon \$exec --port \$hub_port --secret \$hub_secret &
echo \$! > /var/run/fleet-hub.pid
retval=\$?
echo
[ \$retval -eq 0 ] && touch \$lockfile
return \$retval
}
stop() {
echo -n \$"Stopping \$prog: "
# stop it here, often "killproc \$prog"
killproc \$prog
retval=\$?
echo
[ \$retval -eq 0 ] && rm -f \$lockfile
return \$retval
}
restart() {
stop
start
}
force_reload() {
restart
}
fdr_status() {
status \$prog
}
case "\$1" in
start|stop|restart)
\$1
;;
status)
fdr_status
;;
condrestart|try-restart)
[ ! -f \$lockfile ] || restart
;;
*)
echo \$"Usage: \$0 {start|stop|status|restart|try-restart}"
exit 2
esac
EOT
chmod 755 /etc/init.d/fleet-hub
#!/bin/bash
cat > /etc/monit.d/fleet-drone <<EOT
check process fleet-drone with pidfile /var/run/fleet-drone.pid
start program = "/etc/init.d/fleet-drone start"
stop program = "/etc/init.d/fleet-drone stop"
EOT
cat > /etc/monit.d/fleet-hub <<EOT
check process fleet-hub with pidfile /var/run/fleet-hub.pid
start program = "/etc/init.d/fleet-hub start"
stop program = "/etc/init.d/fleet-hub stop"
EOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment