Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Thursday, June 27, 2024

Keep current log file when using logrotate

When using logrotate in Linux, you might encounter a situation where your log file gone when the log rotated. One of the flag that you may need to notice is the copytruncate flag. It did not remove the current log file, instead it copy the log file and then truncate it:

File name: /etc/logrotate.d/your-application

 /var/log/your-application/output.log {
    copytruncate
    rotate 5
    daily 
    compress
    delaycompress
    notifempty
    missingok
}


Thursday, May 9, 2024

Limit CPU and Memory usage in Linux Slack

The Linux Slack consumes a lot of CPU and memory in Linux environment. To limit its resource usages, you can apply a quote via the snap command:

sudo snap set-quota slacklimit --memory=2GB --cpu=20% slack

Thursday, March 28, 2024

Sync multiple git repo at once

Use the following command in Linux will do the job:

 ls -d RepoNames* | xargs -I{} git -C {} pull

Wednesday, August 16, 2023

Bind port 80 for normal user in Linux

To bind port 80 for normal user in Linux, use 'authbind'

Steps:

1. sudo apt get authbind

2. sudo touch /etc/authbind/byport/80

3. sudo chown user:user /etc/authbind/byport/80

4. chmod 500 /etc/authbind/byport/80

5. authbind --deep <command to run> (e.g. quasar dev)

Wednesday, June 28, 2023

Favourite LS_COLORS

Just wanna have my script files (Python script, Shell script) shows color in ls:

LS_COLORS=$LS_COLORS:'*.py=0;94:*.sh=0;94' ; export LS_COLORS 

Monday, June 5, 2023

scp windows recursive copy problem

 In you encounter scp problem when doing a recursive copy from Windows to Linux, try adding the -O parameter.

scp -r -O sample-files/ target-server:/target-path/

Thursday, January 19, 2023

Compile fanvanzh's 3dtiles in Linux

Working for fanvanzh's 3dtiles Linux compilation for days. Some items for reminding everybody how wants to do the same thing.

