vagrant centos8 and freebsd

This commit is contained in:
Olof Hagsand 2020-06-08 13:07:34 +00:00
parent ab73794292
commit 46738d4b37
4 changed files with 64 additions and 76 deletions

View file

@ -53,8 +53,10 @@ VAGRANTS =
all: $(VAGRANTS) all: $(VAGRANTS)
# Local vagrant hosts # Local vagrant hosts eg generic/centos8. The vagrantdir is a subdirectory and logs will
# appear eg as generic/centos8.log
$(VAGRANTS): $(VAGRANTS):
test -d $@ || mkdir -p $@
./vagrant.sh $@ destroy 2>&1 | tee $@.log ./vagrant.sh $@ destroy 2>&1 | tee $@.log
clean: clean:

View file

@ -13,7 +13,7 @@ in a "site.mk" file. You can add such a file, eg:
VAGRANTS += generic/centos8 VAGRANTS += generic/centos8
``` ```
Logs appear in : <hostname>.log. Logs appear in : <dir>/<hostname>.log.
You can also run a single vagrant test as follows: You can also run a single vagrant test as follows:
``` ```
@ -25,4 +25,5 @@ The current status is as follows
* generic/centos8 - some remaining nginx issue * generic/centos8 - some remaining nginx issue
* generic/opensuse42 - fastcgi is not installed * generic/opensuse42 - fastcgi is not installed
See more Vagrant boxes at [https://vagrantcloud.com/search]). For other vagrant boxes, see [search vagrant boxes](https://vagrantcloud.com/search)

View file

@ -2,63 +2,32 @@
# Nginx config script. There are different variants of nginx configs, just off-loading # Nginx config script. There are different variants of nginx configs, just off-loading
# this to a separate script to hide the complexity # this to a separate script to hide the complexity
set -eux set -ux
if [ $# -ne 3 ]; then if [ $# -ne 4 ]; then
echo "usage: $0 <dir> <idfile> <port>" echo "usage: $0 <dir> <idfile> <port> <wwwuser>"
exit -1 exit -1
fi fi
dir=$1 dir=$1
idfile=$2 idfile=$2
port=$3 port=$3
wwwuser=$4
# Macros to access target via ssh
sshcmd="ssh -o StrictHostKeyChecking=no -i $idfile -p $port vagrant@127.0.0.1" sshcmd="ssh -o StrictHostKeyChecking=no -i $idfile -p $port vagrant@127.0.0.1"
scpcmd="scp -o StrictHostKeyChecking=no -p -i $idfile -P $port" scpcmd="scp -o StrictHostKeyChecking=no -p -i $idfile -P $port"
if $($sshcmd test -d /etc/nginx/conf.d) ; then if [ $($sshcmd test -d /usr/local/etc/nginx; echo $?) = 0 ]; then
confd=true prefix=/usr/local # eg freebsd
else else
confd=false prefix=
fi fi
if $confd; then # conf.d nginx config
cat <<EOF > $dir/default.conf
#
server {
listen 80 default_server;
listen localhost:80 default_server;
listen [::]:80 default_server;
server_name localhost;
server_name _;
location / {
fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
include fastcgi_params;
}
location /streams {
fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
include fastcgi_params;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}
EOF
$scpcmd $dir/default.conf vagrant@127.0.0.1:
cat<<EOF > $dir/startnginx.sh
sudo cp default.conf /etc/nginx/conf.d/
# if [ ! -d /run/nginx ]; then
# sudo mkdir /run/nginx
# fi
# Start nginx
/usr/sbin/nginx -c /etc/nginx/nginx.conf
>&2 echo "nginx started"
EOF
else # full nginx config
# Nginx conf file # Nginx conf file
cat<<'EOF' > $dir/nginx.conf cat<<EOF > $dir/nginx.conf
# #
user $wwwuser;
error_log /var/log/nginx/error.log;
worker_processes 1; worker_processes 1;
events { events {
worker_connections 1024; worker_connections 1024;
@ -68,10 +37,6 @@ http {
include mime.types; include mime.types;
default_type application/octet-stream; default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main; #access_log logs/access.log main;
sendfile on; sendfile on;
@ -87,6 +52,7 @@ http {
listen [::]:80 default_server; listen [::]:80 default_server;
server_name localhost; server_name localhost;
server_name _; server_name _;
#:well-known is in root, otherwise restconf would be ok
location / { location / {
fastcgi_pass unix:/www-data/fastcgi_restconf.sock; fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
include fastcgi_params; include fastcgi_params;
@ -100,20 +66,31 @@ http {
} }
} }
EOF EOF
$scpcmd $dir/nginx.conf vagrant@127.0.0.1: $scpcmd $dir/nginx.conf vagrant@127.0.0.1:
cat<<EOF > $dir/startnginx.sh cat<<'EOF' > $dir/startnginx.sh
#!/usr/bin/env bash #!/usr/bin/env bash
if [ $# -ne 0 -a $# -ne 1 ]; then
echo "usage: $0 [<prefix>"]
exit
fi
prefix=$1
# start nginx # start nginx
sudo cp nginx.conf /usr/local/etc/nginx/ sudo cp nginx.conf $prefix/etc/nginx/
if [ -d /etc/rc.conf ]; then # freebsd
if [ ! $(grep nginx_enable /etc/rc.conf) ]; then if [ ! $(grep nginx_enable /etc/rc.conf) ]; then
sudo sh -c ' echo 'nginx_enable="YES"' >> /etc/rc.conf' sudo sh -c ' echo 'nginx_enable="YES"' >> /etc/rc.conf'
fi fi
sudo /usr/local/etc/rc.d/nginx restart sudo /usr/local/etc/rc.d/nginx restart
else
sudo pkill nginx
nginxbin=$(which nginx)
sudo $nginxbin -c $prefix/etc/nginx/nginx.conf
fi
EOF EOF
fi # full nginx config
chmod a+x $dir/startnginx.sh chmod a+x $dir/startnginx.sh
$scpcmd $dir/startnginx.sh vagrant@127.0.0.1: $scpcmd $dir/startnginx.sh vagrant@127.0.0.1:
$sshcmd ./startnginx.sh
$sshcmd ./startnginx.sh $prefix

View file

@ -19,11 +19,13 @@ if [ $# -eq 2 ]; then
else else
destroy=false destroy=false
fi fi
host=$(echo "$box"|awk -F'/' '{print $2}') host=$(echo "$box"|awk -F'/' '{print $2}')
dir=$box dir=$box
# XXX: ad-hoc to get (linus) release from boxname # XXX: ad-hoc to get (linux) release from boxname
# using lsb_release is too heavyweight in many cases # using lsb_release is too heavyweight in many cases
release=$(echo "$host" | grep -io "[a-z]*" | head -1 | tr '[:upper:]' '[:lower:]') release=$(echo "$host" | grep -io "[a-z]*" | head -1 | tr '[:upper:]' '[:lower:]')
wwwuser=www-data
# example box="freebsd/FreeBSD-12.1-STABLE" # example box="freebsd/FreeBSD-12.1-STABLE"
test -d $dir || mkdir -p $dir test -d $dir || mkdir -p $dir
@ -64,8 +66,11 @@ case $system in
$sshcmd sudo pkg install -y git gmake bash $sshcmd sudo pkg install -y git gmake bash
# cligen # cligen
$sshcmd sudo pkg install -y bison flex $sshcmd sudo pkg install -y bison flex
# clixon # Add www user for nginx
$sshcmd sudo pkg install -y fcgi-devkit nginx # FreeBSD if [ ! $($sshcmd id -u $wwwuser) ]; then
$sshcmd sudo pw useradd $wwwuser -d /nonexistent -s /usr/sbin/nologin
fi
$sshcmd sudo pkg install -y fcgi-devkit nginx
;; ;;
Linux) Linux)
case $release in case $release in
@ -75,6 +80,9 @@ case $system in
# cligen # cligen
$sshcmd sudo yum install -y bison flex $sshcmd sudo yum install -y bison flex
# clixon # clixon
if [ ! $($sshcmd id -u $wwwuser) ]; then
$sshcmd sudo useradd -M $wwwuser
fi
$sshcmd sudo yum install -y fcgi-devel nginx $sshcmd sudo yum install -y fcgi-devel nginx
# clixon utilities # clixon utilities
$sshcmd sudo yum install -y libcurl-devel $sshcmd sudo yum install -y libcurl-devel
@ -82,6 +90,7 @@ case $system in
opensuse) # opensuse42 opensuse) # opensuse42
# clixon # clixon
$sshcmd sudo zypper install -y nginx $sshcmd sudo zypper install -y nginx
# XXX: no fastcgi package?
;; ;;
*) *)
;; ;;
@ -93,29 +102,31 @@ case $system in
esac esac
# Hide all complex nginx config in sub-script # Hide all complex nginx config in sub-script
. ./nginx.sh $dir $idfile $port . ./nginx.sh $dir $idfile $port $wwwuser
# Setup cligen and clixon # Setup cligen and clixon
# This is a script generated at the original host, then copied to the target and run there.
# 'EOF' means dont expand $ # 'EOF' means dont expand $
cat<<'EOF' > $dir/setup.sh cat<<'EOF' > $dir/setup.sh
#!/usr/bin/env bash #!/usr/bin/env bash
set -eux # x set -eux # x
if [ $# -ne 1 ]; then if [ $# -ne 2 ]; then
echo "usage: $0 <release>" echo "usage: $0 <release> <wwwuser>"
exit -1 exit -1
fi fi
release=$1 release=$1
wwwuser=$2
# create user & group # create user & group
if [ ! $(id -u clicon) ]; then if [ ! $(id -u clicon) ]; then
if [ $release = "freebsd" ]; then if [ $release = "freebsd" ]; then
sudo pw useradd clicon; sudo pw useradd clicon -d /nonexistent -s /usr/sbin/nologin;
sudo pw group mod clicon -m vagrant; sudo pw group mod clicon -m vagrant;
sudo pw group mod clicon -m www; sudo pw group mod clicon -m $wwwuser;
else else
sudo useradd clicon; sudo useradd clicon;
sudo usermod -a -G clicon vagrant; sudo usermod -a -G clicon vagrant;
sudo usermod -a -G clicon nginx; # nginx? sudo usermod -a -G clicon $wwwuser;
fi fi
fi fi
@ -144,10 +155,10 @@ cd src/clixon
git pull git pull
if [ $release = "freebsd" ]; then if [ $release = "freebsd" ]; then
LDFLAGS=-L/usr/local/lib ./configure --with-wwwuser=www --enable-optyangs LDFLAGS=-L/usr/local/lib ./configure --with-cligen=/usr/local --enable-optyangs
else else
# Problems with su not having "sbin" in path on centos when when we run tests later # Problems with su not having "sbin" in path on centos when when we run tests later
./configure --sbindir=/usr/sbin --libdir=/usr/lib --with-wwwuser=nginx --enable-optyangs ./configure --sbindir=/usr/sbin --libdir=/usr/lib --enable-optyangs
fi fi
$MAKE clean $MAKE clean
$MAKE -j10 $MAKE -j10
@ -160,18 +171,15 @@ sudo ldconfig
cd test cd test
echo "#!/usr/bin/env bash" > ./site.sh echo "#!/usr/bin/env bash" > ./site.sh
if [ $release = "freebsd" ]; then if [ $release = "freebsd" ]; then
echo "wwwuser=www" >> ./site.sh echo "make=gmake" >> ./site.sh
echo "make=gmake" >> ./site.sh echo 'SKIPLIST="test_api.sh"' >> ./site.sh
echo 'SKIPLIST="test_api.sh"' >> ./site.sh
else
echo "wwwuser=nginx" >> ./site.sh
fi fi
EOF EOF
chmod a+x $dir/setup.sh chmod a+x $dir/setup.sh
# config and setup cligen and clixon # config and setup cligen and clixon
$scpcmd $dir/setup.sh vagrant@127.0.0.1: $scpcmd $dir/setup.sh vagrant@127.0.0.1:
$sshcmd ./setup.sh $release $sshcmd ./setup.sh $release $wwwuser
# Run tests # Run tests
$sshcmd "(cd src/cligen/test; ./sum.sh)" $sshcmd "(cd src/cligen/test; ./sum.sh)"