mirror of https://github.com/rapenne-s/bento
bento: SFTP timeout is now configurable
This commit is contained in:
parent
457d4d9ee3
commit
b98bd0f845
|
@ -75,7 +75,7 @@ There is a diagram showing the design pattern of **bento**:
|
|||
- automatic reboot should be scheduled if desired, this may require making bento a NixOS module to set a timer in it, if no timer then it would reboot immediately
|
||||
- document config.sh in the reference
|
||||
- figure out how to make a tutorial for bento
|
||||
- sftp timeout should be configurable in `config.sh`
|
||||
- DONE ~~sftp timeout should be configurable in `config.sh`~~
|
||||
- `config.sh` should have variables for the local / remote / both `nixos-rebuild` parameters (useful for `--fallback`)
|
||||
|
||||
## Minor
|
||||
|
|
18
bento
18
bento
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
TIMEOUT=20
|
||||
|
||||
# FUNCTION LIBRARIES
|
||||
usage() {
|
||||
cat <<EOF
|
||||
|
@ -197,7 +199,7 @@ touch .state
|
|||
ssh-keygen -F "${REMOTE_IP}" >/dev/null || ssh-keyscan "${REMOTE_IP}" >> /root/.ssh/known_hosts
|
||||
|
||||
STATEFILE="\$(mktemp /tmp/bento-state.XXXXXXXXXXXXXXXX)"
|
||||
echo "ls -l last_change_date" | sftp -oConnectTimeout=20 ${dest}@${REMOTE_IP} >"\${STATEFILE}"
|
||||
echo "ls -l last_change_date" | sftp -oConnectTimeout="${TIMEOUT}" ${dest}@${REMOTE_IP} >"\${STATEFILE}"
|
||||
|
||||
if [ "\$?" -ne 0 ]
|
||||
then
|
||||
|
@ -227,7 +229,7 @@ then
|
|||
fi
|
||||
else
|
||||
echo "update required"
|
||||
sftp -oConnectTimeout=20 ${dest}@${REMOTE_IP}:/config/bootstrap.sh .
|
||||
sftp -oConnectTimeout="${TIMEOUT}" ${dest}@${REMOTE_IP}:/config/bootstrap.sh .
|
||||
/bin/sh bootstrap.sh
|
||||
echo "\${STATE}" > "/var/bento/.state"
|
||||
fi
|
||||
|
@ -252,7 +254,7 @@ then
|
|||
find . -maxdepth 1 -type d -exec rm -fr {} \;
|
||||
find . -maxdepth 1 -type f -not -name .state -and -not -name update.sh -and -not -name bootstrap.sh -exec rm {} \;
|
||||
|
||||
printf "%s\n" "cd config" "get -R ." | sftp -oConnectTimeout=20 -r ${dest}@${REMOTE_IP}:
|
||||
printf "%s\n" "cd config" "get -R ." | sftp -oConnectTimeout="${TIMEOUT}" -r ${dest}@${REMOTE_IP}:
|
||||
|
||||
# required by flakes
|
||||
test -d .git || git init
|
||||
|
@ -317,7 +319,7 @@ fi
|
|||
|
||||
# rollback if something is wrong
|
||||
# we test connection to the sftp server
|
||||
echo "ls -l last_change_date" | sftp -oConnectTimeout=20 ${dest}@${REMOTE_IP} >"\${LOGFILE}"
|
||||
echo "ls -l last_change_date" | sftp -oConnectTimeout="${TIMEOUT}" ${dest}@${REMOTE_IP} >"\${LOGFILE}"
|
||||
if [ "\$?" -ne 0 ];
|
||||
then
|
||||
nixos-rebuild --rollback switch
|
||||
|
@ -330,9 +332,9 @@ if [ "\$SUCCESS" -eq 0 ]
|
|||
then
|
||||
if [ "\$autoupdate" -eq 1 ]
|
||||
then
|
||||
echo "put \${LOGFILE}.gz /logs/\$(date +%Y%m%d-%H%M)_\${OSVERSION}_autoupdate.log.gz" | sftp -oConnectTimeout=20 ${dest}@${REMOTE_IP}:
|
||||
echo "put \${LOGFILE}.gz /logs/\$(date +%Y%m%d-%H%M)_\${OSVERSION}_autoupdate.log.gz" | sftp -oConnectTimeout="${TIMEOUT}" ${dest}@${REMOTE_IP}:
|
||||
else
|
||||
echo "put \${LOGFILE}.gz /logs/\$(date +%Y%m%d-%H%M)_\${OSVERSION}_success.log.gz" | sftp -oConnectTimeout=20 ${dest}@${REMOTE_IP}:
|
||||
echo "put \${LOGFILE}.gz /logs/\$(date +%Y%m%d-%H%M)_\${OSVERSION}_success.log.gz" | sftp -oConnectTimeout="${TIMEOUT}" ${dest}@${REMOTE_IP}:
|
||||
fi
|
||||
|
||||
# handle auto reboot if kernel changed
|
||||
|
@ -350,9 +352,9 @@ else
|
|||
# check if we did a rollback
|
||||
if [ "\$SUCCESS" -eq 255 ]
|
||||
then
|
||||
echo "put \${LOGFILE}.gz /logs/\$(date +%Y%m%d-%H%M)_\${OSVERSION}_rollback.log.gz" | sftp -oConnectTimeout=20 ${dest}@${REMOTE_IP}:
|
||||
echo "put \${LOGFILE}.gz /logs/\$(date +%Y%m%d-%H%M)_\${OSVERSION}_rollback.log.gz" | sftp -oConnectTimeout="${TIMEOUT}" ${dest}@${REMOTE_IP}:
|
||||
else
|
||||
echo "put \${LOGFILE}.gz /logs/\$(date +%Y%m%d-%H%M)_\${OSVERSION}_failure.log.gz" | sftp -oConnectTimeout=20 ${dest}@${REMOTE_IP}:
|
||||
echo "put \${LOGFILE}.gz /logs/\$(date +%Y%m%d-%H%M)_\${OSVERSION}_failure.log.gz" | sftp -oConnectTimeout="${TIMEOUT}" ${dest}@${REMOTE_IP}:
|
||||
fi
|
||||
fi
|
||||
rm "\${LOGFILE}.gz"
|
||||
|
|
|
@ -1,2 +1,8 @@
|
|||
CHROOT_DIR=/home/chroot
|
||||
REMOTE_IP=myserver.example
|
||||
|
||||
# Optional
|
||||
|
||||
# maxium time waiting for the SFTP connection to connect
|
||||
# default value is 20
|
||||
#TIMEOUT=20
|
||||
|
|
|
@ -19,6 +19,14 @@
|
|||
- `env NAME=someconfig bento deploy|build`
|
||||
- only build / deploy the system "someconfig"
|
||||
|
||||
# Configuration file
|
||||
|
||||
A local file `config.sh` is required for Bento, it contains variable used to generate the scripts:
|
||||
|
||||
- `CHROOT_DIR`: the directory in which the SFTP server will be configured to serve files from
|
||||
- `REMOTE_IP`: the IP address or hostname used by SFTP client to reach the server with the configuration files
|
||||
- `TIMEOUT`: time in seconds to wait until aborting when connecting to the SFTP server. Default value is `20` seconds.
|
||||
|
||||
# Environment variables
|
||||
|
||||
`bento` is using the following environment variables as configuration:
|
||||
|
|
Loading…
Reference in New Issue