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

Losing sync between filesystem and IDE

silarsis opened this issue · comments

I've built an EC2 instance running the c9 sdk using the "./scripts/install-sdk.sh" script, running on CentOS 7. I'm seeing issues if I, for instance, "git checkout branch" to switch to a new branch, where the IDE doesn't seem to pick up the changes to the files on the filesystem, or sometimes if I create or delete files or directories and the folder view down the side doesn't pick up the changes. Even if I hit "refresh", it doesn't pick up the changes.

I'm presuming this is something specific to my setup as it's pretty much a show-stopper, so I'm wondering how I'd go about debugging these sorts of issues?

Thanks,

Shame I didn't see this earlier. I had this issue too but resolved it within a day or two of inspection.

I have been able to temporarily solve it by creating a bash script in conjunction with some other scripts I've had for a while. This helps me automate my workspace. Sadly it's not a change to c9 itself.

Warning: Setups may differ, so make sure you read them and amend to suit your development environment. I will not edit them to suit your environment

The most important script I have is a sourced function file (sourced from my bash profile) which contains a function to switch branches and then reload the c9 workspace automatically (which I find updates the file tree and git menu bar properly albeit with the need of an automatic browser refresh). Setup will differ but for me, my branch is always symlink'd to my /var/www/html so by getting the real path of the symlink, I can automatically update c9 to reflect it. One could always edit this script to go to a certain directory instead of attempting to detect it (e.g. c9 reload /different/directory)

switch_branch is a custom script that basically does a git clone with the branch name so that I can work on different git branches at once without having to git stash, etc. sws is just a small lazy name of 'switch workspaces' but easy to type in the terminal (e.g. sws branch2). I cannot include the switch_branch script I have so I made a simple bash function instead but it does not check whether the branch is already present and whether to pull changes, etc. I'm not sure whether the function actually works though. One could name it to the same convention of sws by instead calling it sb

function switch_branch() {
  host="https://github.com"
  project="test/HelloWorld.git"
  branch_path=/var/www/branches
  branch=$1
  git clone "$host/$project" --branch "$branch" "$branch_path/$branch"
}

function sws() {
  switch_branch $1
  branchpath="$(realpath /var/www/html)"
  cd $branchpath
  echo -e "Swap c9 workspace? (Y/N)\nTabs might get closed by c9 on this change. Make sure work has been saved!"
  read -p "(Y/N): " answer
  if [[ $answer == "Y" ]]; then
    echo "Changing c9 workspace..."
    c9 reload "$branchpath"
  else
    echo "c9 workspace has not been changed."
  fi
}

This is my c9 service script (I keep in my crontab for now until I learn systemctl/services). It's not perfect, but it does the job for me...

#!/bin/bash
running=$(ps -aux | grep 'server.js' | grep 8081)
action=$1
workspace=$2

if [ -z "$workspace" ]; then
  workspace=$(realpath /var/www/html)
fi

starter="./server.js -p 8081 -l 0.0.0.0 -a : -w "$workspace" &> c9log.txt &"
stopper="echo $running | awk '{print \$2}' | xargs kill -9 &> /dev/null"

if [ -z "$action" ]; then
  action="start"
fi
cd /var/www/c9sdk
if [[ $action == "start" && -z "$running" ]]; then
  exec $starter
elif [[ $action == "restart" || $action == "reload" ]]; then
  exec $stopper
  exec $starter
  echo 'Please wait, restarting c9 IDE...'
  i=0
  done=false
  while [[ $i < 5 && $done == false ]]; do
    sleep 1
    # Restart client browser using bridge
    echo '{"message": {"type": "exec", "command": "restartc9"}}' | nc -U ~/.c9/bridge.socket 2> /dev/null && export done=true
    i=$i+1
  done
  if [[ $done == false ]]; then
    echo "Unable to refresh your browser. Please do this manually for now. If this keeps happening; consider increasing the timeout and make sure the bridge is active."
    exit 1
  fi
elif [[ $action == "kill" || $action == "stop" ]]; then
  echo 'Stopping'
  exec $stopper
  ps -aux | grep 'c9' | grep -v grep | awk '{print $2}' | xargs kill -9 &> /dev/null
  ps -aux | grep 'tmux' | grep -v grep | awk '{print $2}' | xargs kill -9 &> /dev/null
elif [ $action == "--help" ]; then
  echo -e "C9 service script\nusage: c9 (start|restart|reload|kill|stop) [workspace_dir]\n\nThis script is used to control c9 by the commandline.\nOne such feature is the ability to change workspaces.\n(e.g. c9 reload [workspace_dir])"
else
  echo "invalid action - use --help"
fi

This means I start my server with c9 which will run in the background (so you can leave the ssh terminal if needed). Inside a c9 terminal I just run sws [branch name], say yes to the prompt and voila! Everything just restarts. This c9 prompt is also useful when using an SSH terminal so that you don't keep refreshing c9 if you're not using it. The terminal will also change directories to the branch too, which can be incredibly useful.

Please note that if you're running an AWS instance, do not leave use 0.0.0.0 in my c9 script and instead use 127.0.0.1 and then tunnel the ports through SSH, this prevents people from being able to edit code on your server. Do not forward c9 ports 8081 when no authentication is present.

Have fun 👍