//TODO: professional stuff of software engineer 1001010
Category Archives: Linux
Create a 2GB test file filled with urandom noise

I was testing a thing(tm) and I needed 2GB of data to send between 2 things

dd if=/dev/urandom of=sampledata.2gig bs=1048576 count=2048

This worked for me, your milage may vary

Fixing GitLab 502 on my Synology

I run a dockerized GitLab (9.4) on my synology & it started giving me the same 502 error on every page load.

Symptoms

  • 502 Errors on all GitLab pages telling me of to reach out to the system administrator (which is me)
  • Synology > Docker > Container(s) > ‘synology_gitlab’ > Details > Terminal
    Shows “Unicorn” starting and stopping every second or two

Problem

The “unicorn.pid” file was not deleted during a previous GitLab shutdown.  This file is used to block two or more instances of GitLab from running at the same time.  Now when GitLab starts, it erroneously thinks that GitLab is already running and immediately shuts down.  This leads to an endless loop of the scheduler restarting GitLab every few seconds.

Fix

This is a workaround to get back up and running quickly.  In a better world, we would never have to do this dumb maintenance task.

  • ssh to your synology
  • connect as root
  • get a bash shell inside the container
    $ docker exec -it synology_gitlab bash
  • remove the bogus pid file
    $rm /home/git/gitlab/tmp/pids/unicorn.pid
  • Verify the 502 error is gone.  May take a few moments as it starts up for real this time

Solution

File a bug with GitLab so you don’t have to do this ever again.

When the application checks for another running instance at startup, it shouldn’t blindly trust that the existance of a pid file as proof that it’s already running.  The previous instance may have crashed and never had the chance to clean up after itself.  The startup code should check if the pid listed is valid and delete the file if it is not.

It’s sort of like checking for a signed certificate on a file.  It’s not sufficient to check that it is signed, you need to take the extra step and verify the signature is valid for THAT exact file.  I mention this because many corporate A/V products had this bug in the past.

For OSX it’s .profile not .bashrc

Note to self

$ vim ~/.profile
alias ll="ls -lsa"
Note to self: ssh auto login

Sometimes I want ssh to just connect and not ask me for the remote password. By sometimes, I mean last time was 2 years ago.

This works on my mac, your mileage will vary

Make some keys

I like to create unique keys for each site and store them away, for reasons..

$ ssh-keygen -t rsa
Enter file in which to save the key (~/.ssh/id_rsa): ~/.ssh/id_rsa_EXAMPLE_TLD
passphrase: REDACTED
passphrase again: REDACTED
bla bla bla info about the fingerprint & ascii art

Ensure there is a ~/.ssh/ folder on remote

Note: you may have to change permissions on the remote .ssh folder and .ssh/authorized_keys

$ ssh MYUSERNAME@EXAMPLE.TLD mkdir -p .ssh

Send our newly minted public key to the remote

$ cat ~/.ssh/id_rsa_EXAMPLE_TLD.pub | ssh MYUSERNAME@EXAMPLE.TLD 'cat >> ~/.ssh/authorized_keys && chmod 644 ~/.ssh/authorized_keys'

Tell OSX to use our key for this server

$ vim ~/.ssh/config
Host example.tld
	Hostname example.tld
	IdentityFile ~/.ssh/id_rsa_EXAMPLE_TLD
	User MYUSERNAME

Test it out by connecting to it

$ ssh MYUSERNAME@EXAMPLE.TLD
Welcome to EXAMPLE.TLD
Last Login: TIMESTAMP from YOURIP
MYUSERNAME@EXAMPLE.TLD $ _