Created
August 15, 2017 00:02
-
-
Save valentineus/7f810f2d688336c71f86ecd9b769dde9 to your computer and use it in GitHub Desktop.
Cloud9 service for the init initialization system.
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/sh | |
### BEGIN INIT INFO | |
# Provides: cloud9 | |
# Required-Start: $remote_fs $syslog | |
# Required-Stop: $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Starting Cloud9 SDK | |
# Description: Starting the development environment Cloud9 SDK | |
### END INIT INFO | |
# Documentation available at: | |
# http://refspecs.linuxfoundation.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html | |
# Debian provides some extra functions though | |
. /lib/lsb/init-functions | |
# Basic configuration script | |
NAME="cloud9" | |
USER="cloud9" | |
DESC="Cloud9 SDK" | |
WORKINGDIR=$(eval echo ~$USER) | |
PIDFILE="/var/run/$NAME.pid" | |
PATH="/sbin:/usr/sbin:/bin:/usr/bin" | |
DAEMON=$(whereis node | awk '{ print $2 }') | |
SERVER="$WORKINGDIR/c9sdk/server.js" | |
LOG="$WORKINGDIR/.c9/cloud9.log" | |
# Setting IDE environment | |
CLOUD9_SETTINGS="standalone" # Settings File | |
CLOUD9_PORT="20200" # Port | |
CLOUD9_LISTEN="127.0.0.1" # Interface | |
CLOUD9_WORKSPACE="$WORKINGDIR/workspace" # Working directory | |
DAEMON_ARGS="--settings $CLOUD9_SETTINGS | |
--port $CLOUD9_PORT | |
--listen $CLOUD9_LISTEN | |
-w $WORKINGDIR/workspace" | |
# Daemon startup function | |
start_cloud9() { | |
# Return | |
# 0 if daemon has been started | |
# 1 if daemon was already running | |
# 2 if daemon could not be started | |
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \ | |
--test --chdir $WORKINGDIR --chuid $USER \ | |
--exec $DAEMON -- $SERVER $DAEMON_ARGS > $LOG \ | |
|| return 1 | |
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \ | |
--background --chdir $WORKINGDIR --chuid $USER \ | |
--exec $DAEMON -- $SERVER $DAEMON_ARGS > $LOG \ | |
|| return 2 | |
} | |
# Daemon stop function | |
stop_cloud9() { | |
# Return | |
# 0 if daemon has been stopped | |
# 1 if daemon was already stopped | |
# 2 if daemon could not be stopped | |
# other if a failure occurred | |
start-stop-daemon --stop --quiet --retry=TERM/1/KILL/5 --pidfile $PIDFILE --name $NAME | |
RETVAL="$?" | |
[ "$RETVAL" = 2 ] && return 2 | |
start-stop-daemon --stop --quiet --oknodo --retry=0/1/KILL/5 --exec $DAEMON | |
[ "$?" = 2 ] && return 2 | |
rm -f "$PIDFILE" | |
return "$RETVAL" | |
} | |
case "$1" in | |
start) | |
start_cloud9 | |
case "$?" in | |
0|1) log_success_msg "The process started / is running" ;; | |
2) log_failure_msg "Error when the process starts" ;; | |
esac | |
;; | |
stop) | |
stop_cloud9 | |
case "$?" in | |
0|1) log_success_msg "The process is stopped / it has stopped" ;; | |
2) log_failure_msg "The process can not be stopped" ;; | |
esac | |
;; | |
restart) | |
stop_cloud9 | |
case "$?" in | |
0|1) | |
start_cloud9 | |
case "$?" in | |
0) log_success_msg "New process is running" ;; | |
1) log_success_msg "Process is had already been running" ;; | |
*) log_failure_msg "Error when the process starts" ;; | |
esac | |
;; | |
*) log_failure_msg "The process can not be stopped" ;; | |
esac | |
;; | |
*) | |
N=/etc/init.d/$NAME | |
echo "Usage: $N {start|stop|restart}" >&2 | |
exit 0 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation:
Update: