c9 / core

Cloud9 Core - Part of the Cloud9 SDK for Plugin Development https://c9.github.io/core/ https://c9.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

c9 start|stop|status|restart

Arlington1985 opened this issue · comments

Would like to share simple script for managing c9 process in your own VPS. Works for me. You need just to replace YOUR_IP, PORT_NUM, YOUR_USER, YOUR_PASSWORD, PROJECT_FOLDER:

#!/bin/bash
get_c9_pid(){
    echo $(ps x | grep '[n]ode server.js' | awk '{print $1}')
}

start() {
    local c9_pid=$(get_c9_pid)
    if [ -z "$c9_pid" ];
    then
	if [ $? -eq 0 ];
        then
	    nohup node server.js --listen YOUR_IP -p PORT_NUM -a YOUR_USER:YOUR_PASSWORD -w PROJECT_FOLDER >/dev/null 2>&1 &
            echo "c9 started"
	fi
    else
	echo "already running"
    fi
}

stop() {
    local c9_pid=$(get_c9_pid)
    if [ ! -z "$c9_pid" ]; 
    then    
        kill $c9_pid
        if [ $? -eq 0 ]; 
        then 
            echo "killed"
        else
            echo "cannot kill"   
       fi
    else
        echo "Nothing to stop"
    fi
}
status() {
    local c9_pid=$(get_c9_pid)
    if [ -z "$c9_pid" ];
    then
	echo "process is not running"
    else
	echo "process is running"
    fi 
}

case "$1" in 
    start)
           start
           ;;
    stop)
           stop
           ;;
    status)
           status
           ;;
    restart)
	   stop
	   start
	   ;; 
    *)
           echo "Usage: $0 {start|stop|status|restart}"
esac
exit 0 

this is my configuration with systemd and tmux, it works very well.

[Unit]
Description=Cloud9 IDE
After=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
User=user
Group=user
ExecStart=/bin/bash -c '\
    /usr/bin/tmux has-session -t c9; \
    if [ $? -eq 0 ]; then \
        echo "c9 already start"; \
    else \
        echo "start tmux with c9"; \
        /usr/bin/tmux new-session -d -s c9 "node <PATH TO server.js> -p <YOUR_PORT> -w <YOUR WORKSPACE> --collab"; \
    fi'

ExecStop=/bin/bash -c '\
    /usr/bin/tmux has-session -t c9; \
    if [ $? -eq 0 ]; then \
        echo "stop c9"; \
        /usr/bin/tmux kill-session -t c9; \
    else \
        echo "c9 is not running"; \
    fi'
Restart=no
KillMode=none

[Install]
WantedBy=multi-user.target