Posts

Perl - tidyup!!

 PerlTidy Aside from the obvious perl -c to check syntax, its good to enforce some standards on the layout of our perl scripts. Perltidy is a script that uses the perl module Perl::Tidy To install :  #   cpan install Perl::Tidy We can check install is ok by running the executable: # perltidy -h This shows us the perltidy help version and usage. To tidy a perl script with the default options simply run: # perltidy script.pl This will create a copy called script.pl.tdy - if you're happy with the formatting then copy this to the original file (you have everything under git control right?) Alternatively you can run it on a wildcard and apply to all or a subset of scripts, e.g.: # perltidy *  # perltidy a*.pl Common options include: -o=outfilename -opath=path -b backup and modify in place As I use perltidy fairly frequently its good to setup defaults - this is done in a .perltidyrc file: # PBP .perltidyrc file -l=78 # Max line width is 78 cols -i=4 # Indent level is 4 cols -ci=4

Extend Linux Filesystem for AWS EC2 instance

 How to grow a volume on aws ec2 instance so - space getting a little tight on box, cant archive or delete anything - lets grow it. another inherited box - i would really have preferred app dir to be on a separate partition to root, but moving this one required downtime so lets do it whilst our devs are still using it! prior to growing: # df -hl /dev/xvda1       36G   32G  4.1G  89% / # lsblk NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT xvda         202:0    0   32G  0 disk  └─xvda1 202:1    0   36G  0 part / we then go into aws console, look at instance under ec2 instances, click on actions -> modify volume and then increase size to 100G. alternatively (ideally!) use terraform to increase volume size, or cloudformation or: aws ec2 modify-volume --size 100 --volume-id vol-yourvolidhere df remains the same but lsblk now shows: # lsblk NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT xvda         202:0    0  100G  0 disk  └─xvda1 202:1    0   36G  0 part / we can extend the space onto parti

Change Jenkins home directory in Ubuntu

Change Jenkins home directory in Ubuntu We needed recently to change home directory of Jenkins in Ubuntu. The underlying misconfiguration on this old system is that it wasnt using LVM and so couldnt be expanded on the fly, but it is what it is. To move we create a new volume - after adding more storage if needed - this time making it under LVM so further expansions can be done on the fly if needed. as ever ensure we have backups before making changes shutdown jenkins safely - wait for current jobs to stop and also dont start new jobs .. https://jenkins-url/safeExit once stopped copy /var/lib/jenkins  to /newjenk/dir chown -R jenkins:jenkins /newjenk/dir edit /etc/default/jenkins - change JENKINS_HOME to point to new dir start jenkins (systemctl start jenkins) wait a second .. go to url, login,run a test job that has previously succeeded and ensure ok. and thats it!

AWS Elastic Load Balancing Solutions

AWS Elastic Load Balancing Solutions Overview Elastic Load Balancing - commonly referred to as ELB helps with disrtibuting traffic accross multiple EC2 instances in several availability zones, this helps with: scaling performance reliability Initially AWS provided the classic load balancer (which can confusingly sometimes be referred to as ELB also, due to historical reasons). Usually requests are round-robin, however can make them sticky so that connection between a client and endpoint is persistent for defied periods of time.. at least with ALB. Both ALB and NLB are capable of load balancing to multiple ports on the same instance. Dont necessarily need to define individual instances at backend - can create 'target groups' - which represents a logical grouping of resources such as EC2 instances or microservices, containers etc. Network Load Balancers expose a public static IP, whereas an Application or Classic Load Balancer exposes a static DNS

AWS CLI

AWS CLI Quickstart what is aws cli? essentially a command line python tool you can use to query/create/change state of all things in aws. pretty cool for performing ad-hoc commands. installing: % pip3 install awscli . . check installed ok % aws --version aws-cli/1.17.8 Python/3.8.1 Darwin/19.3.0 botocore/1.14.8 % % aws help or aws command help % complete -C aws_completer aws   <== add this to your .bashrc ^-^ stuart@stuartah ~ $ aws s3 (tab-tab here shows possible options below) cp        ls        mb        mv        presign   rb        rm        sync      website configure % aws configure AWS Access Key ID [None]: ************** AWS Secret Access Key [None]: ******************* Default region name [None]: eu-west2 Default output format [None]: json % you can also add credentials as env variables - e.g. export AWS_[ACCESS/SECRET]_KEY=... here we're adding the credentials to allow connectivity. instead of running aws confi

changing remote in git

generally remote is set by default to the place you originally cloned your repo from, however you may want to change this. a simple way is on first push use: git push -u origin remotename the above can be configured as the default in your gitconfig file: [ push ] default = current git remote set-url ..is the command we need. normally remote has the name origin, which is an alias for a remote repository, set as a key locally in place of the remote repos full url. to do the change its pretty simple: $ git remote set-url origin https://urlname.com/ USERNAME / REPONAME .git an interesting feature is we can have multiple remotes (or aliases pointing at them) in your repo... can push or pull to multiple remotes then..but be careful..can get confusing! e.g. git remote add alt different-machine:/path/to/repo

bash best practices

Bash best practices A few hints on bash best practice: * use #!/usr/bin/env bash .. this is more portable but you cant rely on a specific version * use set, dont use options to bash - if someone runs your script with bash scriptname then it will ignore the options to bash * use {} to enclose variables - can cause mistakes if you donr - e.g. variable name becomes VAR_ext rather than what you wanted * to ensure you always have a value, set defaults - e.g. "${MYNAME}" = "Stuart" - MYNAME defaults to Stuart if not already set * use spaces for tabs, not tabs - tab not portable * max line length of 80 characters for readability - use \ to split of lines if needed * dont have whitespace at end of lines as may confuse source code control like git * use $(command) instead of backticks * variables and function names lowercase and underscores - use meaninful names * constants should be in caps, declare them first in file * use readonly to set a variable reado