liwei0705 did a good move in making fanvanzh's 3dtiles converter works. But if you are using a new version of OSG and GDAL, pay attention to the following summarised reminders when building your own version of "_3dtile"

  • Delete 3dtiles/bin, it is for windows only
  • Compile your own OpenSceneGraph
    • Copy OpenSceneGraph /lib to 3dtiles
    • Copy OpenSceneGraph /include/* to 3dtiles/src/osg/*
  • If not compile OpenSceneGraph on your own, you can install "openscenegraph" and "libopenscenegraph-dev" instead
    • Delete /lib in 3dtiles (the /lib is for self-compiled OSG, GDAL actually)
    • Delete 3dtiles/src/osg/ (no need to provide OSG header, use the one in libopenscenegraphi-dev)
    • Install gdal-bin, libgdal-dev
      • rm -rf 3dtiles/src/gdal (we will use libraries and header by gdal-bin and libgdal-dev)

    • Source file: src/tileset.cpp
      • Hide up #ifdef _WIN32, turn on "epsg_convert" and "wkt_convert"
      • Comment out GDAL_DATA: 
        • // CPLSetConfigOption("GDAL_DATA", path);

    • For epsg_convert( )
      • Don't use importFromEPSG(), use:
        • // For 2326 Input (Hard code the input SRS) (Ref)
        • inRs.importFromProj4("+proj=tmerc +lat_0=22.3121333333333 +lon_0=114.178555555556 +k=1 +x_0=836694.05 +y_0=819069.8 +ellps=intl +towgs84=-162.619,-276.959,-161.764,-0.067753,2.243648,1.158828,-1.094246 +units=m +no_defs +type=crs");
        • // for 4326 Output (Hard code the output SRS) (Ref)
        • outRs.importFromProj4("+proj=longlat +datum=WGS84 +no_defs +type=crs");

    • Source file: src/earcut.hpp
      • Add header files
        • #include <stdexcept>
        • #include <limits>

    • Source file: build.rs
      • In linux bulid config, add:
        • println!("cargo:rustc-link-lib=gdal");

    • When running the ./target/release/_3dtile
      • export LD_LIBRARY_PATH=./lib

    • Side notes, if you use "cargo run" for debugging and when to rebuild the project when some CPP files are modified, add the following in linux build config (build.rs): (reference)
      • println!("cargo:rerun-if-changed=./src/tileset.cpp");


    Thursday, August 11, 2022

    Setup autostart services in Linux with SELinux


    1) Create your start / stop script in a predefined directory (e.g. /development/service-script/ )

    • /development/service-script/start-cmd
    • /development/service-script/stop-cmd

    2) Allow SELinux to execute binaries in the predefined directory /development/service-script/ (!! important for SELinux)

        chcon -R -t bin_t /development/service-script/


    3) Create abc.service in /etc/systemd/system/

        # Systemd unit file for ABC service

        [Unit]
     
        Description=ABC service
        After=syslog.target network.target

        [Service]
        Type=forking

        ExecStart=/development/service-script/start-cmd
        ExecStop=/development/service-script/stop-cmd

        User=service_owner
        Group=service_owner
        UMask=0007
        RestartSec=10
        Restart=always

        [Install]
        WantedBy=multi-user.target


    4) Reload systemd

        systemctl daemon-reload

    5) Start ABC service

        systemctl start abc


    6) If ABC service is working, then we can enabled it for autostart

        systemctl enable abc



    Wednesday, August 10, 2022

    NO_PUBKEY when updating QGIS in Linux / Ubuntu (2022)

    Update the key file (qgis-archive.gpg) by:


    wget  -qO  -  https://qgis.org/downloads/qgis-2022.gpg.key  |  gpg  --no-default-keyring  --keyring  gnupg-ring:/etc/apt/trusted.gpg.d/qgis-archive.gpg  --import


    The NO_PUBKEY error message will be gone for 'apt update'


    Tuesday, May 25, 2021

    Share folder in VirtualBox

    I'd been creating a shared folder in VirtualBox guest (Lubuntu) in a Ubuntu host. While the folder path I entered is a symbolic link, it just NOT work at all.

    So, always remember the "Folder Path" has to be a REAL PATH, no symbolic link !!





    Sunday, October 11, 2020

    Ubuntu apt-get update with NO_PUBKEY error

     In Ubuntu, I'd encountered the following error when doing a apt-get update:

    The following signatures couldn't be verified because the public key is not available: NO_PUBKEY F7E06F06199EF2F2

    This key belongs to the repository https://qgis.org/ubuntu. To add the key, I did the following:

    sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 F7E06F06199EF2F2

    By default, the command above will called gpg which uses port 11371. I had to force command   to use port 80 instead. Also, please also pay attention that the protocol is called "hkp://"

    Ref: https://askubuntu.com/questions/1119727/gpg-keyserver-receive-failed-connection-timed-out



    Thursday, September 3, 2020

    Stop / hide up pcieport error in Ubuntu / Linux

     Number of ways  to try in grub:

    • pci=nomsi
    • pci=noaer
    • pcie_aspm=off

    Actual steps:
    1. sudo vi /etc/default/grub
    2. Edit line:
      GRUB_CMDLINE_LINUX_DEFAULT="quiet splash pci=noaer"
    3. sudo update-grub
    4. Reboot machine

    Restart / Reboot Linux


    To restart Linux anytime: Hold Alt-SysRq (i.e. PrtSc) and type R E I S U B


    Reference:

    http://blog.kember.net/articles/reisub-the-gentle-linux-restart/

    Thursday, July 16, 2020

    Add git information to your bash prompt

    To show git information in your bash prompt, add the following function in your ~/.bashrc

    function git-shell() {
      export GIT_PS1_SHOWDIRTYSTATE=1
      export PS1='\[\033[01;33m\] (git) \[\033[01;34m\]\w$(__git_ps1 " \[\033[01;32m\](%s)")\[\033[00m\]\n\$ '
    }

    Then, in your bash, run "git-shell" and you will get a nice git prompt:

     (git) /path_to_your_git_project (master *)
    $ 
    

    Tuesday, July 14, 2020

    curl returns "ssl_choose_client_version:unsupported protocol" error in Ubuntu 20.x

    If you encountered "ssl_choose_client_version:unsupported protocol" when using curl in Ubuntu 20:

        $ curl https://somehost/
     
    curl: (35) error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol


    It may because the "somehost" only accepts old protocol (e.g. TLS v1, etc.), but in Ubuntu 20.x, the OpenSSL assumes minimum = TLS v1.2 by default. 

    If the "somehost" just cannot upgrade to TLS v1.2, you might consider fixing it with the following:

    1) Modify /etc/ssl/openssl.cnf

    Search for the line "oid_section = new_oids"

    Add the following lines below it:

    openssl_conf = default_conf

    [default_conf]
    ssl_conf = ssl_sect

    [ssl_sect]
    system_default = system_default_sect

    [system_default_sect]
    MinProtocol = TLSv1.1
    CipherString = DEFAULT@SECLEVEL=1

    2) curl "somehost" with the following parameters

    $ curl --tlsv1 https://somehost

    3) If the "somehost" just using a self-signed certificate

        $ curl -k --tlsv1 https://somehost

    Reference:



    Tuesday, December 17, 2019

    Keep the color prompt in tmux

    To keep your prompt (PS1) with color shown in tmux screen, add the following property in .bashrc:

    force_color_prompt=yes


    Monday, December 16, 2019

    Navigate tmux splitted pane using mouse

    To enable navigation on tmux splitted pane using mouse

    In tmux environment, do the following:
    1. Ctrl-b
    2. Type :setw -g mouse on
    Done, try to switch your tmux pane with mouse.

    Note:
    To make this setting persistent, save this line in .tmux.conf:
    setw -g mouse on





    Tuesday, December 3, 2019

    QGIS freezes while editing features

    There are many possibilities for QGIS to hang / freezes while editing features. But for my experience, I found it often hangs when using a Shapefile layer.

    To minimize this kind of problem, I tried to use other feature format (e.g. SpatialLite). And the problem is relieved to some extent.



    Have a try and let me know if it helps or not.

    CSP on Apache

    To add CSP to root if sort of funny. The following will NOT work for most cases !!     <LocationMatch "^/$">        Header s...