deb package on the knee

    Task: create a package for Debian to upload the daemon / site to the server.
    I've never worked with deb packages before - so the solution may not be optimal. But it works and is fairly easy to use.

    Training

    First of all, for periodic downloads to the server, we will need versioned code. If svn is used, then most likely you can use the revision number. Since I use git, I wrote a simple script for maintaining the version of the project: tag.sh
    To increase the version of the project, call ./tag.sh build, ./tag minor or ./tag major. The script creates labels of the form v..(for example v0.1.25)
    To get the version, call git describe --match = v * HEAD and get the version in the form v0.2.1 (or v0.2.1-59-g919ab19 if there were commits after the tag).

    There are many package creation manuals on the network that use dh_make or describe all possible options for creating a package from scratch. But we do not need the right package to bring the debian to the repository, but just a package of our project, which we will install on the server.

    Of all the package configuration files, only 2 seemed important:
    control - description of the package
    conffiles - description of the configuration files of the package (when installing a new version, apt will ask whether to replace the file or keep the old version).

    control

    The file format is quite simple: For example: Dependencies can be obtained using ldd and apt-file
    Package: ИМЯ_ПАКЕТА
    Version: ВЕРСИЯ - получаная git describe
    Architecture: АРХИТЕКТУРА - amd64 если есть бинарники или all - если только скрипты
    Depends: ЗАВИСИМОСТИ - можно упустить
    Maintainer: ВАШЕ_ИМЯ
    Description: ОПИСАНИЕ


    Package: ggseductionserver
    Version: v0.2.1-59-g919ab19
    Architecture: amd64
    Depends: libc6 (>= 2.4), libgcc1 (>= 1:4.1.1), libstdc++6 (>= 4.1.1), libboost-system1.38.0 (>=1.38.0),
    libboost-thread1.38.0 (>=1.38.0), libboost-regex1.38.0 (>=1.38.0), libboost-serialization1.38.0 (>=1.38.0), libboost-program-options1.38.0 (>=1.38.0),
    tokyotyrant, tokyocabinet, mysql-client (>=5.0), libssl0.9.8 (>=0.9.8), libreadline5 (>= 5.2), libmysql++3 (>= 3.0),
    libpcre3 (>= 7.6), libpcrecpp0 (>= 7.6), libgd2-xpm (>= 2.0)
    Maintainer: Alexander Fedora
    Description: glagol games server
    <ПРОБЕЛ>This is server


    $ ldd ./build/server | grep libboost_thread
    /usr/lib/libboost_thread-mt.so.1.38.0
    $ apt-file search /usr/lib/libboost_thread-mt.so.1.38.0
    libboost-thread1.38.0: /usr/lib/libboost_thread-mt.so.1.38.0
    libboost1.38-dbg: /usr/lib/debug/usr/lib/libboost_thread-mt.so.1.38.0

    conffiles

    This file contains the list of package configuration files. Example:
    /etc/seduction/seductiond.conf
    /etc/seduction/seductiond.log.properties


    Package creation

    I decided to use a simple shell script to create a package. Actions in order:
    1. Create a deb directory
    2. Create the deb / DEBIAN directory
    3. Get the current version of the project version = `git describe --match = v * HEAD`
    4. We write the package description in deb / DEBIAN / control, and use $ version as the version
    5. Write the list of configuration files to the deb / DEBIAN / conffiles file
    6. In the deb / directory we write the proxy files as if deb / is the root of the disk (for example deb / usr / local / bin / exe_name, deb / etc / config_name, etc.)
    7. Create the package using the dpkg -b deb / BACK_NAME_ $ version'.deb 'command

    After the package name, it is mandatory to put an underscore (_) in front of the version.
    An example of a working script can be found here (this is an example for a c ++ daemon, for a site on php an example is here )

    Creating a repository on the server

    Install the dpkg-dev package.
    Create the directory / var / opt / repo /, and in it 2 subdirectories binary and source.
    We fill in the packages in binary and run the command to create the archive directory: We

    dpkg-scanpackages -m binary /dev/null | gzip -9c > binary/Packages.gz

    write a shell script to automate the server update:

    rsync -av -e ssh $HOME/projects/repo/*.deb server_name:/var/opt/repo/ || exit 1
    ssh server_name 'cd /var/opt/repo; dpkg-scanpackages -m binary /dev/null | gzip -9c > binary/Packages.gz' || exit 1


    Raising nginx to access the repository

    Install nginx, add a new site: Raise the site and make sure that it works.
    $ cat /etc/nginx/sites-available/repo
    server {
    listen 9977;
    server_name localhost;
    access_log /var/log/nginx/repo.access.log;
    location / {
    autoindex on;
    allow 127.0.0.1;
    allow 192.168.0.2;
    root /var/opt/repo;
    }
    }



    $ ln -s /etc/nginx/sites-available/repo /etc/nginx/sites-enabled/repo
    $ sudo /etc/init.d/nginx restart
    $ wget 192.168.0.1:9977/binary/Packages.gz


    Install packages from the created repository

    Add our site to /etc/apt/sources.list:
    deb 192.168.0.1:9977/ binary/
    And install the package:
    $ sudo apt-get update
    $ sudo apt-get install package_name


    Conclusion

    When installing the package, apt-get will yell that the package cannot be authenticated. In principle, you can add a digital signature to the package, but we already know that it is installed from our repository - therefore, you can add the -y --force-yes keys and install the package in automatic mode.

    PS. do not kick much - this is my first post.

    Also popular now: