GithubHelp home page GithubHelp logo

nginx / unit Goto Github PK

View Code? Open in Web Editor NEW
5.1K 130.0 313.0 12.17 MB

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.

Home Page: https://unit.nginx.org

License: Apache License 2.0

Makefile 1.28% C 59.88% Go 0.39% C++ 1.00% Perl 0.21% PHP 0.14% Shell 1.22% Python 13.90% Roff 0.35% Ruby 0.23% HTML 0.06% JavaScript 1.80% Java 15.74% Raku 0.02% Dockerfile 0.11% Rust 3.64% Mustache 0.03%

unit's Introduction

NGINX Unit

Project Status: Active – The project has reached a stable, usable state and is being actively developed. CI

Universal Web App Server

NGINX Unit Logo

NGINX Unit is a lightweight and versatile open-source server that has two primary capabilities:

  • serves static media assets,
  • runs application code in seven languages.

Unit compresses several layers of the modern application stack into a potent, coherent solution with a focus on performance, low latency, and scalability. It is intended as a universal building block for any web architecture regardless of its complexity, from enterprise-scale deployments to your pet's homepage.

Its native RESTful JSON API enables dynamic updates with zero interruptions and flexible configuration, while its out-of-the-box productivity reliably scales to production-grade workloads. We achieve that with a complex, asynchronous, multithreading architecture comprising multiple processes to ensure security and robustness while getting the most out of today's computing platforms.

Installation

macOS

Run the following command to install both unitd (the Unit daemon) and unitctl (the control tool).

$ brew install nginx/unit/unit

For details and available language packages, see the docs.

Docker

$ docker pull unit:<TAG>
$ mkdir /tmp/unit-control # customize as needed.
$ docker run -d \
      --mount type=bind,src=/tmp/unit-control,dst=/var/run \
      --mount type=bind,src=.,dst=/www \
      --network host \
      unit

For a description of image tags, see the docs.

WARNING: latest image tag may not provide support for specific language modules, do check the available image tags from the link above before pulling your image.

Your current working directory will now be mounted to the Unit image at /www. You can reach its socket at /tmp/unit-control/control.unit.sock assuming no further customizations have been made.

Debian, Ubuntu, Amazon Linux, Fedora, Red Hat

This helper script configures the correct package repositories for system.

$ wget https://raw.githubusercontent.com/nginx/unit/master/tools/setup-unit && chmod +x setup-unit
# ./setup-unit repo-config

Debian derivatives:

# apt install unit

Fedora derivatives:

# yum install unit

For details and available language packages, see the docs.

Getting Started with unitctl

unitctl streamlines the management of NGINX Unit processes through an easy-to-use command line interface. To get started with unitctl, download it from the official GitHub releases or Homebrew.

Installation

Note

If you installed Unit with Homebrew, you can skip this step as unitctl is included by default.

Download the appropriate unitctl binary for your system from the NGINX Unit releases.

$ tar xzvf unitctl-master-x86_64-unknown-linux-gnu.tar.gz
# mv unitctl /usr/local/bin/

Launch Unit using Docker

If you have Docker installed on your machine, and then you can effortlessly spin up one of Unit's official Docker images alongside your application.

Tip

How-to and configuration guides are available on unit.nginx.org for web application frameworks built with Python, PHP, WebAssembly, Node.js, Ruby, and more.

Here's an example using the unit:python Docker image:

$ unitctl instances new 127.0.0.1:8001 /path/to/app 'unit:python'

/path/to/app will mount to /www in the Docker filesystem.

Save this to /path/to/app/wsgi.py:

def application(environ, start_response):
    start_response("200 OK", [("Content-Type", "text/plain")])
    return (b"Hello, Python on Unit!")

You can then interactively edit the currently active configuration:

$ unitctl edit
{
  "listeners": {
    "*:8000": {
      // Point listener to new application
      "pass": "applications/python"
    }
  },

  // Add an application definition
  "applications": {
    "python": {
        "type": "python",
        "path": "/www/",
        "module": "wsgi"
    }
  }
}

Valid configurations will be applied upon save and close.

$ curl localhost:8000

Hello, Python on Unit!

More Python configuration examples can be found in the Unit docs.

Hello World with PHP and curl

Unit runs apps in a variety of languages. Let's explore the configuration of a simple PHP app on Unit with curl.

Suppose you saved a PHP script as /www/helloworld/index.php:

<?php echo "Hello, PHP on Unit!"; ?>

To run it on Unit with the unit-php module installed, first set up an application object. Let's store our first config snippet in a file called config.json:

{
    "helloworld": {
        "type": "php",
        "root": "/www/helloworld/"
    }
}

Saving it as a file isn't necessary, but can come in handy with larger objects.

Now, PUT it into the /config/applications section of Unit's control API, usually available by default via a Unix domain socket:

# curl -X PUT --data-binary @config.json --unix-socket  \
       /path/to/control.unit.sock http://localhost/config/applications
{
	"success": "Reconfiguration done."
}

Next, reference the app from a listener object in the /config/listeners section of the API. This time, we pass the config snippet straight from the command line:

# curl -X PUT -d '{"127.0.0.1:8080": {"pass": "applications/helloworld"}}'  \
       --unix-socket /path/to/control.unit.sock http://localhost/config/listeners
{
    "success": "Reconfiguration done."
}

Now Unit accepts requests at the specified IP and port, passing them to the application process. Your app works!

$ curl 127.0.0.1:8080

      Hello, PHP on Unit!

Finally, query the entire /config section of the control API:

# curl --unix-socket /path/to/control.unit.sock http://localhost/config/

Unit's output should contain both snippets, neatly organized:

{
    "listeners": {
        "127.0.0.1:8080": {
            "pass": "applications/helloworld"
        }
    },

    "applications": {
        "helloworld": {
            "type": "php",
            "root": "/www/helloworld/"
        }
    }
}

WebAssembly

Unit supports running WebAssembly Components (WASI 0.2). For more information see the Unit Configuration Docs.

OpenAPI Specification

Our OpenAPI specification aims to simplify configuring and integrating NGINX Unit deployments and provide an authoritative source of knowledge about the control API.

Community

  • The go-to place to start asking questions and share your thoughts is GitHub Discussions.

  • Our GitHub issues page offers space for a more technical discussion at your own pace.

  • The project map on GitHub sheds some light on our current work and plans for the future.

  • Our official website may provide answers not easily found otherwise.

  • Get involved with the project by contributing! See the contributing guide for details.

  • To reach the team directly, subscribe to the mailing list.

  • For security issues, email us, mentioning NGINX Unit in the subject and following the CVSS v3.1 spec.

unit's People

Contributors

ac000 avatar alejandro-colomar avatar alexcrichton avatar andrey-zelenkov avatar arbourd avatar avagin avatar avahahn avatar callahad avatar danielledeleo avatar defanator avatar dependabot[bot] avatar hongzhidao avatar i4ki avatar igorsysoev avatar javorszky avatar lcrilly avatar mar0x avatar mdocguard avatar nshadrin avatar ocanty avatar osokin avatar outoffocus4 avatar pluknet avatar remicollet avatar svt09 avatar synodriver avatar tarynmusgrave avatar tclesius avatar thresheek avatar vbart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unit's Issues

source install error: ‘build/php56.unit.so’ and ‘build/php56.unit.so’ are the same file

Doing source install and make install command has an error

install: ‘build/php56.unit.so’ and ‘build/php56.unit.so’ are the same file

System:

  • CentOS 7.4 64bit
  • PHP-FPM 5.6.31 source installed
  • Go 1.9 binary
  • Python 2.7 yum installed
./configure
configuring for Linux 3.10.0-693.2.2.el7.x86_64 x86_64
checking for C compiler: gcc
 + using GNU C compiler
 + gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) 
building an "echo" program
checking for int size ... 4
checking for long size ... 8
checking for long long size ... 8
checking for void * size ... 8
checking for size_t size ... 8
checking for off_t size ... 8
checking for time_t size ... 8
checking for C99 variadic macro ... found
checking for GCC __builtin_expect() ... found
checking for GCC __builtin_unreachable() ... found
checking for GCC __builtin_prefetch() ... not found
checking for GCC __builtin_clz() ... found
checking for GCC __attribute__ visibility ... found
checking for GCC __attribute__ aligned ... found
checking for GCC __attribute__ malloc ... found
checking for GCC __attribute__ packed ... found
checking for GCC builtin atomic operations ... found
checking for posix_memalign() ... found
checking for Linux malloc_usable_size() ... found
checking for alloca() ... found
checking for MAP_ANON ... found
checking for MAP_POPULATE ... found
checking for MAP_PREFAULT_READ ... not found
checking for shm_open() ... found
checking for memfd_create() ... found
checking for Linux clock_gettime(CLOCK_REALTIME_COARSE) ... found
checking for FreeBSD clock_gettime(CLOCK_REALTIME_FAST) ... not found
checking for clock_gettime(CLOCK_REALTIME) ... found
checking for Linux clock_gettime(CLOCK_MONOTONIC_COARSE) ... found
checking for FreeBSD clock_gettime(CLOCK_MONOTONIC_FAST) ... not found
checking for clock_gettime(CLOCK_MONOTONIC) ... found
checking for HP-UX hg_gethrtime() ... not found
checking for struct tm.tm_gmtoff ... found
checking for altzone ... not found
checking for localtime_r() ... found
checking for pthread_yield() ... found
checking for pthread spinlock ... found
checking for pthread spinlock zero initial value ... found but is not working
checking for MacOSX spinlock ... not found
checking for sem_timedwait() ... not found
checking for sem_timedwait() in libpthread ... found
checking for __thread ... found
checking for Linux epoll ... found
checking for Linux signalfd() ... found
checking for Linux eventfd() ... found
checking for kqueue ... not found
checking for Solaris event port ... not found
checking for /dev/poll ... not found
checking for AIX pollset ... not found
checking for AF_INET6 ... found
checking for sockaddr.sa_len ... not found
checking for struct sockaddr size ... 16
checking for struct sockaddr_in size ... 16
checking for struct sockaddr_in6 size ... 28
checking for struct sockaddr_un size ... 110
checking for struct sockaddr_storage size ... 128
checking for socketpair(AF_UNIX, SOCK_SEQPACKET) ... found
checking for struct msghdr.msg_control ... found
checking for sys/filio.h ... not found
checking for ioctl(FIONBIO) ... found
checking for socket(SOCK_NONBLOCK) ... found
checking for accept4() ... found
checking for Linux sendfile() ... found
checking for posix_fadvise() ... found
checking for fcntl(F_READAHEAD) ... not found
checking for fcntl(F_RDAHEAD) ... not found
checking for getrandom() ... not found
checking for ucontext ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for posix_spawn() ... found
checking for setproctitle() ... not found
creating build/Makefile

Configuration summary:

  unit pid file:             "unit.pid"
  unit log file:             "unit.log"
  unit modules path:         "build"
  unit state path:           "build"

  unit control API socket:   "unix:control.unit.sock"

  non-privileged user:          "nobody"
  non-privileged group:         ""

  IPv6 support:                 YES
  Unix domain sockets support:  YES
  debug logging:                NO
./configure go
configuring Go package
checking for Go ... found
 + go version go1.9 linux/amd64
 + Go package path: "/root/golang/packages"
./configure php --module=php56 --config=/usr/local/bin/php-config
configuring PHP module
checking for PHP ... found
 + PHP version: 5.6.31
 + PHP SAPI: [cli embed fpm cgi]
checking for PHP embed SAPI ... found
 + PHP module: php56.unit.so
./configure python
configuring Python module
checking for Python ... found
checking for Python version ... 2.7.5
 + Python module: python.unit.so

after make all ran make install

make install
install -d sbin
install -p build/unitd sbin/
install -d /root/golang/packages/src/unit
install -p -m644 ./src/go/unit/* /root/golang/packages/src/unit/
CGO_CFLAGS="-I/svr-setup/unit/build -I/svr-setup/unit/src" \
        CGO_LDFLAGS="-L/svr-setup/unit/build -lrt" \
        GOPATH=/root/golang/packages \
        go install -v unit
unit
install -d build
install -p build/php56.unit.so \
        build/
install: ‘build/php56.unit.so’ and ‘build/php56.unit.so’ are the same file
make: *** [php56-install] Error 1

build directory

ls -lah build/  
total 7.1M
drwxr-xr-x 4 root root 4.0K Sep 23 05:14 .
drwxr-xr-x 8 root root 4.0K Sep 23 05:13 ..
-rw-r--r-- 1 root root  350 Sep 23 05:13 autoconf.data
-rw-r--r-- 1 root root  20K Sep 23 05:14 autoconf.err
-rwxr-xr-x 1 root root 8.4K Sep 23 05:13 echo
-rw-r--r-- 1 root root 4.8M Sep 23 05:14 libnxt.a
-rw-r--r-- 1 root root  28K Sep 23 05:14 Makefile
-rw-r--r-- 1 root root 4.7K Sep 23 05:14 nxt_auto_config.h
-rw-r--r-- 1 root root 206K Sep 23 05:14 nxt_go_gen.a
-rw-r--r-- 1 root root 2.6K Sep 23 05:14 nxt_go_gen.h
-rwxr-xr-x 1 root root  76K Sep 23 05:14 php56.unit.so
-rwxr-xr-x 1 root root  91K Sep 23 05:14 python.unit.so
drwxr-xr-x 2 root root 4.0K Sep 23 05:14 src
drwxr-xr-x 2 root root    6 Sep 23 05:13 test
-rwxr-xr-x 1 root root 1.9M Sep 23 05:14 unitd

PHP 5.6.31 configuration

php-config 
Usage: /usr/local/bin/php-config [OPTION]
Options:
  --prefix            [/usr/local]
  --includes          [-I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib]
  --ldflags           []
  --libs              [-lcrypt  -lc-client  -lz -lexslt -ltidy -lresolv -lcrypt -ledit -lncurses -laspell -lpspell -lrt -lmcrypt -lltdl -lldap -llber -lstdc++ -lcrypt -lpam -lgmp -lt1 -lX11 -lXpm -lpng -lz -ljpeg -lvpx -lenchant -lcurl -lbz2 -lz -lrt -lm -ldl -lnsl  -lxml2 -lz -lm -ldl -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lssl -lcrypto -lcurl -lxml2 -lz -lm -ldl -lssl -lcrypto -lfreetype -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lssl -lcrypto -ldl -lm -licui18n -licuuc -licudata -ldl -lm -licuio -lxml2 -lz -lm -ldl -lnetsnmp -lssl -lssl -lcrypto -lm -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxslt -lxml2 -lz -ldl -lm -lssl -lcrypto -lcrypt ]
  --extension-dir     [/usr/local/lib/php/extensions/no-debug-non-zts-20131226]
  --include-dir       [/usr/local/include/php]
  --man-dir           [/usr/local/php/man]
  --php-binary        [/usr/local/bin/php]
  --php-sapis         [ cli embed fpm cgi]
  --configure-options [--enable-fpm --enable-opcache --enable-intl --enable-pcntl --with-mcrypt --with-snmp --enable-embed=shared --with-mhash --with-zlib --with-gettext --enable-exif --enable-zip --with-bz2 --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --with-pear --enable-mbstring --with-openssl --with-mysql=mysqlnd --with-libdir=lib64 --with-mysqli=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --with-curl --with-gd --with-xmlrpc --enable-bcmath --enable-calendar --enable-ftp --enable-gd-native-ttf --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr --with-vpx-dir=/usr --with-t1lib=/usr --enable-pdo --with-pdo-sqlite --with-pdo-mysql=mysqlnd --enable-inline-optimization --with-imap --with-imap-ssl --with-kerberos --with-readline --with-libedit --with-gmp --with-pspell --with-tidy --with-enchant --with-fpm-user=nginx --with-fpm-group=nginx --disable-fileinfo --with-ldap --with-ldap-sasl --with-config-file-scan-dir=/etc/centminmod/php.d --with-xsl CC=ccache CFLAGS=-O3 -m64 -march=core-avx-i -pipe -gsplit-dwarf CXX=ccache CXXFLAGS=-O3 -m64 -march=core-avx-i -pipe -gsplit-dwarf]
  --version           [5.6.31]
  --vernum            [50631]

Launch nginx unit

Hello, good project.

I don't understand how to launch nginx unit. Where should I create the control socket file unit.control.sock?

What should i need in order to launch unit?
Which file should contain the application and listener detail information? is it the unit.control.sock file?

thx

why named rpc ?

As for now, rpc is just used callback across. It's confused me. What about rename it to callback?
And port is confusing too. Maybe ipc should be used ? Just wondering.

Nginx Unit --state saving multiple json configs on service restarts

I source compiled Nginx Unit on CentOS 7.4 64bit using configure options

./configure --prefix=/opt/unit --pid=/run/unitd.pid --log=/var/log/unitd.log --modules=modules --user=nginx --group=nginx --state=state

I assumed the --state option would save all loaded configurations as when I tested with just a single /root/tools/unitconfigs/php5631start.json loaded, a unitd service restart reloaded the config ok. But when I loaded more php configurations listed below, on unitd service restart, only the last loaded config was restored for /root/tools/unitconfigs/php720start.json ?

5.6.31

/root/tools/unitconfigs/php5631start.json

{
     "listeners": {
         "*:8300": {
             "application": "php56domaincom"
         }
     },
     "applications": {
         "php56domaincom": {
             "type": "php 5.6.31",
              "workers": 20,
              "root": "/home/nginx/domains/domain.com/public",
              "user": "nginx",
              "group": "nginx",
              "index": "index.php"
         }
     }
}
curl -X PUT -d @/root/tools/unitconfigs/php5631start.json --unix-socket /opt/unit/control.unit.sock http://localhost/
curl -X PUT -d @/root/tools/unitconfigs/php5631start.json --unix-socket /opt/unit/control.unit.sock http://localhost/
{
        "success": "Reconfiguration done."
}

7.0.24

/root/tools/unitconfigs/php7024start.json

{
     "listeners": {
         "*:8400": {
             "application": "php70domaincom"
         }
     },
     "applications": {
         "php70domaincom": {
             "type": "php 7.0.24",
              "workers": 20,
              "root": "/home/nginx/domains/domain.com/public",
              "user": "nginx",
              "group": "nginx",
              "index": "index.php"
         }
     }
}
curl -X PUT -d @/root/tools/unitconfigs/php7024start.json --unix-socket /opt/unit/control.unit.sock http://localhost/
curl -X PUT -d @/root/tools/unitconfigs/php7024start.json --unix-socket /opt/unit/control.unit.sock http://localhost/
{
        "success": "Reconfiguration done."
}

7.1.10

/root/tools/unitconfigs/php7110start.json

{
     "listeners": {
         "*:8500": {
             "application": "php71domaincom"
         }
     },
     "applications": {
         "php71domaincom": {
             "type": "php 7.1.10",
              "workers": 20,
              "root": "/home/nginx/domains/domain.com/public",
              "user": "nginx",
              "group": "nginx",
              "index": "index.php"
         }
     }
}
curl -X PUT -d @/root/tools/unitconfigs/php7110start.json --unix-socket /opt/unit/control.unit.sock http://localhost/
{
        "success": "Reconfiguration done."
}

7.2.0

/root/tools/unitconfigs/php720start.json

{
     "listeners": {
         "*:8600": {
             "application": "php72domaincom"
         }
     },
     "applications": {
         "php72domaincom": {
             "type": "php 7.2.0",
              "workers": 20,
              "root": "/home/nginx/domains/domain.com/public",
              "user": "nginx",
              "group": "nginx",
              "index": "index.php"
         }
     }
}
curl -X PUT -d @/root/tools/unitconfigs/php720start.json --unix-socket /opt/unit/control.unit.sock http://localhost/
curl -X PUT -d @/root/tools/unitconfigs/php720start.json --unix-socket /opt/unit/control.unit.sock http://localhost/
{
        "success": "Reconfiguration done."
}

but only the last config was restored on unitd service restart

curl --unix-socket /opt/unit/control.unit.sock http://localhost/
{
        "listeners": {
                "*:8600": {
                        "application": "php72domaincom"
                }
        },

        "applications": {
                "php72domaincom": {
                        "type": "php 7.2.0",
                        "workers": 20,
                        "root": "/home/nginx/domains/domain.com/public",
                        "user": "nginx",
                        "group": "nginx",
                        "index": "index.php"
                }
        }
}

How to apply changes from php.ini?

It's unclear, how to tell unitd to re-read php.ini to apply new changes? Send some signal to unitd process?
Now unitd reads php.ini for application on creation and ignores further updates.

How to use and assign applications to different PHP versions ?

If I am understanding Nginx Unit's feature set, one is to be able to use different PHP versions for different applications ? From http://unit.nginx.org/docs-configuration.html#php-application I am not seeing any option to tie a PHP application to a specific PHP version ?

If I have multiple PHP versions installed 5.6.31, 7.0.23, 7.1.9 via conifguring PHP http://unit.nginx.org/docs-installation.html#source-code, how does an PHP application know which PHP version to use ? How is it associated ?

Right now if I configure for PHP 5.6.31, 7.0.23 and 7.1.9, which version gets used by default for a Unit created PHP application type = php ?

thanks

SIGSEGV in unit controller process on CentOS 6.9

Hello dear sirs, I'm getting SIGSEGV when trying to configure unit via TCP socket. Here's my env:

[root@dev unit]# uname -a
Linux 4.9.50-x86_64-linode86 #1 SMP Thu Sep 14 19:28:20 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

[root@dev unit]# ./sbin/unitd -V
unit version: 0.2
configured as ./configure --prefix=/usr/local/unit --debug

Here's config file:

[root@dev unit]# cat /root/wiki.json
{
"type": "php",
"workers": 10,
"root": "/home/kost"
}

[root@dev unit]# curl http://127.0.0.1:8400/
{
"listeners": {},
"applications": {}
}

[root@dev ~]# curl -X PUT -d @wiki.json http://127.0.0.1:8400/applications/test
curl: (52) Empty reply from server

[root@dev ~]# strace -p 21835
Process 21835 attached
write(2, "2017/10/24 19:58:27.562 [debug] "..., 62) = 62
write(2, "2017/10/24 19:58:27.562 [info] 2"..., 93) = 93
write(2, "2017/10/24 19:58:27.562 [debug] "..., 86) = 86
write(2, "2017/10/24 19:58:27.562 [debug] "..., 69) = 69
epoll_wait(3, {{EPOLLIN, {u32=22244816, u64=22244816}}}, 32, -1) = 1
write(2, "2017/10/24 19:58:38.736 [debug] "..., 61) = 61
write(2, "2017/10/24 19:58:38.736 [debug] "..., 84) = 84
write(2, "2017/10/24 19:58:38.736 [debug] "..., 86) = 86
write(2, "2017/10/24 19:58:38.736 [debug] "..., 63) = 63
accept4(6, {sa_family=AF_INET, sin_port=htons(40230), sin_addr=inet_addr("127.0.0.1")}, [16], SOCK_NONBLOCK) = 11
write(2, "2017/10/24 19:58:38.736 [debug] "..., 59) = 59
write(2, "2017/10/24 19:58:38.736 [debug] "..., 62) = 62
write(2, "2017/10/24 19:58:38.736 [debug] "..., 65) = 65
write(2, "2017/10/24 19:58:38.736 [debug] "..., 77) = 77
write(2, "2017/10/24 19:58:38.736 [debug] "..., 62) = 62
write(2, "2017/10/24 19:58:38.736 [debug] "..., 63) = 63
accept4(6, 0x1541748, [16], SOCK_NONBLOCK) = -1 EAGAIN (Resource temporarily unavailable)
write(2, "2017/10/24 19:58:38.736 [debug] "..., 94) = 94
write(2, "2017/10/24 19:58:38.736 [debug] "..., 61) = 61
write(2, "2017/10/24 19:58:38.736 [debug] "..., 74) = 74
write(2, "2017/10/24 19:58:38.736 [debug] "..., 77) = 77
write(2, "2017/10/24 19:58:38.736 [debug] "..., 77) = 77
write(2, "2017/10/24 19:58:38.736 [debug] "..., 78) = 78
write(2, "2017/10/24 19:58:38.736 [debug] "..., 61) = 61
write(2, "2017/10/24 19:58:38.736 [debug] "..., 74) = 74
write(2, "2017/10/24 19:58:38.736 [debug] "..., 70) = 70
recvfrom(11, "GET / HTTP/1.1\r\nUser-Agent: curl"..., 1024, 0, NULL, NULL) = 167
write(2, "2017/10/24 19:58:38.736 [debug] "..., 81) = 81
write(2, "2017/10/24 19:58:38.736 [debug] "..., 61) = 61
write(2, "2017/10/24 19:58:38.736 [debug] "..., 68) = 68
write(2, "2017/10/24 19:58:38.736 [debug] "..., 118) = 118
write(2, "2017/10/24 19:58:38.736 [debug] "..., 65) = 65
write(2, "2017/10/24 19:58:38.736 [debug] "..., 79) = 79
write(2, "2017/10/24 19:58:38.736 [debug] "..., 74) = 74
write(2, "2017/10/24 19:58:38.736 [debug] "..., 64) = 64
write(2, "2017/10/24 19:58:38.736 [debug] "..., 62) = 62
write(2, "2017/10/24 19:58:38.736 [debug] "..., 64) = 64
write(2, "2017/10/24 19:58:38.736 [debug] "..., 72) = 72
write(2, "2017/10/24 19:58:38.736 [debug] "..., 71) = 71
writev(11, [{"HTTP/1.1 200 OK\r\nServer: unit/0."..., 145}, {"{\r\n\t"listeners": {},\r\n\t"applicat"..., 46}], 2) = 191
write(2, "2017/10/24 19:58:38.736 [debug] "..., 66) = 66
write(2, "2017/10/24 19:58:38.736 [debug] "..., 72) = 72
write(2, "2017/10/24 19:58:38.736 [debug] "..., 66) = 66
write(2, "2017/10/24 19:58:38.736 [debug] "..., 62) = 62
write(2, "2017/10/24 19:58:38.736 [debug] "..., 69) = 69
write(2, "2017/10/24 19:58:38.736 [debug] "..., 78) = 78
write(2, "2017/10/24 19:58:38.736 [debug] "..., 69) = 69
write(2, "2017/10/24 19:58:38.736 [debug] "..., 70) = 70
write(2, "2017/10/24 19:58:38.736 [debug] "..., 65) = 65
write(2, "2017/10/24 19:58:38.736 [debug] "..., 75) = 75
shutdown(11, SHUT_RDWR) = 0
write(2, "2017/10/24 19:58:38.736 [debug] "..., 63) = 63
write(2, "2017/10/24 19:58:38.736 [debug] "..., 62) = 62
write(2, "2017/10/24 19:58:38.736 [debug] "..., 72) = 72
close(11) = 0
write(2, "2017/10/24 19:58:38.736 [debug] "..., 64) = 64
write(2, "2017/10/24 19:58:38.736 [debug] "..., 61) = 61
write(2, "2017/10/24 19:58:38.736 [debug] "..., 68) = 68
write(2, "2017/10/24 19:58:38.736 [debug] "..., 58) = 58
write(2, "2017/10/24 19:58:38.736 [debug] "..., 58) = 58
write(2, "2017/10/24 19:58:38.736 [debug] "..., 58) = 58
write(2, "2017/10/24 19:58:38.736 [debug] "..., 58) = 58
write(2, "2017/10/24 19:58:38.736 [debug] "..., 58) = 58
write(2, "2017/10/24 19:58:38.736 [debug] "..., 58) = 58
write(2, "2017/10/24 19:58:38.736 [debug] "..., 58) = 58
write(2, "2017/10/24 19:58:38.736 [debug] "..., 69) = 69
epoll_wait(3, {{EPOLLIN, {u32=22244816, u64=22244816}}}, 32, -1) = 1
write(2, "2017/10/24 19:59:16.646 [debug] "..., 61) = 61
write(2, "2017/10/24 19:59:16.646 [debug] "..., 84) = 84
write(2, "2017/10/24 19:59:16.646 [debug] "..., 86) = 86
write(2, "2017/10/24 19:59:16.646 [debug] "..., 63) = 63
accept4(6, {sa_family=AF_INET, sin_port=htons(40232), sin_addr=inet_addr("127.0.0.1")}, [16], SOCK_NONBLOCK) = 11
write(2, "2017/10/24 19:59:16.646 [debug] "..., 59) = 59
write(2, "2017/10/24 19:59:16.646 [debug] "..., 62) = 62
write(2, "2017/10/24 19:59:16.646 [debug] "..., 65) = 65
write(2, "2017/10/24 19:59:16.646 [debug] "..., 77) = 77
write(2, "2017/10/24 19:59:16.646 [debug] "..., 62) = 62
write(2, "2017/10/24 19:59:16.646 [debug] "..., 63) = 63
accept4(6, 0x1541708, [16], SOCK_NONBLOCK) = -1 EAGAIN (Resource temporarily unavailable)
write(2, "2017/10/24 19:59:16.646 [debug] "..., 94) = 94
write(2, "2017/10/24 19:59:16.646 [debug] "..., 61) = 61
write(2, "2017/10/24 19:59:16.646 [debug] "..., 74) = 74
write(2, "2017/10/24 19:59:16.646 [debug] "..., 77) = 77
write(2, "2017/10/24 19:59:16.646 [debug] "..., 77) = 77
write(2, "2017/10/24 19:59:16.646 [debug] "..., 78) = 78
write(2, "2017/10/24 19:59:16.646 [debug] "..., 61) = 61
write(2, "2017/10/24 19:59:16.646 [debug] "..., 74) = 74
write(2, "2017/10/24 19:59:16.646 [debug] "..., 70) = 70
recvfrom(11, "PUT /applications/test HTTP/1.1\r"..., 1024, 0, NULL, NULL) = 315
write(2, "2017/10/24 19:59:16.646 [debug] "..., 81) = 81
write(2, "2017/10/24 19:59:16.646 [debug] "..., 61) = 61
write(2, "2017/10/24 19:59:16.646 [debug] "..., 68) = 68
write(2, "2017/10/24 19:59:16.646 [debug] "..., 120) = 120
write(2, "2017/10/24 19:59:16.646 [debug] "..., 65) = 65
write(2, "2017/10/24 19:59:16.646 [debug] "..., 65) = 65
write(2, "2017/10/24 19:59:16.646 [debug] "..., 79) = 79
write(2, "2017/10/24 19:59:16.646 [debug] "..., 65) = 65
write(2, "2017/10/24 19:59:16.646 [debug] "..., 65) = 65
write(2, "2017/10/24 19:59:16.646 [debug] "..., 79) = 79
write(2, "2017/10/24 19:59:16.646 [debug] "..., 58) = 58
write(2, "2017/10/24 19:59:16.646 [debug] "..., 58) = 58
write(2, "2017/10/24 19:59:16.646 [debug] "..., 58) = 58
write(2, "2017/10/24 19:59:16.646 [debug] "..., 65) = 65
write(2, "2017/10/24 19:59:16.646 [debug] "..., 79) = 79
write(2, "2017/10/24 19:59:16.646 [debug] "..., 75) = 75
write(2, "2017/10/24 19:59:16.646 [debug] "..., 78) = 78
write(2, "2017/10/24 19:59:16.646 [debug] "..., 64) = 64
write(2, "2017/10/24 19:59:16.646 [debug] "..., 67) = 67
ftruncate(0, 10489856) = -1 EINVAL (Invalid argument)
write(2, "2017/10/24 19:59:16.646 [warn] 2"..., 88) = 88
write(2, "2017/10/24 19:59:16.646 [debug] "..., 58) = 58
write(2, "2017/10/24 19:59:16.649 [debug] "..., 79) = 79
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x30} ---
+++ killed by SIGSEGV +++

Pls find unit.log attached.
unit.log

I'm ready to provide more info as needed.

PHP Invalid configuration

Not sure what I am doing wrong with /root/tools/unitconfigs/phpstart.json

{
     "listeners": {
         "*:8300": {
             "application": "php56domaincom"
         }
     },
     "applications": {
         "php56domaincom": {
             "type": "php",
              "workers": 10,
              "root": "/home/nginx/domains/domain.com/public",
              "user": "nginx",
              "group": "nginx",
              "index": "index.php"
         }
     }
}
curl -X PUT -d @/root/tools/unitconfigs/phpstart.json --unix-socket /var/run/control.unit.sock http://localhost/ 
{
        "error": "Invalid configuration."
}
curl --unix-socket /var/run/control.unit.sock http://localhost/
{
        "listeners": {},
        "applications": {}
}

[timer] set timer parent nil after deleted

Hi!

diff -r 411ed164f393 src/nxt_timer.c
--- a/src/nxt_timer.c Fri Oct 27 11:05:37 2017 +0300
+++ b/src/nxt_timer.c Fri Nov 24 03:08:03 2017 -0500
@@ -220,6 +220,7 @@
timer->time, timer->state);

             nxt_rbtree_delete(&timers->tree, &timer->node);
  •            nxt_timer_in_tree_clear(timer);
           }
    

Thanks.

Supporting many language versions on the same machine

Many languages (PHP, Python, etc) have numerous versions in active use that can be installed on the same machine. Could there be an option named version to support this? Or just a binpath setting where you could define the interpreter used?

Example for config with version included:

"blogs": {
    "type": "php",
    "version": "7.1",
    "workers": 20,
    "root": "/www/blogs/scripts",
    "index": "index.php",
    "user": "www-blogs",
    "group": "www-blogs"
},
"legacy": {
    "type": "php",
    "version": "5.6",
    "workers": 5,
    "root": "/www/legacy/public_html",
    "index": "index.php",
    "user": "www-legacy",
    "group": "www-legacy"
}

make install fails with 'are the same file'

root@deb9x64:~/unit# ./configure
configuring for Linux 4.9.0-3-amd64 x86_64
checking for C compiler: cc
 + using GNU C compiler
 + gcc version 6.3.0 20170516 (Debian 6.3.0-18)
building an "echo" program
checking for int size ... 4
checking for long size ... 8
checking for long long size ... 8
checking for void * size ... 8
checking for size_t size ... 8
checking for off_t size ... 8
checking for time_t size ... 8
checking for C99 variadic macro ... found
checking for GCC __builtin_expect() ... found
checking for GCC __builtin_unreachable() ... found
checking for GCC __builtin_prefetch() ... found
checking for GCC __builtin_clz() ... found
checking for GCC __attribute__ visibility ... found
checking for GCC __attribute__ aligned ... found
checking for GCC __attribute__ malloc ... found
checking for GCC __attribute__ packed ... found
checking for GCC builtin atomic operations ... found
checking for posix_memalign() ... found
checking for Linux malloc_usable_size() ... found
checking for alloca() ... found
checking for MAP_ANON ... found
checking for MAP_POPULATE ... found
checking for MAP_PREFAULT_READ ... not found
checking for shm_open() ... found
checking for memfd_create() ... found
checking for Linux clock_gettime(CLOCK_REALTIME_COARSE) ... found
checking for FreeBSD clock_gettime(CLOCK_REALTIME_FAST) ... not found
checking for clock_gettime(CLOCK_REALTIME) ... found
checking for Linux clock_gettime(CLOCK_MONOTONIC_COARSE) ... found
checking for FreeBSD clock_gettime(CLOCK_MONOTONIC_FAST) ... not found
checking for clock_gettime(CLOCK_MONOTONIC) ... found
checking for HP-UX hg_gethrtime() ... not found
checking for struct tm.tm_gmtoff ... found
checking for altzone ... not found
checking for localtime_r() ... found
checking for pthread_yield() ... found
checking for pthread spinlock ... found
checking for pthread spinlock zero initial value ... found but is not working
checking for MacOSX spinlock ... not found
checking for sem_timedwait() ... not found
checking for sem_timedwait() in libpthread ... found
checking for __thread ... found
checking for Linux epoll ... found
checking for Linux signalfd() ... found
checking for Linux eventfd() ... found
checking for kqueue ... not found
checking for Solaris event port ... not found
checking for /dev/poll ... not found
checking for AIX pollset ... not found
checking for AF_INET6 ... found
checking for sockaddr.sa_len ... not found
checking for struct sockaddr size ... 16
checking for struct sockaddr_in size ... 16
checking for struct sockaddr_in6 size ... 28
checking for struct sockaddr_un size ... 110
checking for struct sockaddr_storage size ... 128
checking for socketpair(AF_UNIX, SOCK_SEQPACKET) ... found
checking for struct msghdr.msg_control ... found
checking for sys/filio.h ... not found
checking for ioctl(FIONBIO) ... found
checking for socket(SOCK_NONBLOCK) ... found
checking for accept4() ... found
checking for Linux sendfile() ... found
checking for posix_fadvise() ... found
checking for fcntl(F_READAHEAD) ... not found
checking for fcntl(F_RDAHEAD) ... not found
checking for getrandom() ... not found
checking for ucontext ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for posix_spawn() ... found
checking for setproctitle() ... not found
creating build/Makefile

Configuration summary:

  unit pid file:             "unit.pid"
  unit log file:             "unit.log"
  unit modules path:         "build"

  unit control API socket:   "unix:control.unit.sock"

  non-privileged user:          "nobody"
  non-privileged group:         ""

  IPv6 support:                 YES
  Unix domain sockets support:  YES
  debug logging:                NO
./configure php --module=php71 --config=/var/www/vhosts/example_com/php/bin/php-config --lib-path=/var/www/vhosts/example_com/php/lib/
configuring PHP module
checking for PHP ... found
 + PHP version: 7.1.9
 + PHP SAPI: [cli embed phpdbg cgi]
checking for PHP embed SAPI ... found
 + PHP module: php71.unit.so

make all finished without errors

root@deb9x64:~/unit# make install
install -d sbin
install -p build/unitd sbin/
install -d build
install -p build/php71.unit.so \
        build/
install: 'build/php71.unit.so' and 'build/php71.unit.so' are the same file
build/Makefile:983: recipe for target 'php71-install' failed
make: *** [php71-install] Error 1

The part of ~/unit/build/Makefile:983:

php71-install: php71
        install -d $(DESTDIR)build
        install -p build/php71.unit.so \
                $(DESTDIR)build/

I've not found where DESTDIR is defined.

Inject environment variables to Application object

Is it possible ? Something like:-

"shopping_cart": {
             "type": "python",
             "workers": 10,
             "path": "/www/store/cart",
             "module": "wsgi",
             "user": "www",
             "group": "www"
             "env_vars": {
                  "DB_HOST": "localhost:3306",
                  "DB_USER": "app",
                  "DB_PASS": "xxxx"
              }
            },

Hello world samples ?

Hey,

this project looks very promising, but I got hard time trying to understand what you expect an application to look like.

Is there a place where I could find hello world application for the different supported language?

Issues with listen address

Hello!

Noticed that switching to or from using a wildcard (*:port) in listeners causes the re-configuration to fail[1]. Switching from a ip-adress to another does work however which makes me assume that unit tries to bind the new port(s) before unbinding the old one(s).

Also, listeners seem to require a ip-adress. Me (and I suspect many others) will instinctively try to use "localhost" instead of 127.0.0.1.

I'm running unit from apt on ubuntu xenial

[1]:

{
	"error": "Failed to apply new configuration."
}

From the log:
listen socket error: {listener: "0.0.0.0:8300", code:"ListenerInUse", message: "bind(\"0.0.0.0:8300\") failed (98: Address already in use)"}

being able to redirect logs to stderr

I'd like to run

unitd --log /dev/stderr

but currently it says:

2017/09/11 09:13:19 [crit] 12#12 epoll_ctl(3, 3, 9) failed (2: No such file or directory)

Is it something doable?
thanks.

Can't load compiled PHP module into interpreter

The point of issue: I compiled unit PHP extension, put it in appropriate directory and checked modules list with php -m. The output doesn't show anything about unit module, so it means the module is not installed.

Here is what I did step by step.

./configure --prefix=/opt/unit --pid=/run/unitd.pid --log=/var/log/unitd.log --modules=modules --user=nginx --group=nginx --state=state

...

./configure php --module=php56 --config=/opt/build/php56/bin/php-config --lib-path=/opt/build/php56/lib64

configuring PHP module
checking for PHP ... found
 + PHP version: 5.6.31
 + PHP SAPI: [apache2handler cli fpm]
checking for PHP embed SAPI ... found
 + PHP module: php56.unit.so

make all
make install
## Copy the library to extensions directory
cp /opt/unit/modules/php56.unit.so /opt/build/php56/lib64/extensions/no-debug-non-zts-20131226/php56.unit.so
echo "extension=php56.unit.so" >> /etc/php56/php.ini

Also I checked that the path is right changing from extension to zend_extension and the php -m output showed up the error that the file is not a Zend extension. It meant that the extension path is correct.

What am I doing wrong? Is there another way to include compiled PHP module into interpreter?

Problem with POST's

Did a vanilla nginx/unit/php7/wordpress install on a fresh Ubuntu Xenial and noticed that I couldn't log in to wp-admin or post comments. Seems like $_POST doesn't get populated[1]?

Not sure if its a known issue, if it is you can just go ahead and close this. :)

[1]:
Did a simple test to verify:

test.php: <?php print_r($_POST); ?>

$ curl --data "foo=bar" http://host/test.php

Array
(
)

Multithreading support for python amd how does ngonx-unitnis different from apache web server

ningx unit delegates request to individual python worker processes, right? Is there a way to allow multiple threads in each python worker processs so for io bound application we can use threads and increase the number of request to handle?

Also just wondering how is it different than apache web server which has almost the same offering and you can even run multiple applications using the same server via different virtualhost configs?

If java supported

Unit will work as tomcat or jetty if java supported? Or what it supposed todo?

[php] SCRIPT_FILENAME is not parsed correctly

my config looks like that:

% curl --unix-socket /usr/src/app/control.unit.sock http://localhost/
{
        "listeners": {
                "*:8300": {
                        "application": "api"
                }
        },

        "applications": {
                "api": {
                        "type": "php",
                        "workers": 20,
                        "root": "/usr/src/app/web",
                        "index": "app.php"
                }
        }
}

I'd like being able to call URLs like /app.php/en/contents or /en/contents, but none of them works:

% curl localhost:8300/app.php/en/contents

Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0

Fatal error: Unknown: Failed opening required '/usr/src/app/web/app.php/en/contents' (include_path='.:/usr/share/php') in Unknown on line 0

The problem apparently lies in the detection of the SCRIPT_FILENAME. It should parse the url and extract the filename, or maybe the index option of the config should be populating the SCRIPT_FILENAME all the time.

Any idea how to achieve that?
Thanks!

How to apply changes to wsgi.py ?

Pushing the json doesn't seem to work:-

sudo curl -X PUT -d @hello.json --unix-socket /var/run/control.unit.sock http://localhost/
{
	"success": "Reconfiguration done."
}

But it still reading the old file. So I have to restart unitd but then it cause issue #16.

Add musl support

Currently building on alpine fails with:

/src/unit-0.1 # cc -Wl,-E  -o build/unitd -pipe -fPIC -fvisibility=hidden -O -W -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wmissing-prototypes -Werro
r -g   build/src/nxt_main.o  build/libnxt.a -lm -lrt -lpthread
build/libnxt.a(nxt_fiber.o): In function `nxt_fiber_switch_stack':
/src/unit-0.1/src/nxt_fiber.c:214: undefined reference to `getcontext'
/src/unit-0.1/src/nxt_fiber.c:223: undefined reference to `makecontext'
/src/unit-0.1/src/nxt_fiber.c:229: undefined reference to `setcontext'
collect2: error: ld returned 1 exit status

Presumably because getcontext/makecontext/setcontext are deprecated posix api's not implemented by musl.

All applications and listeners lost after restarting unitd

sudo curl --unix-socket /var/run/control.unit.sock http://localhost/
{
	"listeners": {
		"*:8300": {
			"application": "hello"
		}
	},

	"applications": {
		"hello": {
			"type": "python",
			"workers": 2,
			"module": "wsgi",
			"user": "ubuntu",
			"group": "ubuntu",
			"path": "/home/ubuntu/unit/hello"
		}
	}
}

After restarting with sudo systemctl restart unitd:-

sudo curl --unix-socket /var/run/control.unit.sock http://localhost/
{
	"listeners": {},
	"applications": {}
}

So I have to add it again:-

sudo curl -X PUT -d @hello.json --unix-socket /var/run/control.unit.sock http://localhost/

This is on Ubuntu Xenial and unit install through apt.

apt show unit
Package: unit
Version: 0.1-1~xenial
Priority: extra
Section: admin
Maintainer: Andrei Belov <[email protected]>
Installed-Size: 504 kB
Depends: lsb-base, curl, libc6 (>= 2.15), libpython2.7 (>= 2.7), libphp-embed
Homepage: https://www.nginx.com
Download-Size: 128 kB
APT-Manual-Installed: yes
APT-Sources: http://nginx.org/packages/mainline/ubuntu xenial/nginx amd64 Packages

Problem install RPM: nothing provides libphp5

Fedora 26
PHP 7.1 (installed: php-devel-7.1 php-embedded-7.1)

Try install package from repo
dnf install unit

Error:

Problem: conflicting requests
  - nothing provides libphp5-5.4.so()(64bit) needed by unit-0.1-1.el7.ngx.x86_64

How to fix it?

I guess i should try to compile everything with my hands :)

Missing nxt_port_rpc.h in auto/sources

Hi!

The dependency file 'nxt_port_rpc.h' is missed in auto/sources, and nxt_port_hash.h is duplicated.

diff -r e01f2cadf399 auto/sources
--- a/auto/sources Wed Oct 25 15:09:07 2017 +0300
+++ b/auto/sources Thu Oct 26 12:06:35 2017 -0400
@@ -19,7 +19,7 @@
src/nxt_process.h
src/nxt_signal.h
src/nxt_port.h \

  • src/nxt_port_hash.h \
  • src/nxt_port_rpc.h
    src/nxt_port_memory.h
    src/nxt_port_memory_int.h
    src/nxt_dyld.h \

Thanks.

"Generic" language support

There are many languages now, much like Golang, that compile down to native binaries and feature robust C interop -- Rust, D, Scala Native, and quite a few others could probably re-use most of the same code as nxt_go uses currently. Is there any plan to support this kind of functionality?

Enable building of `foreground default` version

Please make a compile-time option for "--no-daemon" as a default state.
In other words: rt->daemon = NXT_DAEMON.

Docker and Systemd environments prefer master pid to stay alive and non-forking.

Lua should be supported

Lua is borned to be a glue language,and it is very powerful。also multithead mode should be supported。

Remi PHP 7.2.0 PHP embed library detection

Trying to conifgure Nginx Unit with Remi YUM repo's PHP 7.2.0 RC2 but it's not picking up the PHP embed library for Remi PHP 7.2.0 RC2 but picks up fine for Remi PHP 5.6, 7.0, 7.1 Embed ?

rpm -ql php72-php-embedded
/opt/remi/php72/root/usr/lib64/libphp7-7.2.so
/opt/remi/php72/root/usr/lib64/libphp7.so

rpm -ql php71-php-embedded
/opt/remi/php71/root/usr/lib64/libphp7-7.1.so
/opt/remi/php71/root/usr/lib64/libphp7.so

rpm -ql php70-php-embedded
/opt/remi/php70/root/usr/lib64/libphp7-7.0.so
/opt/remi/php70/root/usr/lib64/libphp7.so

rpm -ql php56-php-embedded             
/opt/remi/php56/root/usr/lib64/libphp5-5.6.so
/opt/remi/php56/root/usr/lib64/libphp5.so
./configure php --module=php5631 --config=/usr/local/bin/php-config --lib-path=/usr/local/lib
configuring PHP module
checking for PHP ... found
 + PHP version: 5.6.31
 + PHP SAPI: [cli embed fpm cgi]
checking for PHP embed SAPI ... found
 + PHP module: php5631.unit.so

./configure php --module=remiphp5631 --config=/opt/remi/php56/root/usr/bin/php-config --lib-path=/opt/remi/php56/root/usr/lib64
configuring PHP module
checking for PHP ... found
 + PHP version: 5.6.31
 + PHP SAPI: [apache2handler embed fpm cli phpdbg cgi]
checking for PHP embed SAPI ... found
 + PHP module: remiphp5631.unit.so

./configure php --module=remiphp7023 --config=/opt/remi/php70/root/usr/bin/php-config --lib-path=/opt/remi/php70/root/usr/lib64
configuring PHP module
checking for PHP ... found
 + PHP version: 7.0.24RC1
 + PHP SAPI: [apache2handler embed fpm cli phpdbg cgi]
checking for PHP embed SAPI ... found
 + PHP module: remiphp7023.unit.so

./configure php --module=remiphp719 --config=/opt/remi/php71/root/usr/bin/php-config --lib-path=/opt/remi/php71/root/usr/lib64
configuring PHP module
checking for PHP ... found
 + PHP version: 7.1.10RC1
 + PHP SAPI: [apache2handler embed fpm cli phpdbg cgi]
checking for PHP embed SAPI ... found
 + PHP module: remiphp719.unit.so

./configure php --module=remiphp720 --config=/opt/remi/php72/root/usr/bin/php-config --lib-path=/opt/remi/php72/root/usr/lib64
configuring PHP module
checking for PHP ... found
 + PHP version: 7.2.0RC2
 + PHP SAPI: [apache2handler embed fpm cli phpdbg cgi]
checking for PHP embed SAPI ... not found

./configure: error: no PHP embed SAPI found.

missing header nxt_go_gen.h

I'm trying to build Go application with "unit" library and I get this error:

$ go build unit-app.go
# unit
../go/src/unit/nxt_go_lib.c:62:24: fatal error: nxt_go_gen.h: No such file or directory
compilation terminated.

Where to find this file ?

More suitable max open file descriptor limits by default ?

With benchmarking and general performance for Nginx Unit and it's processes, maybe a more suitable and higher default max open file descriptor limits is needed ?

On CentOS 7.4 64bit using systemd unitd.service file, the default limits are fairly low with soft/hard limits at 1024/4096.

root      4018  0.0  0.0  16428   516 ?        Ss   00:35   0:00 unit: main [/opt/unit/sbin/unitd]
nginx     4039  0.0  0.0  26672   264 ?        S    00:35   0:00  \_ unit: controller
nginx     4241  0.0  0.0 1165196   40 ?        S    00:36   0:00  \_ unit: "php71domaincom" application
cat /proc/4039/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             7272                 7272                 processes
Max open files            1024                 4096                 files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       7272                 7272                 signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0              
Max realtime priority     0                    0              
Max realtime timeout      unlimited            unlimited            us
cat /proc/4241/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             7272                 7272                 processes
Max open files            1024                 4096                 files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       7272                 7272                 signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0              
Max realtime priority     0                    0              
Max realtime timeout      unlimited            unlimited            us

Setting higher defaults

mkdir -p /etc/systemd/system/unitd.service.d
echo -en "[Service]\nLimitNOFILE=262144\nLimitNPROC=16384\n" > /etc/systemd/system/unitd.service.d/limit.conf
systemctl daemon-reload
systemctl restart unitd
root      4559  0.0  0.0  16032   800 ?        Ss   00:54   0:00 unit: main [/opt/unit/sbin/unitd]
nginx     4578  0.0  0.0  26276   720 ?        S    00:54   0:00  \_ unit: controller
nginx     4579  0.0  0.0 341832   912 ?        Sl   00:54   0:00  \_ unit: router
nginx     4642  5.2  2.7 1175440 52152 ?       S    00:57   0:00  \_ unit: "php71domaincom" application
cat /proc/4578/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             16384                16384                processes
Max open files            262144               262144               files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       7272                 7272                 signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0                
Max realtime priority     0                    0                
Max realtime timeout      unlimited            unlimited            us  
cat /proc/4642/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             16384                16384                processes
Max open files            262144               262144               files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       7272                 7272                 signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0                
Max realtime priority     0                    0                
Max realtime timeout      unlimited            unlimited            us

Python WSGI shutdown

Hi,

I cannot get python functions registered via atexit to run when running the sample WSGI application below. Trying to migrate from uWSGI, where cleanup was always executed whenever the uWSGI service was terminated.

I've tried sending TERM|QUIT|INT to unit, all of which resulted in the workers exiting with 0 in the logs, yet cleanup was never triggered.

Could you please give some pointers, what am I missing here? Thanks!

import atexit, webapp2

def cleanup():
    print('Cleanup done.')
atexit.register(cleanup)

class Handler(webapp2.RequestHandler):
    def get(self):
        self.response.write('hello\n')

application = webapp2.WSGIApplication([
    (r'/', Handler)
])

What competitive advantages?

Please, describe in more detail in readme, your advantages in comparison with similar Application servers.

For example PHP:

  1. Is it faster than PHP-FPM?
  2. Is it better scaled than PHP-FPM?
  3. Is it planned that the php script will work in the daemon mode, do not reset the state after HTTP request executed?
  4. Is planned implement Websocket protocol?

Thanks.

Nginx Unit source install instructions incomplete ?

From http://unit.nginx.org/docs-installation.html#source-code the source install instructions are missing the initial ./configure command before configuring go, php and python

If i follow those instructions and try configure go first I get the error prompt

./configure go

Please run common ./configure before configuring module "go".

Only after doing an initial ./configure first does go, php and python configurations work

./configure
configuring for Linux 3.10.0-693.2.2.el7.x86_64 x86_64
checking for C compiler: gcc
 + using GNU C compiler
 + gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) 
building an "echo" program
checking for int size ... 4
checking for long size ... 8
checking for long long size ... 8
checking for void * size ... 8
checking for size_t size ... 8
checking for off_t size ... 8
checking for time_t size ... 8
checking for C99 variadic macro ... found
checking for GCC __builtin_expect() ... found
checking for GCC __builtin_unreachable() ... found
checking for GCC __builtin_prefetch() ... not found
checking for GCC __builtin_clz() ... found
checking for GCC __attribute__ visibility ... found
checking for GCC __attribute__ aligned ... found
checking for GCC __attribute__ malloc ... found
checking for GCC __attribute__ packed ... found
checking for GCC builtin atomic operations ... found
checking for posix_memalign() ... found
checking for Linux malloc_usable_size() ... found
checking for alloca() ... found
checking for MAP_ANON ... found
checking for MAP_POPULATE ... found
checking for MAP_PREFAULT_READ ... not found
checking for shm_open() ... found
checking for memfd_create() ... found
checking for Linux clock_gettime(CLOCK_REALTIME_COARSE) ... found
checking for FreeBSD clock_gettime(CLOCK_REALTIME_FAST) ... not found
checking for clock_gettime(CLOCK_REALTIME) ... found
checking for Linux clock_gettime(CLOCK_MONOTONIC_COARSE) ... found
checking for FreeBSD clock_gettime(CLOCK_MONOTONIC_FAST) ... not found
checking for clock_gettime(CLOCK_MONOTONIC) ... found
checking for HP-UX hg_gethrtime() ... not found
checking for struct tm.tm_gmtoff ... found
checking for altzone ... not found
checking for localtime_r() ... found
checking for pthread_yield() ... found
checking for pthread spinlock ... found
checking for pthread spinlock zero initial value ... found but is not working
checking for MacOSX spinlock ... not found
checking for sem_timedwait() ... not found
checking for sem_timedwait() in libpthread ... found
checking for __thread ... found
checking for Linux epoll ... found
checking for Linux signalfd() ... found
checking for Linux eventfd() ... found
checking for kqueue ... not found
checking for Solaris event port ... not found
checking for /dev/poll ... not found
checking for AIX pollset ... not found
checking for AF_INET6 ... found
checking for sockaddr.sa_len ... not found
checking for struct sockaddr size ... 16
checking for struct sockaddr_in size ... 16
checking for struct sockaddr_in6 size ... 28
checking for struct sockaddr_un size ... 110
checking for struct sockaddr_storage size ... 128
checking for socketpair(AF_UNIX, SOCK_SEQPACKET) ... found
checking for struct msghdr.msg_control ... found
checking for sys/filio.h ... not found
checking for ioctl(FIONBIO) ... found
checking for socket(SOCK_NONBLOCK) ... found
checking for accept4() ... found
checking for Linux sendfile() ... found
checking for posix_fadvise() ... found
checking for fcntl(F_READAHEAD) ... not found
checking for fcntl(F_RDAHEAD) ... not found
checking for getrandom() ... not found
checking for ucontext ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for posix_spawn() ... found
checking for setproctitle() ... not found
creating build/Makefile

Configuration summary:

  unit pid file:             "unit.pid"
  unit log file:             "unit.log"
  unit modules path:         "build"
  unit state path:           "build"

  unit control API socket:   "unix:control.unit.sock"

  non-privileged user:          "nobody"
  non-privileged group:         ""

  IPv6 support:                 YES
  Unix domain sockets support:  YES
  debug logging:                NO

FEATURE REQUEST: add static file support

While be very perfect if support also static file (and http cache handcheck), in that way they can be used as autonomous container behing nginx/proxy loadbalancer in kubernetes environement...

No access log ?

There is no access log in unit ? Or it's desiged to have no access log ?

router process hangs when repeat PUT and DELETE

I wrote simple python WSGI app and uploaded as follows:

wsgi.py:

def get_response():
    return 'foo\n'.encode('utf-8')

def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    response = get_response()
    return [response]'

conf.json:

{
    "listeners": {
        "*:9999": {
            "application": "foo"
        }
    },
    "applications": {
        "foo": {
            "type": "python",
            "workers": 2,
            "path": "/var/tmp/bobunderson/nginx_unit/test/app",
            "module": "wsgi",
            "user": "bobunderson",
            "group": "bobunderson"
        }
    }
}

and I uploaded conf.json and executed 'curl -D - http://localhost:9999/', then it looked working well.
I deleted all of listeners and applications and re-uploaded the same conf.json immediately, then unitd does not respond.
2 DELETE methods were worked successfully, but when I send 2nd PUT method, unitd router process hanged and the process were using 100% of CPU resource.
so I did 'kill -KILL [pid of router]' then, unitd output core file.
backtrace is as follows:

(gdb) bt
#0  0x00007fc8092985db in raise () from /lib64/libpthread.so.0
#1  0x000000000040aa20 in nxt_port_mp_cleanup (task=<value optimized out>, obj=0x1d14a00, 
    data=0x1d0eb10) at src/nxt_port.c:34
#2  0x000000000040b7a4 in nxt_mp_destroy (mp=0x1d0eb10) at src/nxt_mp.c:300
#3  0x000000000040b83c in nxt_mp_release (mp=0x1d0eb10, p=<value optimized out>)
    at src/nxt_mp.c:964
#4  0x000000000040a624 in nxt_port_release (port=0x1d14a00) at src/nxt_port.c:103
#5  0x00000000004105fc in nxt_runtime_process_remove (rt=0x1d02850, process=0x1d0cd80)
    at src/nxt_runtime.c:1780
#6  0x0000000000410e78 in nxt_runtime_exit (task=<value optimized out>, obj=0x1d02850, 
    data=<value optimized out>) at src/nxt_runtime.c:553
#7  0x000000000040f570 in nxt_event_engine_start (engine=0x1d03290)
    at src/nxt_event_engine.c:517
#8  0x000000000040669e in main (argc=<value optimized out>, argv=<value optimized out>)
    at src/nxt_main.c:35

unitd.log:

2017/09/12 12:36:03 [info] 21043#21043 discovery started
2017/09/12 12:36:03 [notice] 21043#21043 module: python 3.4.3 "build/python3.unit.so"
2017/09/12 12:36:03 [info] 21044#21044 controller started
2017/09/12 12:36:03 [crit] 21044#21044 epoll_ctl(3, 3, 9) failed (2: No such file or directory)
2017/09/12 12:36:03 [info] 21045#21045 router started
2017/09/12 12:36:03 [notice] 21042#21042 process 21043 exited with code 0
2017/09/12 12:36:03 [crit] 21045#21045 epoll_ctl(3, 3, 9) failed (2: No such file or directory)
2017/09/12 12:36:06 [info] 21052#21052 "foo" application started
2017/09/12 12:36:06 [crit] 21052#21052 epoll_ctl(3, 3, 9) failed (2: No such file or directory)
2017/09/12 12:36:08 [notice] 21042#21042 process 21052 exited with code 0
2017/09/12 12:37:04 [alert] 21044#21044 src/nxt_port.c:34 assertion failed: nxt_lvlhsh_is_empty(&port->rpc_streams)
2017/09/12 12:37:05 [crit] 21042#21042 process 21044 exited on signal 6 (core dumped)

environment:

Linux (hostname) 2.6.32-504.12.2.el6.x86_64 #1 SMP Wed Mar 11 22:03:14 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
CentOS release 6.6 (Final)
Python 3.4.3

[coredump] close idle connection

Hi!

A rash happens in close idle connection. The main problem is with nxt_conn_accept function.

  1. Is it better insert the accepted connection into idle_connections after generating next connection?
    `diff -r 411ed164f393 src/nxt_conn_accept.c
    --- a/src/nxt_conn_accept.c Fri Oct 27 11:05:37 2017 +0300
    +++ b/src/nxt_conn_accept.c Mon Nov 20 03:06:11 2017 -0500
    @@ -191,8 +191,6 @@
    nxt_debug(task, "client: %*s",
    c->remote->address_length, nxt_sockaddr_address(c->remote));
  • nxt_queue_insert_head(&task->thread->engine->idle_connections, &c->link);
  • c->read_work_queue = lev->work_queue;
    c->write_work_queue = lev->work_queue;

@@ -214,6 +212,8 @@
nxt_work_queue_add(lev->socket.read_work_queue,
lev->accept, task, lev, next);
}
+

  • nxt_queue_insert_head(&task->thread->engine->idle_connections, &c->link);
    }`

Since nxt_conn_accept_next may close the connection just generated.

  1. The write_state of connection may not be set yet before closed as the previous description.

  2. The engine connections forget to decrease after free connection?
    Maybe it's better to add a handy function nxt_conn_free(task, c);

  3. The way of free connection is different in the controller (mp_destroy) and router (mp_release) ?

Anyway, the main problem is with closing the idle connections.

Thanks.

python virtual environment configuration

I think that for python application type, there should be some sort of congfiguration to specify a virtual env to be used, since ther's no control now over which python executable should be used, I suppose system one is used.
So if the application needs dependancies (sure it does! ) we have to install them system wide and it's not good !

Send POST request with no response

I am using Ubuntu server 16.04 with unit, with simple php application. and it's works.
and trying to run phpmyadmin it's works too, but with some issue.

index.php is appears, if I trying to login, nothing happened.
without error message. just like reload the pages.

screenshot 16

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.