Autarchy of the Private Cave

Tiny bits of bioinformatics, [web-]programming etc

    • Archives

    • Recent comments

    Archive for the 'how-to' Category

    How to fix: mod_proxy’s ProxyPass directive does not work

    10th February 2016

    So… You had finally built a nice LXC container for your web-facing application, and even configured Apache (Debian package version 2.14.18-1 in my case) to serve some static/web-only components.
    From your client-side JavaScript UI you talk (in JSON) to the API, which is implemented as a separate node.js/Python/etc server – say, on port 8000 in the same LXC container.

    The simplest solution to forward requests from the web-frontend to your API is by using mod_proxy.
    If you want to forward any requests to /api/* to your custom back-end server on port 8000, you just add the following lines to your VirtualHost configuration:

    ProxyPass “/api” “http://localhost:8000″
    ProxyPassReverse “/api” “http://localhost:8000″

    I’d suggest not wrapping this fragment with the classical IfModule: as your application will not really work without its API back-end, you actually want Apache to fail as soon as possible if mod_proxy is missing.

    That was easy, right? What, it doesn’t work? Can’t be! It’s dead simple! No way you could make a mistake in 2 lines of configuration!!! :mad_rage: :)

    Oh wait… I remember I had this problem before… Read the rest of this entry »

    Share

    Posted in *nix, how-to, Web | No Comments »

    Midnight Commander (mc): convenient hard links creation from user menu

    3rd December 2015

    Midnight Commander is a convenient two-panel file manager with tons of features.

    You can create hard links and symbolic links using C-x l and C-x s keyboard shortcuts. However, these two shortcuts invoke two completely different dialogs.

    While for C-x s you get 2 pre-populated fields (path to the existing file, and path to the link – which is pre-populated with your opposite file panel path plus the name of the file under cursor; simply try it to see what I mean), for C-x l you only get 1 empty field: path of the hard link to create for a file under cursor. Symlink’s behaviour would be much more convenient…

    Fortunately, a good man called Wiseman1024 created a feature request in the MC’s bug tracker 6 years ago. Not only had he done so, but he had also uploaded a sample mc user menu script (local copy), which works wonderfully! You can select multiple files, then F2 l (lower-case L), and hard-links to your selected files (or a file under cursor) will be created in the opposite file panel. Great, thank you Wiseman1024!

    Word of warning: you must know what hard links are and what their limitations are before using this menu script. You also must check and understand the user menu code before adding it to your mc (by F9 C m u, and then pasting the script from the file).

    Word of hope: 4 years ago Wiseman’s feature request was assigned to Future Releases version, so a more convenient C-x l will (sooner or later) become the part of mc. Hopefully.

    Share

    Posted in *nix, how-to, Notepad | No Comments »

    How to fix: Xiaomi Mi Band stopped tracking steps and sleep

    26th July 2015

    Mi BandA few days ago, my Mi Band (version 1) stopped properly tracking sleep and counting steps. Here is a full list of symptoms:

    • synchronization appears to work correctly;
    • total count of steps is updated, but when you click it – there are no per-hour details;
    • in the older app version: after sync completes, there is no green message “Updated X items”;
    • night sleep tracker does not update at all: neither total hours slept, nor per-hour details;
    • the band is otherwise functional, e.g. “Find the band” works – it vibrates and flashes diodes.

    Warangelo00 found a solution, which worked for me (and no, you do not need to hard reset the device):
    note: the fix below will most probably not work for Mi Band 2, see comments; iPhone owners may try switching iPhone from AM/PM (12-hour clock) to 24-hour clock to fix the non-synchronization problems with MiBand2 – please write in the comments if this method works for you.

    1. enable Bluetooth, if it is disabled;
    2. start Mi Fit, go to Play –> Incoming call (or, in older app version, SettingsIncoming calls);
    3. enable it – set to On;
    4. now call your mobile phone from a different one – wait for the band to vibrate and flash lights;
    5. you should now be able to refresh Mi Fit main page, and see both current day and previous night per-hour details; in the older app version, it should also show the green “Updated X items” message after syncing;
    6. you can now disable incoming calls notification if you don’t need it.

    According to Holly, the trick may also work for Mi Pulse.

    Not sure if this fix will last, but it did help me – thanks, Warangelo00!

    Share

    Posted in Hardware, how-to | 51 Comments »

    My smartd.conf, explained

    28th February 2015

    After fixing offline uncorrectable sector warning email, I have taken a closer look at my /etc/smartd.conf, and now it looks like this:

    DEFAULT -d sat -H -f -p -t -W 0,40,45 -n standby -S on -m example@example.com
    # Attributes 1, 230, and 231 are very important (-r 1! -r 230! -R 230! -r 231! -R 231!), but likely covered by -t.
    /dev/sda -s (S/../../6/01|L/../(01|02|03|04|05|06|07)/7/00) -C 0 -I 189 -I 194
    # -a implies -f and -p (through -t)
    DEFAULT -d sat -a -I 194 -W 0,40,45 -n standby -o on -S on -m example@example.com
    /dev/sdb -s (S/../../6/02|L/../(01|02|03|04|05|06|07)/7/02)
    # This drive does not decrement Offline_Uncorrectable (198) after re-allocation,
    # so only monitoring for increase, not for non-zero value.
    /dev/sdc -s (S/../../6/03|L/../(01|02|03|04|05|06|07)/7/04) -U 198+
    # This drive has 40 “normally”.
    /dev/sdd -s (S/../../6/04|L/../(01|02|03|04|05|06|07)/7/06) -W 0,42,45

    Note: explanations below are intentionally simplified; please consult man smartd.conf for more precise, complete, and up-to-date information.

    Ok, so what do these settings mean, and how is this different from default settings?
    Read the rest of this entry »

    Share

    Posted in *nix, how-to, Notepad, Software | No Comments »

    How to fix Offline Uncorrectable sector outside of a partition

    26th February 2015

    A few days ago my smartd daemon (from the smartmontools package) notified me about a +1 increase in Current_Pending_Sector (197) and Offline_Uncorrectable (198) SMART attributes. The 2.5″ Fujitsu laptop hard-drive these appeared on is very old, and it also has been working 24/365 since a little over a year.

    Running a short SMART self-test (sudo smartctl -t short /dev/sdc) produced a read error at sector 1289:

    Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error
    1 Short offline Completed: read failure 80% 22339 1289

    Looking at the partition table of /dev/sdc, we see that this sector is outside of the only RAID partition on the disk, which starts at sector 2048:

    Device Boot Start End Blocks Id System
    /dev/sdc1 2048 117209087 58605088 fd Lnx RAID auto

    Read the rest of this entry »

    Share

    Posted in *nix, how-to, Software | 1 Comment »

    How to update a multisite Drupal 6/7 installation using Drush

    25th August 2014

    There are quite a lot of posts on how to do this, but my differs a tiny little bit, so I’m saving it for my own future reference, and also for the benefits of the wider audience.

    I am updating a multisite Drupal 6 installation. To the best of my knowledge, the only difference for Drupal 7 is that instead of the site_offline D6 variable the maintenance_mode variable is used in D7.

    On Debian stable and later, you can sudo aptitude install drush and then just use it immediately after that.

    Note: I recommend su webuser (or sudo -s followed by sudo -s -u webuser) before you run any non-testing drush commands, where webuser is the user which owns your web-exposed files (e.g. Debian’s default is, I think, www-data). I’ve seen a lot of recommendations to run drush as a super-user, but that does not make sense, and may actually cause problems with file ownership.

    One last thing before we start: if your drush seems to work fine but hangs when untarring modules – check this solution.

    Read the rest of this entry »

    Share

    Posted in *nix, Drupal, how-to, Notepad, PHP, Programming, Software, Web | 1 Comment »

    Saving and restoring the list of packages installed on a Debian system using aptitude or deborphan

    18th October 2013

    The usual, or even classical way is to create the list of installed packages with sudo dpkg --get-selections > package_list, and then restore when/if necessary with cat package_list | xargs sudo apt-get -y install.

    As VihangD points out in his serverfault answer, the same can be achieved with aptitude, while also excluding dependent, automatically installed packages (which are included by the classical method). To create the list of packages, run aptitude search -F '%p' '~i!~M' > package_list. Here, -F '%p' asks aptitude to only print package names (instead of the default output, which also contains package state and description); search term ‘~i!~M’ asks for all non-automatically installed packages.

    To install packages using the created list, run xargs aptitude --schedule-only install < package_list; aptitude install. The first of these two commands instructs aptitude to mark all the packages from the list as scheduled for installation. The second command actually performs the installation.

    Hamish Downer suggests an alternative way of getting the initial package_list: using the deborphan utility, deborphan -a --no-show-section > package_list. This command asks deborphan to show a list of packages, which have no dependencies on them. Sounds very similar to what we did with aptitude above, but using deborphan will most likely result in a much shorter list of packages (on my system, deborphan printed 291 package names, aptitude printed 847, and dpkg printed 3650 package names). One more potentially important difference between aptitude- and deborphan-produced package lists is that aptitude only specifies package architecture when it is different from native (e.g. 'googleearth:i386' on a 64-bit system), while deborphan specifies architectures for all the packages (resulting in e.g. 'google-talkplugin:amd64' and 'googleearth-package:all' on a 64-bit system).

    Share

    Posted in *nix, how-to, Notepad | 2 Comments »