# Free Open-Source Hosting Platform «ClonOS»

### Installation on FreeBSD

# ClonOS

FreeBSD based distro for virtual hosting platform and appliance

### Installing ClonOS/CBSD WEB UI via PKG

###

ClonOS in pkg packages

Daniel Shafer prepared a Jenkins task to build ClonOS pkg package repo (at the moment FreeBSD 12 only)

To enable repository, just put the following lines in /usr/local/etc/pkg/repos/clonos-pkg.ircdriven.net.conf:

    ClonOS-pkg.ircdriven.net: {
            url: "https://pkg.ircdriven.net/packages/12amd64-clonos/",
            mirror_type: "none",
            enabled: yes
    }

Update pkg metafile and install it:

    pkg update -f
    pkg install clonos

### Installing ClonOS/CBSD WEB UI on stock FreeBSD

###

Install ClonOS and dependencies

- Update ports tree first:

      portsnap fetch extract

- Install ClonOS dependencies:

      pkg install -y net/libvncserver security/gnutls databases/sqlite3 shells/bash www/npm \
      www/nginx sysutils/py-supervisor sysutils/cbsd security/ca_root_nss \
      www/node security/sudo databases/sqlite3 net/beanstalkd devel/git devel/pkgconf www/nginx \
      lang/php73 www/php73-session archivers/php73-zip databases/php73-sqlite3 databases/php73-pdo_sqlite \
      www/php73-opcache devel/php73-json security/php73-hash lang/go

- Checkout ClonOS ports tree:

      git clone https://github.com/clonos/clonos-ports-wip.git /tmp/clonos-ports

- Merge ClonOS port with your ports tree:

    cp -a /tmp/clonos-ports/* /usr/ports/

- Build and install ClonOS

    env BATCH=no make -C /usr/ports/www/clonos install

Follow post-message instruction

You must merge or copy working configuration files

- Check for RACCT is enabled on the host, please add:

        kern.racct.enable="1"

  into /boot/loader.conf and reboot host
- If CBSD still not initialized, do it first:

      env workdir=/usr/jails /usr/local/cbsd/sudoexec/initenv

  more about CBSD initialization: https://www.bsdstore.ru/en/installing_cbsd.html#initenv

- Ensure CBSD is started:

        sysrc cbsdd_enable=YES
        service cbsdd status || service cbsdd start

- Configure and run beanstalkd:

        sysrc beanstalkd_flags="-l 127.0.0.1 -p 11300"
        sysrc beanstalkd_enable=YES
        service beanstalkd restart

- Change in /usr/local/etc/php-fpm.conf events mechanism to BSD-specific. To do this, uncomment and edit the events.mechanism parameter to:

        ..
        events.mechanism = kqueue
        ..

  Or copy: cp /usr/local/etc/php-fpm.conf.clonos.sample /usr/local/etc/php-fpm.conf
- Uncomment and change in /usr/local/etc/php-fpm.d/www.conf port to Unix socket and set's correct access permission:

        ..
        listen = /tmp/php-fpm.sock
        ..
        listen.backlog = -1
        ..
        listen.owner = www
        listen.group = www
        listen.mode = 0660
        ..

  Or copy: cp /usr/local/etc/php-fpm.d/www-php-fpm.conf.clonos.sample /usr/local/etc/php-fpm.d/www.conf
- Add "www" user to "cbsd" group:

      pw groupmod cbsd -M www

- To execute CBSD commands, let the www user run CBSD through sudo: edit /usr/local/etc/sudoers.d/10_www:

        Defaults     env_keep += "workdir DIALOG NOCOLOR"
        Cmnd_Alias   WEB_CMD = /usr/local/bin/cbsd
        www   ALL=(ALL) NOPASSWD:SETENV: WEB_CMD

  And make sure the file permissions are safe:

        chown root:wheel /usr/local/etc/sudoers.d/10_www
        chmod 0440 /usr/local/etc/sudoers.d/10_www

  Or copy: cp /usr/local/etc/sudoers_10_www.clonos.sample /usr/local/etc/sudoers.d/10_www
- Change /usr/local/etc/supervisord.conf to:

        [unix_http_server]
        file=/var/run/supervisor.sock
        chmod=0777
        chown=nobody:nobody
        [supervisorctl]
        serverurl=unix:///var/run/supervisor.sock
        [supervisord]
        logfile=/var/log/supervisor/supervisord.log
        pidfile=/var/run/supervisor/supervisord.pid
        nodaemon=false
        minfds=1024
        minprocs=200
        umask=022
        strip_ansi=false
        [rpcinterface:supervisor]
        supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
        [include]
        files=/usr/local/etc/supervisor.d/*.conf

  Or copy: cp /usr/local/etc/supervisord.conf.clonos.sample /usr/local/etc/supervisord.conf
- Make sure /usr/local/etc/supervisor.d/program_wsclonos.conf have correct path to CBSD workdir. Please check that line "environment=PATH.." in /usr/local/etc/supervisor.d/program_wsclonos.conf pointed to ~cbsd path in 'cbsd_workdir':

        environment=PATH=[.skipp..],cbsd_workdir="/usr/jails"
                                                  ^^^^^^^^^^

- Change /usr/local/etc/php.ini params:

      ..
      memory_limit = 256M
      ..
      post_max_size = 12G
      ..
      upload_tmp_dir = /tmp
      ..
      upload_max_filesize = 16G
      ..
      opcache.enable=1

Or copy: cp /usr/local/etc/php.ini.clonos.sample /usr/local/etc/php.ini
- Configure NGINX: make sure/merge this settings into /usr/local/etc/nginx/nginx.conf:

        user www;
        load_module /usr/local/libexec/nginx/ngx_stream_module.so;
        events {
                use kqueue;
        }
        http {
                include       /usr/local/etc/nginx/mime.types;
                default_type  application/octet-stream;
                client_max_body_size    1m;
                include /usr/local/etc/nginx/sites-enabled/*.conf;
        }
        stream {
                include /usr/local/etc/nginx/conf.stream.d/*.conf;
                include /usr/local/etc/nginx/streams-enabled/*;
        }

  Or copy: cp /usr/local/etc/nginx/nginx.conf.clonos.sample /usr/local/etc/nginx/nginx.conf
- Enable nginx, php-fpm and supervisord to run at system startup:

        sysrc nginx_enable="YES"
        sysrc php_fpm_enable="YES"
        sysrc supervisord_enable="YES"

- Start nginx, php-fpm and supervisord to run at system startup:

        service nginx restart
        service php-fpm restart
        service supervisord restart

- Configure CBSD:

        1)
          ~cbsd/etc/modules.conf must have:

          pkg.d
          bsdconf.d
          zfsinstall.d
          puppet.d
          convectix.d
          cbsd_queue.d
          vncterm.d

  Or copy: cp /usr/local/etc/cbsd-modules.conf.clonos.sample ~cbsd/etc/modules.conf

        2) Re-run CBSD initenv to init modules:

          cbsd initenv

        3) Init web user database:

          sh /usr/local/cbsd/modules/forms.d/clonos_database/initforms.sh

        4) Configure and run CBSD RACCT stats daemon:

          sysrc cbsd_statsd_hoster_enable=YES
          sysrc cbsd_statsd_jail_enable=YES
          sysrc cbsd_statsd_bhyve_enable=YES
          service cbsd-statsd-hoster restart
          service cbsd-statsd-jail restart
          service cbsd-statsd-bhyve restart

- Open ClonOS UI in your web browser.

        Default login: 'admin', default password: 'admin'

- Enjoy the ClonOS !