Type: array
Value: ["<cmd-str>", "<cmd-str>", ... , "<cmd-str>"]
Attribute: If key
is set as ssh
, then value
should be ssh_cmds
only
Parent: None
List of commands executed by ssh
. <cmd-str>
is the standard linux command.
If you need to execute complicated commands including conditional-branch or loop-body, please write a standalone script and add execute it by <cmd-str>
:
[
{
"key": "scp",
"value":
[
......
{ "local": "upgrade.sh", "remote": "/data/tmp/" }
......
]
},
{
"key": "ssh",
"value":
[
......
"sh upgrader.sh"
......
]
}
......
]
Special tag: @index_place_holder
If <cmd-str>
is configured with @index_place_holder
, deploygen
will replace the tag with the sequence number in order of machines stored in host_file
.
For instance, configure deploy.json
like this:
[
{
"key": "scp",
"value":
[
{ "local": "zookeeper-3.4.8.tar.gz", "remote": "/data/" }
]
},
{
"key": "ssh",
"value":
[
"cd /data",
"test -d zookeeper-3.4.8 && mv zookeeper-3.4.8 zookeeper-3.4.8-old",
"tar -zxf zookeeper-3.4.8.tar.gz -C ."
]
},
{
"key": "scp",
"value":
[
{ "local": "zoo.cfg", "remote": "/data/zookeeper-3.4.8/conf/" }
]
},
{
"key": "ssh",
"value":
[
"cd /data/zookeeper-3.4.8",
"mkdir -p data",
"cd data/",
"echo \"@index_place_holder\" > myid",
"cd ../../",
"rm -f zookeeper-3.4.8.tar.gz"
]
}
]
Edit host.txt
as below:
192.168.1.101
192.168.1.102
192.168.1.103
Run command:
python deploygen.py jobs deploy.json host.txt > deploy.sh
The output script:
#!/bin/sh
##############################################################################
# NOTE : Generated by deploygen. It is NOT supposed to modify this file.
##############################################################################
echo '[192.168.1.101]...'
sudo -u jobs \
scp -oStrictHostKeyChecking=no \
zookeeper-3.4.8.tar.gz \
[email protected]:/data/
sudo -u jobs \
ssh -oStrictHostKeyChecking=no \
[email protected] \
' \
cd /data; \
test -d zookeeper-3.4.8 && mv zookeeper-3.4.8 zookeeper-3.4.8-old; \
tar -zxf zookeeper-3.4.8.tar.gz -C .; \
'
sudo -u jobs \
scp -oStrictHostKeyChecking=no \
zoo.cfg \
[email protected]:/data/zookeeper-3.4.8/conf/
sudo -u jobs \
ssh -oStrictHostKeyChecking=no \
[email protected] \
' \
cd /data/zookeeper-3.4.8; \
mkdir -p data; \
cd data/; \
echo "0" > myid; \
cd ../../; \
rm -f zookeeper-3.4.8.tar.gz; \
'
echo '[192.168.1.102]...'
sudo -u jobs \
scp -oStrictHostKeyChecking=no \
zookeeper-3.4.8.tar.gz \
[email protected]:/data/
sudo -u jobs \
ssh -oStrictHostKeyChecking=no \
[email protected] \
' \
cd /data; \
test -d zookeeper-3.4.8 && mv zookeeper-3.4.8 zookeeper-3.4.8-old; \
tar -zxf zookeeper-3.4.8.tar.gz -C .; \
'
sudo -u jobs \
scp -oStrictHostKeyChecking=no \
zoo.cfg \
[email protected]:/data/zookeeper-3.4.8/conf/
sudo -u jobs \
ssh -oStrictHostKeyChecking=no \
[email protected] \
' \
cd /data/zookeeper-3.4.8; \
mkdir -p data; \
cd data/; \
echo "1" > myid; \
cd ../../; \
rm -f zookeeper-3.4.8.tar.gz; \
'
echo '[192.168.1.103]...'
sudo -u jobs \
scp -oStrictHostKeyChecking=no \
zookeeper-3.4.8.tar.gz \
[email protected]:/data/
sudo -u jobs \
ssh -oStrictHostKeyChecking=no \
[email protected] \
' \
cd /data; \
test -d zookeeper-3.4.8 && mv zookeeper-3.4.8 zookeeper-3.4.8-old; \
tar -zxf zookeeper-3.4.8.tar.gz -C .; \
'
sudo -u jobs \
scp -oStrictHostKeyChecking=no \
zoo.cfg \
[email protected]:/data/zookeeper-3.4.8/conf/
sudo -u jobs \
ssh -oStrictHostKeyChecking=no \
[email protected] \
' \
cd /data/zookeeper-3.4.8; \
mkdir -p data; \
cd data/; \
echo "2" > myid; \
cd ../../; \
rm -f zookeeper-3.4.8.tar.gz; \
'
echo 'finish!'
As you see, @index_place_holder
is replaced by the sequence number in order.