diff mbox

Add a script to maintain the symlink for config.xml into, /userdata/conf

Message ID 56DF8565.9030303@sonymobile.com (mailing list archive)
State New, archived
Headers show

Commit Message

Bird, Tim March 9, 2016, 2:07 a.m. UTC
This adds a feature to maintain the symlink from /var/lib/jenkins/config.xml
to /userdata/conf/config.xml.  Jenkins removes this symlink when it
edits the file (which happens when a board is added or removed).

This change adds the inotify-tools package to the container build,
and adds a shell script which uses that in order to monitor the
directory for changes, and repair the link if needed.  A small
change is made to the jta-start-cmd.sh to start the script
(which runs forever).

The script is currently a bit noisy, but I could add a 'quiet'
option if desired, so that it runs silently.
---
Let me know what you think about this fix.  If you'd prefer
a different approach for fixing this bug, that's fine.
I tested this, and it does work pretty well.

 Dockerfile                          |  7 ++++++-
 jta-scripts/jta-start-cmd.sh        |  1 +
 jta-scripts/maintain_config_link.sh | 38 +++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100755 jta-scripts/maintain_config_link.sh

Comments

Dmitry Cherkasov March 15, 2016, 6:28 p.m. UTC | #1
Nice idea. It works.
Thanks for the patch.

On Wed, Mar 9, 2016 at 5:07 AM, Tim Bird <tim.bird@sonymobile.com> wrote:

> This adds a feature to maintain the symlink from
> /var/lib/jenkins/config.xml
> to /userdata/conf/config.xml.  Jenkins removes this symlink when it
> edits the file (which happens when a board is added or removed).
>
> This change adds the inotify-tools package to the container build,
> and adds a shell script which uses that in order to monitor the
> directory for changes, and repair the link if needed.  A small
> change is made to the jta-start-cmd.sh to start the script
> (which runs forever).
>
> The script is currently a bit noisy, but I could add a 'quiet'
> option if desired, so that it runs silently.
> ---
> Let me know what you think about this fix.  If you'd prefer
> a different approach for fixing this bug, that's fine.
> I tested this, and it does work pretty well.
>
>  Dockerfile                          |  7 ++++++-
>  jta-scripts/jta-start-cmd.sh        |  1 +
>  jta-scripts/maintain_config_link.sh | 38
> +++++++++++++++++++++++++++++++++++++
>  3 files changed, 45 insertions(+), 1 deletion(-)
>  create mode 100755 jta-scripts/maintain_config_link.sh
>
> diff --git a/Dockerfile b/Dockerfile
> index eab5995..ac3d6fe 100644
> --- a/Dockerfile
> +++ b/Dockerfile
> @@ -20,7 +20,7 @@ ENV URL_PREFIX /jta
>  WORKDIR /jta-install
>  RUN dpkg --add-architecture i386
>  RUN echo deb http://ftp.us.debian.org/debian jessie main non-free >>
> /etc/apt/sources.list
> -RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get -yV install
> apt-utils daemon gcc make python-paramiko python-lxml python-simplejson
> python-matplotlib libtool xmlstarlet autoconf automake rsync openjdk-7-jre
> openjdk-7-jdk iperf netperf netpipe-tcp texlive-latex-base sshpass wget git
> sudo net-tools vim openssh-server curl
> +RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get -yV install
> apt-utils daemon gcc make python-paramiko python-lxml python-simplejson
> python-matplotlib libtool xmlstarlet autoconf automake rsync openjdk-7-jre
> openjdk-7-jdk iperf netperf netpipe-tcp texlive-latex-base sshpass wget git
> sudo net-tools vim openssh-server curl inotify-tools
>  RUN /bin/bash -c 'echo "dash dash/sh boolean false" |
> debconf-set-selections ; DEBIAN_FRONTEND=noninteractive dpkg-reconfigure
> dash'
>  COPY frontend-install/jenkins_1.509.2_all.deb /jta-install/
>  RUN dpkg -i /jta-install/jenkins_1.509.2_all.deb
> @@ -47,6 +47,11 @@ RUN ln -s $INST_JTA_ENGINE_PATH/jta/jobs
> $INST_JTA_FRONTEND_PATH/jobs
>  COPY docs $INST_JTA_FRONTEND_PATH/userContent/docs/
>
>  #
> ==============================================================================
> +# copy a miscelaneous JTA script
> +#
> ==============================================================================
> +COPY jta-scripts/maintain_config_link.sh /usr/local/bin/
> +
> +#
> ==============================================================================
>  # Init userdata
>  #
> ==============================================================================
>
> diff --git a/jta-scripts/jta-start-cmd.sh b/jta-scripts/jta-start-cmd.sh
> index 50eb49e..5f67dc2 100755
> --- a/jta-scripts/jta-start-cmd.sh
> +++ b/jta-scripts/jta-start-cmd.sh
> @@ -4,4 +4,5 @@
>  /etc/init.d/netperf start
>  /sbin/ifconfig eth0
>  chown -R jenkins /userdata
> +exec /usr/local/bin/maintain_config_link.sh &
>  /bin/bash
> diff --git a/jta-scripts/maintain_config_link.sh
> b/jta-scripts/maintain_config_link.sh
> new file mode 100755
> index 0000000..bf9815b
> --- /dev/null
> +++ b/jta-scripts/maintain_config_link.sh
> @@ -0,0 +1,38 @@
> +#!/bin/bash
> +#
> +# maintain_config_link.sh
> +#
> +# maintain_config_link.sh expects /var/lib/jenkins/config.xml to be a
> symlink
> +# to /userdata/conf/config.xml.  It uses inotifywait to monitor
> +# /var/lib/jenkins for any change in the link status, and if the link
> +# disappears it restores the symlink
> +#
> +# this needs inotifywait, from the inotify-tools package
> +#
> +# this is needed because Jenkins removes the symlink when it edits
> +# the config.xml file, but we want this file to appear in /userdata
> +# where it can be accessed (and edited) in the host filesystem
> +
> +#set -x
> +
> +dest_dir=/var/lib/jenkins
> +source=/userdata/conf/config.xml
> +dest=/var/lib/jenkins/config.xml
> +
> +function fixlink()
> +{
> +       # check for <dest> still being a symlink
> +       if [ ! -L "$dest" ]; then
> +               echo $dest is NOT a symlink - fixing it now.
> +               mv -f $dest $source ;
> +               ln -s $source $dest ;
> +       else
> +               echo $dest is a symlink - everything is OK.
> +       fi
> +}
> +
> +fixlink
> +while true
> +do
> +       inotifywait -e move $dest_dir && fixlink
> +done
> --
> 1.9.1
>
>
diff mbox

