dssh 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/share/dssh +65 -39
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6c195466d73ad8235b04a1af45db1f59c61ea5c
4
- data.tar.gz: 775a91c9e7e56f0df75fb26a5e4bf60f0ba58143
3
+ metadata.gz: 9457bc9bcd24cf5c44025db3c4cef1f5f0d5cacf
4
+ data.tar.gz: be8f47528b8a187da4d41745fb0465a70dbfd6b7
5
5
  SHA512:
6
- metadata.gz: c5d011035153ff5bf20575aa1e3797d5315fa38ca9c036c662e5f9ca64f81340bc40801e87490886703d142a8b3b6793681730dfd366d0ea42e7f3e4e60da3b0
7
- data.tar.gz: 3d4c2751a5ada363a599fe753df8d685c4f88a109ff79daf6ef8beb7e038d359f046f38bbc9101eb341ec22d325e6bb007ec67b71fd1833cbe7a7cb4cc280a14
6
+ metadata.gz: 80d2b3595a2ed7d1c439105fa95b55e393996c0d01f72b8032c77e7f62e402ab733f19e04f503bc4e61ebb30e54d1fffc7fbb50a16aa0796cdcab77ef96e5bbf
7
+ data.tar.gz: 822053b7125b71cc44937808bc72cf22222c96e677869976dcbafcc4715b043ade56e1bc61f41849eab179378a864f2499c2d8947b8fb1b83cc2121e8b08ab00
data/share/dssh CHANGED
@@ -1,9 +1,9 @@
1
1
  #! /usr/bin/env bash
2
2
 
3
3
 
4
- ################################
5
- ######## Usage & Options #######
6
- ################################
4
+ ##############################################################
5
+ ####################### Usage & Options ######################
6
+ ##############################################################
7
7
 
8
8
  usage() {
9
9
  cat << EOF
@@ -40,9 +40,9 @@ do
40
40
  done
41
41
 
42
42
 
43
- ################################
44
- ######## Set Options ###########
45
- ################################
43
+ ##############################################################
44
+ ####################### Set Options ##########################
45
+ ##############################################################
46
46
 
47
47
  CONTAINER_NAMES=$1
48
48
 
@@ -50,13 +50,17 @@ if [[ -z "$CONTAINER_NAMES" ]]; then
50
50
  NL=$'\n'
51
51
  CONTAINER_NAMES=$(docker ps -q | sed ':a;N;$!ba;s/\n/ /g')
52
52
  if [[ "$?" != "0" ]]; then
53
- echo "If you're on OSX, make sure boot2docker is working properly"
54
- echo "Otherwise, use sudo"
53
+ if [[ "$?" == "130" ]]; then
54
+ echo "] If you're on OSX, make sure boot2docker is working properly"
55
+ echo "] In all cases, make sure you're using the right user and command (to sudo or not to sudo)"
56
+ else
57
+ echo "] Error while trying to list docker containers"
58
+ fi
55
59
  fi
56
60
  fi
57
61
 
58
62
  if [[ -z "$CONTAINER_NAMES" ]]; then
59
- echo "Usage: $0 container_name"
63
+ usage
60
64
  exit 1
61
65
  fi
62
66
 
@@ -66,43 +70,65 @@ unset CONTAINER_NAMES[0]
66
70
 
67
71
 
68
72
 
69
- ################################
70
- ######### Dependencies #########
71
- ################################
73
+ ##############################################################
74
+ ####################### Init nsenter #########################
75
+ ########### https://github.com/jpetazzo/nsenter ##############
76
+ ##############################################################
72
77
 
73
-
74
- #https://github.com/jpetazzo/nsenter
75
- if [[ ! -f /usr/local/bin/nsenter ]]; then
76
- echo "################################################################"
77
- echo "###################### Fetching nsenter ########################"
78
- echo "############# (https://github.com/jpetazzo/nsenter) ############"
79
- echo "################################################################"
80
- echo ""
81
- docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter
82
- echo ""
78
+ type docker-enter >/dev/null 2>&1
79
+ if [[ "$?" != "0" ]]; then
80
+ docker-enter() {
81
+ boot2docker ssh '[ -f /var/lib/boot2docker/nsenter ] || docker run --rm -v /var/lib/boot2docker/:/target jpetazzo/nsenter'
82
+ boot2docker ssh -t sudo /var/lib/boot2docker/docker-enter "$@"
83
+ }
83
84
  fi
84
-
85
85
 
86
- ################################
87
- ######## Go do stuff!!!! #######
88
- ################################
89
86
 
90
- echo "Searching for a container matching \"$CONTAINER_NAME\""
91
- PID=$(docker inspect --format {{.State.Pid}} $CONTAINER_NAME)
92
- if [[ "$?" != "0" ]]; then
93
- echo ""
94
- echo "Run \`docker ps\` to see available containers"
95
- docker ps
87
+ ##############################################################
88
+ ####################### Go do stuff!!!! ######################
89
+ ##############################################################
90
+
91
+ echo ""
92
+ echo -n "] Searching for a container matching \"$CONTAINER_NAME\"..."
93
+ PID=$( docker inspect --format {{.State.Pid}} "$CONTAINER_NAME" 2>&1 & wait $! )
94
+
95
+ CODE=$?
96
+ if [[ "$CODE" != "0" ]]; then
97
+
98
+ echo " no such luck."
99
+
100
+ if [[ "$CODE" == "2" ]]; then
101
+ echo "] No valid docker environment found"
102
+ elif [[ "$CODE" == "130" ]]; then
103
+ echo "] Invalid permissions"
104
+ echo "] Tip: You can't alternate between using 'sudo' for some Docker commands and not others."
105
+ elif [[ "$CODE" == "1" ]]; then
106
+ RUNNING_COUNT=$(docker ps | tail -n+2 | grep "" -c)
107
+ if [[ "$RUNNING_COUNT" == "" ]]; then
108
+ echo ""
109
+ echo "] You have no running Docker containers"
110
+ echo "] Start one with \`docker start\` and then try to enter it"
111
+ echo ""
112
+ echo "] Running \`docker ps\` to show available containers"
113
+ echo ""
114
+
115
+
116
+
117
+
118
+ docker ps -n 5 | tail -n+2 | awk '{FS="[, \t][, \t]+"} BEGIN{ printf("%-20s %-30s %-15s %-10s\n","Container ID","Image","Created","Name")} {printf("%-20s %-30s %-15s %-10s\n",$1,$2,$4,$6)}'
119
+ fi
120
+ echo " "
121
+ echo "-----------------------------------------------"
96
122
  echo ""
97
- exit 1
98
- fi
99
-
100
- echo "Connecting to container $CONTAINER_NAME with pid $PID..."
101
- nsenter --target $PID --mount --uts --ipc --net --pid
102
- if [[ "$?" != "0" ]]; then
103
- exit 0;#/TODO: iterate?
123
+ else
124
+ echo "] Unknown error with code $CODE"
125
+ echo "] nsenter said: $PID"
126
+ fi
127
+ exit $CODE
104
128
  fi
105
129
 
106
130
 
131
+ echo "] Calling docker-enter with \"$CONTAINER_NAME\""
132
+ docker-enter "$CONTAINER_NAME"
107
133
 
108
134
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Johnson