Comments (10)
But be careful, since you changed "EOF"
to EOF
, also the $?
variables will be expanded before the script is passed to the server. You need to escape it like \$?
or go back to "EOF"
from laminar.
The difference is, test.sh
on the remote server has the shebang #!/bin/bash
, while this line on laminar
ssh [email protected] "env C_NAME=$C_NAME /bin/bash -xe"<<"EOF"
executes under /bin/bash -xe
. -x
causes each line to be printed before its executed (that's what causes all the lines beginning with +
), and -e
causes the script to abort on the first command that returns a non-zero exit status. See Advanced Bash Scripting Guide: Options.
Since the ping
command isn't executed, I guess lxc exec pkg-builder-37 ip a add 10.214.101.2/24 dev eth0
is returning non-zero. On your test.sh
, this is ignored and the script continues.
If you don't care if it returns non-zero, you can either remove the -e
from the bash
invocation, or change the line to something like lxc exec pkg-builder-37 ip a add 10.214.101.2/24 dev eth0 || true
By the way, if you don't need internal variables inside the heredoc, you might consider changing "EOF"
to EOF
. This would expand the variables before passing the script to the server and allow you to remove env C_NAME=$C_NAME
from laminar.
So I changed the script now to:
#!/bin/bash
echo This script should start a container build a package and report back.
echo We are going to start container:
C_NAME=pkg-builder-$RUN
echo $C_NAME
echo Connecting to remote host and starting container
ssh [email protected] /bin/bash -xe << EOF
echo $C_NAME
lxc launch -e -p prf-funtoo -p default fun-generic "$C_NAME"
sleep 3
lxc exec "$C_NAME" ip a add 10.214.101.2/24 dev eth0
echo $?
lxc exec "$C_NAME" -- ping -c3 10.214.101.1
echo $?
echo "Waiting 3 seconds"
sleep 3
lxc exec "$C_NAME" -- poweroff
EOF
Laminar:
[laminar] Executing /var/lib/laminar/cfg/jobs/pkg-builder.run
This script should start a container build a package and report back.
We are going to start container:
pkg-builder-40
Connecting to remote host and starting container
pkg-builder-40
+ echo pkg-builder-40
+ lxc launch -e -p prf-funtoo -p default fun-generic pkg-builder-40
Creating pkg-builder-40
Starting pkg-builder-40
+ sleep 3
+ lxc exec pkg-builder-40 ip a add 10.214.101.2/24 dev eth0
Using remote script:
Job:
#!/bin/bash
echo Running on robor ...
ssh [email protected] /bin/bash -xe /root/test.sh
echo Done
remote script:
#!/bin/bash
C_NAME=pkg-builder-1
echo $C_NAME
lxc launch -e -p prf-funtoo -p default fun-generic "$C_NAME"
sleep 3
lxc exec "$C_NAME" ip a add 10.214.101.2/24 dev eth0
echo $?
lxc exec "$C_NAME" -- ping -c3 10.214.101.1
echo $?
echo "Waiting 3 seconds"
sleep 3
lxc exec "$C_NAME" -- poweroff
output:
[laminar] Executing /var/lib/laminar/cfg/jobs/pkg-builder-remote.run
Running on robor ...
pkg-builder-1
+ C_NAME=pkg-builder-1
+ echo pkg-builder-1
+ lxc launch -e -p prf-funtoo -p default fun-generic pkg-builder-1
Creating pkg-builder-1
Starting pkg-builder-1
+ sleep 3
+ lxc exec pkg-builder-1 ip a add 10.214.101.2/24 dev eth0
0
+ echo 0
+ lxc exec pkg-builder-1 -- ping -c3 10.214.101.1
PING 10.214.101.1 (10.214.101.1) 56(84) bytes of data.
64 bytes from 10.214.101.1: icmp_seq=1 ttl=64 time=0.175 ms
64 bytes from 10.214.101.1: icmp_seq=2 ttl=64 time=0.067 ms
64 bytes from 10.214.101.1: icmp_seq=3 ttl=64 time=0.062 ms
--- 10.214.101.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2077ms
rtt min/avg/max/mdev = 0.062/0.101/0.175/0.052 ms
0
Waiting 3 seconds
+ echo 0
+ echo 'Waiting 3 seconds'
+ sleep 3
+ lxc exec pkg-builder-1 -- poweroff
Done
Hm. the ip a add command returns 0 when running from remote script. I don't really understand. Thanks for the tips about bash -xe and EOF.
from laminar.
Yeah that is weird. Can you try removing the -e
from ssh [email protected] /bin/bash -xe
just to prove that this is the issue, and if so, the error code it returns might help diagnose the root cause
from laminar.
Same output, no error code.
from laminar.
Hmm, I'm not sure how else to help. Did you try executing the laminar .run
file directly yourself (not via laminar)? Or try the heredoc directly in a console?
from laminar.
Direct run also doesn't work. Oh, well not too bad. I will workaround with the remote script that works well so far. Thank you for support.
from laminar.
If you eventually figure this out I'd be interested in the solution. It's apparently not a laminar issue but since laminar encourages scripts as heredocs I can imagine this coming up again.
By the way, thanks very much for all your detailed issues, this is great QA and I think has really helped improve laminar.
from laminar.
You are welcome, I didn't want to a be a big pain in the ...
ad heredoc: I will if I find a solution let you know. One thing that I also noticed eg. from your example on Remote jobs is that you have to use #!/bin/bash -e on your .run script or else the job will always succeed. So might want to put that somewhere in the docs, that the scripts have to provide a valid exit code when something goes wrong.
Thank you for you help and also for fixing and improving your very nice software.
from laminar.
With 792c69a I added a note about -e
under Creating a job
from laminar.
Related Issues (20)
- Build jobs outputting loooong lines slowly may delay other server responses? HOT 1
- Do you implement login system to web ui? HOT 1
- Laminar own webhooks HOT 1
- Route from run to job? HOT 1
- SIGSEGV (with a few browser tabs and while fetching a large job log) HOT 12
- Show currently running `run` in graph on jobs page HOT 2
- FE: "Jobs" link not working with new-and-not-yet-built jobs HOT 5
- laminard: `pages` count wrong with no finished run for a given job HOT 3
- Better Average Runtime Calculation to see what to expect for the next builds HOT 1
- Issues with large databases / large job output HOT 28
- Add Content Security Policy (CSP) HOT 3
- Adding PostgreSQL support HOT 8
- Storing list of artifacts in database HOT 5
- Storing the list of artifacts in the database HOT 1
- [feature request] Abort button. HOT 1
- [PATCH] database: fix missing import HOT 1
- [PROPOSAL] Manual triggers HOT 2
- Shell not sourcing /etc/profile on NixOS HOT 3
- Question on packaging and directory permissions HOT 2
- SigMask has changed, says kj. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laminar.