Starting/stopping Linux services as part of a Job.

2,427 views
Skip to first unread message

Guillaume Belrose

unread,
Jun 23, 2014, 6:37:01 AM6/23/14
to go...@googlegroups.com
Hi,

I've just started to look at Go 13.4.1, currently deployed on a CentOS 6.5 virtual machine. I've built a Continuous Delivery pipeline with Jenkins, and I am trying to reproduce the features with Go as it seems more intuitive.

I am trying to model an automated user acceptance stage a job which require access to a CouchDB database. I've tried to model the startup and teardown of CouchDB using tasks. In other word, my job consists of:
-a task to start couchdb
-a task to run the tests
-a task to stop couchdb.

My agent is not able to execute the task to start couchdb (sudo service couchdb start or sudo /etc/init.d/couchdb start). I can execute the task directly from the terminal as the "go" user.

See the extract from the agent's log ([1]).

Any clues as to what might be the issue? 

Cheers, 

Guillaume.

[1]
[go] Start to build GStack/8/GStack_Automated_Acceptance_Tests/1/Start_CouchDB on vagrant-centos6 [/var/lib/go-agent1] at Mon Jun 23 19:06:49 JST 2014

[go] Current job status: passed.

[go] Start to execute task: <exec command="sudo /etc/init.d/couchdb start" />. 
[go] setting environment variable 'GO_SERVER_URL' to value 'https://localhost:8154/go/'
[go] setting environment variable 'GO_TRIGGER_USER' to value 'changes'
[go] setting environment variable 'GO_PIPELINE_NAME' to value 'GStack'
[go] setting environment variable 'GO_PIPELINE_COUNTER' to value '8'
[go] setting environment variable 'GO_PIPELINE_LABEL' to value '8'
[go] setting environment variable 'GO_STAGE_NAME' to value 'GStack_Automated_Acceptance_Tests'
[go] setting environment variable 'GO_STAGE_COUNTER' to value '1'
[go] setting environment variable 'GO_JOB_NAME' to value 'Start_CouchDB'
[go] setting environment variable 'GO_REVISION' to value '25d9070124210dfd4a720225ad9e8701318e6ed1'
[go] setting environment variable 'GO_TO_REVISION' to value '25d9070124210dfd4a720225ad9e8701318e6ed1'
[go] setting environment variable 'GO_FROM_REVISION' to value '25d9070124210dfd4a720225ad9e8701318e6ed1'
Error happened while attempting to execute 'sudo /etc/init.d/couchdb start'. 
Please make sure [sudo /etc/init.d/couchdb start] can be executed on this agent.

nathan chu

unread,
Jun 23, 2014, 12:47:20 PM6/23/14
to go...@googlegroups.com
We have a similar set up (sort of - We stop a service, deploy and then start the service).  I have found that if you use 'bash' or your favorite shell as a command, then Go is able to handle it.  as an example:

bash -c sudo service tomcat-dev stop

or

bash -c /etc/init.d/activemq start


You may also want to check your sudoers comfig - sudo will not allow elevated privileges from a headless connection without additional set up.  look for the requiretty config - if you want to execute sudo remotely, this must be set to false.


Nate

Aravind SV

unread,
Jun 23, 2014, 2:39:52 PM6/23/14
to Guillaume Belrose, go...@googlegroups.com
On Mon, Jun 23, 2014 at 4:07 PM, Guillaume Belrose <kaf...@gmail.com> wrote:
[go] Start to execute task: <exec command="sudo /etc/init.d/couchdb start" />.

In this case, it looks like your config is setup like this:

<exec command="sudo /etc/init.d/couchdb start">
</exec>

So, Go is trying to execute the whole thing as a command. Your config needs to look like this:

<exec command="sudo">
    <arg>/etc/init.d/couchdb</arg>
    <arg>start</arg>
</exec>

This tells it that sudo is the command and the other bits are the arguments. In the task creation section of the admin, it looks like this:

Inline image 1

That should work. If you want to use what Nathan suggested, you can too. In that case, the config looks like:

<exec command="/bin/bash">
    <arg>-c</arg>
    <arg>sudo /etc/init.d/couchdb start</arg>
</exec>

Cheers,
Aravind

Guillaume Belrose

unread,
Jun 23, 2014, 3:44:58 PM6/23/14
to Aravind SV, chu.n...@gmail.com, go...@googlegroups.com
Hi, 

Thanks a lot for your suggestions. The combinations [1] and [2] failed for me.
Using bash -c works (see [3]), CouchDB starts, but the job is marked as “building” and never completes. I was hoping it would complete as soon as CouchDB is started in the background (which is what the Jenkins job does).

I’ve added the go user to the sudoers list like so:

go ALL=(ALL) NOPASSWD: ALL

Defaults:go !requiretty


As I’ve said before, I can run the commands fine directly via the shell. 

Many thanks once again for your help, but for the time being, I think I am going to get back to Jenkins and maybe revisit Go when I have more time.

Guillaume. 

[1]
[go] Start to execute task: <exec command="sudo " >
<arg>service</arg>
<arg>couchdb</arg>
<arg>start</arg>
</exec>.  
[go] setting environment variable 'GO_SERVER_URL' to value 'https://localhost:8154/go/'
[go] setting environment variable 'GO_TRIGGER_USER' to value 'anonymous'
[go] setting environment variable 'GO_PIPELINE_NAME' to value 'Couchdb'
[go] setting environment variable 'GO_PIPELINE_COUNTER' to value '9'
[go] setting environment variable 'GO_PIPELINE_LABEL' to value '9'
[go] setting environment variable 'GO_STAGE_NAME' to value 'defaultStage'
[go] setting environment variable 'GO_STAGE_COUNTER' to value '1'
[go] setting environment variable 'GO_JOB_NAME' to value 'defaultJob'
[go] setting environment variable 'GO_REVISION' to value '3a401846a21c8a56ec0c23b6a411e74b6fd2dab0'
[go] setting environment variable 'GO_TO_REVISION' to value '3a401846a21c8a56ec0c23b6a411e74b6fd2dab0'
[go] setting environment variable 'GO_FROM_REVISION' to value '3a401846a21c8a56ec0c23b6a411e74b6fd2dab0'
Error happened while attempting to execute 'sudo  service couchdb start'.  
Please make sure [sudo ] can be executed on this agent.

[2]
[go] Start to execute task: <exec command="sudo " >
<arg>/etc/init.d/couchdb</arg>
<arg>start</arg>
</exec>.  
[go] setting environment variable 'GO_SERVER_URL' to value 'https://localhost:8154/go/'
[go] setting environment variable 'GO_TRIGGER_USER' to value 'anonymous'
[go] setting environment variable 'GO_PIPELINE_NAME' to value 'Couchdb'
[go] setting environment variable 'GO_PIPELINE_COUNTER' to value '10'
[go] setting environment variable 'GO_PIPELINE_LABEL' to value '10'
[go] setting environment variable 'GO_STAGE_NAME' to value 'defaultStage'
[go] setting environment variable 'GO_STAGE_COUNTER' to value '1'
[go] setting environment variable 'GO_JOB_NAME' to value 'defaultJob'
[go] setting environment variable 'GO_REVISION' to value '3a401846a21c8a56ec0c23b6a411e74b6fd2dab0'
[go] setting environment variable 'GO_TO_REVISION' to value '3a401846a21c8a56ec0c23b6a411e74b6fd2dab0'
[go] setting environment variable 'GO_FROM_REVISION' to value '3a401846a21c8a56ec0c23b6a411e74b6fd2dab0'
Error happened while attempting to execute 'sudo  /etc/init.d/couchdb start'.  
Please make sure [sudo ] can be executed on this agent.

[3]
[go] Start to execute task: <exec command="bash" >
<arg>-c</arg>
<arg>sudo /etc/init.d/couchdb start</arg>
</exec>.  
[go] setting environment variable 'GO_SERVER_URL' to value 'https://localhost:8154/go/'
[go] setting environment variable 'GO_TRIGGER_USER' to value 'anonymous'
[go] setting environment variable 'GO_PIPELINE_NAME' to value 'Couchdb'
[go] setting environment variable 'GO_PIPELINE_COUNTER' to value '12'
[go] setting environment variable 'GO_PIPELINE_LABEL' to value '12'
[go] setting environment variable 'GO_STAGE_NAME' to value 'defaultStage'
[go] setting environment variable 'GO_STAGE_COUNTER' to value '1'
[go] setting environment variable 'GO_JOB_NAME' to value 'defaultJob'
[go] setting environment variable 'GO_REVISION' to value '3a401846a21c8a56ec0c23b6a411e74b6fd2dab0'
[go] setting environment variable 'GO_TO_REVISION' to value '3a401846a21c8a56ec0c23b6a411e74b6fd2dab0'
[go] setting environment variable 'GO_FROM_REVISION' to value '3a401846a21c8a56ec0c23b6a411e74b6fd2dab0'
Starting couchdb: [  OK  ]


-- 
Guillaume Belrose
Sent with Airmail
ii_146ca0529eda778c

Florian Lüscher

unread,
Aug 11, 2014, 4:50:58 AM8/11/14
to go...@googlegroups.com


Hi,

I currently have exactly the same issue. Is there any update on this?

We use Go Version: 14.2.0(377-d8a2866d6af85e) with Java 8 (build 1.8.0_11-b12) on a AWS Machine running Amazon Linux AMI release 2014.03.

Our Job configuration looks like this

<exec command="bash" >
<arg>-c</arg>
<arg>service meet-server start</arg>
</exec>

and our init script like this:

do_start()
{
        if [ ! -f "$LOCK_FILE" ] ; then
                echo -n $"Starting $SERVER: "
                su - $USER -c "java -jar path-to-jar.jar --some-opts >> $LOG_FILE" &
                RETVAL=$?
                echo "OK"
                echo
                [ $RETVAL -eq 0 ] && touch $LOCK_FILE
        else
                echo "$SERVER is locked with file $LOCK_FILE"
                RETVAL=1
        fi
}


Regards,
Florian

Sachin Sudheendra

unread,
Aug 11, 2014, 5:07:53 AM8/11/14
to Florian Lüscher, kaf...@gmail.com, go...@googlegroups.com
Try configuring your task like

@Florian

<exec command="/bin/bash">
    <arg>-c</arg>
    <arg>ssh localhost 'service meet-server start'</arg>
</exec>

@Guillaume

<exec command="/bin/bash">
    <arg>-c</arg>
    <arg>ssh localhost 'sudo /etc/init.d/couchdb start'</arg>
</exec>

This task assumes that Go agent can ssh to itself without prompting for password (ssh-key-based-auth)

Reference: 

Hope this helps.


--
You received this message because you are subscribed to the Google Groups "go-cd" group.
To unsubscribe from this group and stop receiving emails from it, send an email to go-cd+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Sachin Sudheendra

Florian Lüscher

unread,
Aug 11, 2014, 6:28:20 AM8/11/14
to go...@googlegroups.com, florian....@gmail.com, kaf...@gmail.com
Hi Sachin,

Thank you very much for your fast reply. Thanks to your SSH login tipp, I was able to reproduce the behaviour outside of Go and to resolve it.

The root cause of the problem was our init script, which kept some file descriptors to the bash open. By changing the init script from:

su - $USER -c "$DAEMON $SERVER $SERVER_OPTS >> $LOG_FILE" &
to:
su - $USER -c "$DAEMON $SERVER $SERVER_OPTS" </dev/null >> $LOG_FILE 2>&1 &

Go is able to start the service with the command

<exec command="/bin/bash">
    <arg>-c</arg>
    <arg>service meet-server start'</arg>
</exec>

Thanks again and have a good week!

Regards,
Florian

Marius Ciotlos

unread,
Aug 11, 2014, 11:35:48 AM8/11/14
to go...@googlegroups.com, florian....@gmail.com, kaf...@gmail.com
If you don't want to be asked to accept key, you can also use something similar to below:

<exec command="/bin/bash">
    <arg>-c</arg>
    <arg>ssh -o StrictHostKeyChecking=no localhost 'service meet-server start'</arg>
</exec>
Reply all
Reply to author
Forward
0 new messages