Patch

diff --git a/Dockerfile b/Dockerfile
index eab5995..ac3d6fe 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -20,7 +20,7 @@  ENV URL_PREFIX /jta
 WORKDIR /jta-install
 RUN dpkg --add-architecture i386
 RUN echo deb http://ftp.us.debian.org/debian jessie main non-free >> /etc/apt/sources.list
-RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get -yV install apt-utils daemon gcc make python-paramiko python-lxml python-simplejson python-matplotlib libtool xmlstarlet autoconf automake rsync openjdk-7-jre openjdk-7-jdk iperf netperf netpipe-tcp texlive-latex-base sshpass wget git sudo net-tools vim openssh-server curl
+RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get -yV install apt-utils daemon gcc make python-paramiko python-lxml python-simplejson python-matplotlib libtool xmlstarlet autoconf automake rsync openjdk-7-jre openjdk-7-jdk iperf netperf netpipe-tcp texlive-latex-base sshpass wget git sudo net-tools vim openssh-server curl inotify-tools
 RUN /bin/bash -c 'echo "dash dash/sh boolean false" | debconf-set-selections ; DEBIAN_FRONTEND=noninteractive dpkg-reconfigure dash'
 COPY frontend-install/jenkins_1.509.2_all.deb /jta-install/
 RUN dpkg -i /jta-install/jenkins_1.509.2_all.deb
@@ -47,6 +47,11 @@  RUN ln -s $INST_JTA_ENGINE_PATH/jta/jobs $INST_JTA_FRONTEND_PATH/jobs
 COPY docs $INST_JTA_FRONTEND_PATH/userContent/docs/
 
 # ==============================================================================
+# copy a miscelaneous JTA script
+# ==============================================================================
+COPY jta-scripts/maintain_config_link.sh /usr/local/bin/
+
+# ==============================================================================
 # Init userdata
 # ==============================================================================
 
diff --git a/jta-scripts/jta-start-cmd.sh b/jta-scripts/jta-start-cmd.sh
index 50eb49e..5f67dc2 100755
--- a/jta-scripts/jta-start-cmd.sh
+++ b/jta-scripts/jta-start-cmd.sh
@@ -4,4 +4,5 @@ 
 /etc/init.d/netperf start
 /sbin/ifconfig eth0
 chown -R jenkins /userdata
+exec /usr/local/bin/maintain_config_link.sh &
 /bin/bash
diff --git a/jta-scripts/maintain_config_link.sh b/jta-scripts/maintain_config_link.sh
new file mode 100755
index 0000000..bf9815b
--- /dev/null
+++ b/jta-scripts/maintain_config_link.sh
@@ -0,0 +1,38 @@ 
+#!/bin/bash
+#
+# maintain_config_link.sh
+#
+# maintain_config_link.sh expects /var/lib/jenkins/config.xml to be a symlink
+# to /userdata/conf/config.xml.  It uses inotifywait to monitor
+# /var/lib/jenkins for any change in the link status, and if the link
+# disappears it restores the symlink
+#
+# this needs inotifywait, from the inotify-tools package
+#
+# this is needed because Jenkins removes the symlink when it edits
+# the config.xml file, but we want this file to appear in /userdata
+# where it can be accessed (and edited) in the host filesystem
+
+#set -x
+
+dest_dir=/var/lib/jenkins
+source=/userdata/conf/config.xml
+dest=/var/lib/jenkins/config.xml
+
+function fixlink()
+{
+	# check for <dest> still being a symlink
+	if [ ! -L "$dest" ]; then
+		echo $dest is NOT a symlink - fixing it now.
+		mv -f $dest $source ;
+		ln -s $source $dest ;
+	else
+		echo $dest is a symlink - everything is OK.
+	fi
+}
+
+fixlink
+while true
+do
+	inotifywait -e move $dest_dir && fixlink 
+done