Created
May 10, 2013 02:44
-
-
Save jessearmand/5552073 to your computer and use it in GitHub Desktop.
fleet hub init script from @tblobaum
This file contains hidden or 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 | |
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment