vagrant centos8 and freebsd
This commit is contained in:
parent
ab73794292
commit
46738d4b37
4 changed files with 64 additions and 76 deletions
|
|
@ -53,8 +53,10 @@ 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):
|
||||
test -d $@ || mkdir -p $@
|
||||
./vagrant.sh $@ destroy 2>&1 | tee $@.log
|
||||
|
||||
clean:
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ in a "site.mk" file. You can add such a file, eg:
|
|||
VAGRANTS += generic/centos8
|
||||
```
|
||||
|
||||
Logs appear in : <hostname>.log.
|
||||
Logs appear in : <dir>/<hostname>.log.
|
||||
|
||||
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/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)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,63 +2,32 @@
|
|||
# Nginx config script. There are different variants of nginx configs, just off-loading
|
||||
# this to a separate script to hide the complexity
|
||||
|
||||
set -eux
|
||||
set -ux
|
||||
|
||||
if [ $# -ne 3 ]; then
|
||||
echo "usage: $0 <dir> <idfile> <port>"
|
||||
if [ $# -ne 4 ]; then
|
||||
echo "usage: $0 <dir> <idfile> <port> <wwwuser>"
|
||||
exit -1
|
||||
fi
|
||||
dir=$1
|
||||
idfile=$2
|
||||
port=$3
|
||||
wwwuser=$4
|
||||
|
||||
# Macros to access target via ssh
|
||||
sshcmd="ssh -o StrictHostKeyChecking=no -i $idfile -p $port vagrant@127.0.0.1"
|
||||
scpcmd="scp -o StrictHostKeyChecking=no -p -i $idfile -P $port"
|
||||
|
||||
if $($sshcmd test -d /etc/nginx/conf.d) ; then
|
||||
confd=true
|
||||
if [ $($sshcmd test -d /usr/local/etc/nginx; echo $?) = 0 ]; then
|
||||
prefix=/usr/local # eg freebsd
|
||||
else
|
||||
confd=false
|
||||
prefix=
|
||||
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
|
||||
cat<<'EOF' > $dir/nginx.conf
|
||||
cat<<EOF > $dir/nginx.conf
|
||||
#
|
||||
user $wwwuser;
|
||||
error_log /var/log/nginx/error.log;
|
||||
worker_processes 1;
|
||||
events {
|
||||
worker_connections 1024;
|
||||
|
|
@ -68,10 +37,6 @@ http {
|
|||
include mime.types;
|
||||
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;
|
||||
|
||||
sendfile on;
|
||||
|
|
@ -87,6 +52,7 @@ http {
|
|||
listen [::]:80 default_server;
|
||||
server_name localhost;
|
||||
server_name _;
|
||||
#:well-known is in root, otherwise restconf would be ok
|
||||
location / {
|
||||
fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
|
||||
include fastcgi_params;
|
||||
|
|
@ -100,20 +66,31 @@ http {
|
|||
}
|
||||
}
|
||||
EOF
|
||||
$scpcmd $dir/nginx.conf vagrant@127.0.0.1:
|
||||
cat<<EOF > $dir/startnginx.sh
|
||||
$scpcmd $dir/nginx.conf vagrant@127.0.0.1:
|
||||
cat<<'EOF' > $dir/startnginx.sh
|
||||
#!/usr/bin/env bash
|
||||
if [ $# -ne 0 -a $# -ne 1 ]; then
|
||||
echo "usage: $0 [<prefix>"]
|
||||
exit
|
||||
fi
|
||||
prefix=$1
|
||||
# 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
|
||||
sudo sh -c ' echo 'nginx_enable="YES"' >> /etc/rc.conf'
|
||||
fi
|
||||
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
|
||||
|
||||
fi # full nginx config
|
||||
|
||||
chmod a+x $dir/startnginx.sh
|
||||
$scpcmd $dir/startnginx.sh vagrant@127.0.0.1:
|
||||
$sshcmd ./startnginx.sh
|
||||
|
||||
$sshcmd ./startnginx.sh $prefix
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,13 @@ if [ $# -eq 2 ]; then
|
|||
else
|
||||
destroy=false
|
||||
fi
|
||||
|
||||
host=$(echo "$box"|awk -F'/' '{print $2}')
|
||||
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
|
||||
release=$(echo "$host" | grep -io "[a-z]*" | head -1 | tr '[:upper:]' '[:lower:]')
|
||||
wwwuser=www-data
|
||||
|
||||
# example box="freebsd/FreeBSD-12.1-STABLE"
|
||||
test -d $dir || mkdir -p $dir
|
||||
|
|
@ -64,8 +66,11 @@ case $system in
|
|||
$sshcmd sudo pkg install -y git gmake bash
|
||||
# cligen
|
||||
$sshcmd sudo pkg install -y bison flex
|
||||
# clixon
|
||||
$sshcmd sudo pkg install -y fcgi-devkit nginx # FreeBSD
|
||||
# Add www user for nginx
|
||||
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)
|
||||
case $release in
|
||||
|
|
@ -75,6 +80,9 @@ case $system in
|
|||
# cligen
|
||||
$sshcmd sudo yum install -y bison flex
|
||||
# clixon
|
||||
if [ ! $($sshcmd id -u $wwwuser) ]; then
|
||||
$sshcmd sudo useradd -M $wwwuser
|
||||
fi
|
||||
$sshcmd sudo yum install -y fcgi-devel nginx
|
||||
# clixon utilities
|
||||
$sshcmd sudo yum install -y libcurl-devel
|
||||
|
|
@ -82,6 +90,7 @@ case $system in
|
|||
opensuse) # opensuse42
|
||||
# clixon
|
||||
$sshcmd sudo zypper install -y nginx
|
||||
# XXX: no fastcgi package?
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
|
|
@ -93,29 +102,31 @@ case $system in
|
|||
esac
|
||||
|
||||
# Hide all complex nginx config in sub-script
|
||||
. ./nginx.sh $dir $idfile $port
|
||||
. ./nginx.sh $dir $idfile $port $wwwuser
|
||||
|
||||
# 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 $
|
||||
cat<<'EOF' > $dir/setup.sh
|
||||
#!/usr/bin/env bash
|
||||
set -eux # x
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "usage: $0 <release>"
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "usage: $0 <release> <wwwuser>"
|
||||
exit -1
|
||||
fi
|
||||
release=$1
|
||||
wwwuser=$2
|
||||
# create user & group
|
||||
if [ ! $(id -u clicon) ]; 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 www;
|
||||
sudo pw group mod clicon -m $wwwuser;
|
||||
else
|
||||
sudo useradd clicon;
|
||||
sudo usermod -a -G clicon vagrant;
|
||||
sudo usermod -a -G clicon nginx; # nginx?
|
||||
sudo usermod -a -G clicon $wwwuser;
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
@ -144,10 +155,10 @@ cd src/clixon
|
|||
git pull
|
||||
|
||||
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
|
||||
# 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
|
||||
$MAKE clean
|
||||
$MAKE -j10
|
||||
|
|
@ -160,18 +171,15 @@ sudo ldconfig
|
|||
cd test
|
||||
echo "#!/usr/bin/env bash" > ./site.sh
|
||||
if [ $release = "freebsd" ]; then
|
||||
echo "wwwuser=www" >> ./site.sh
|
||||
echo "make=gmake" >> ./site.sh
|
||||
echo 'SKIPLIST="test_api.sh"' >> ./site.sh
|
||||
else
|
||||
echo "wwwuser=nginx" >> ./site.sh
|
||||
echo "make=gmake" >> ./site.sh
|
||||
echo 'SKIPLIST="test_api.sh"' >> ./site.sh
|
||||
fi
|
||||
EOF
|
||||
chmod a+x $dir/setup.sh
|
||||
|
||||
# config and setup cligen and clixon
|
||||
$scpcmd $dir/setup.sh vagrant@127.0.0.1:
|
||||
$sshcmd ./setup.sh $release
|
||||
$sshcmd ./setup.sh $release $wwwuser
|
||||
|
||||
# Run tests
|
||||
$sshcmd "(cd src/cligen/test; ./sum.sh)"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue