Archive

Linux startup script

Create script in /etc/init.d

sudo nano /etc/init.d/NameOfYourScript

The following is an example based on starting up the no-ip service [/usr/local/bin/noip], but change the name of the script and the command to start and stop it and it would work for any command.

#! /bin/sh
# /etc/init.d/noip

### BEGIN INIT INFO
# Provides:          noip
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to start a program at boot
# Description:       A simple script from www.stuffaboutcode.comwhich will start / stop a program a boot / shutdown.
### END INIT INFO

# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system
case “$1” in
start)
echo “Starting noip”
# run application you want to start
/usr/local/bin/noip2
;;
stop)
echo “Stopping noip”
# kill application you want to stop
killall noip2
;;
*)
echo “Usage: /etc/init.d/noip {start|stop}”
exit 1
;;
esac

exit 0

Warning – its important you test your script first and make sure it doesn’t need a user to provide a response, press “y” or similar, because you may find it hangs the raspberry pi on boot waiting for a user (who’s not there) to do something!

Make script executable

sudo chmod 755 /etc/init.d/NameOfYourScript

Test starting the program

sudo /etc/init.d/NameOfYourScript start

Test stopping the program

sudo /etc/init.d/NameOfYourScript stop

Register script to be run at start-up
To register your script to be run at start-up and shutdown, run the following command:

sudo update-rc.d NameOfYourScript defaults

Note – The header at the start is to make the script LSB compliant and provides details about the start up script and you should only need to change the name.  If you want to know more about creating LSB scripts for managing services, see http://wiki.debian.org/LSBInitScripts

If you ever want to remove the script from start-up, run the following command:

sudo update-rc.d -f  NameOfYourScript remove

Openvpn private key password in –daemon

Edit your openvpn.conf:

verb 3
askpass /etc/openvpn/my.pass <<< new line here

The file /etc/openvpn/my.pass just contains the password.
You can chmod this file to 600.

XFCE4 Vnc Linux

#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &

Display Virtuals As NoEdit Fields In Keystone Admin UI

Use the post init hook.
For example:

Assume the Post list model has the following, of which contentFull will be filled from the content.full virtual:

...
content: {
    brief: { type: Types.Html, wysiwyg: true, height: 150 },
    extended: { type: Types.Html, wysiwyg: true, height: 400 }
},
contentFull: {type: Types.Html, wysiwyg: true, height: 400, noedit: true}
...
Post.schema.virtual('content.full').get(function() {
    return this.content.extended || this.content.brief;
});

Then you can fill up contentFull as follows:

Post.schema.post('init', function() {
    this.contentFull = this.content.full;
});

Resize EBS volume without rebooting in AWS

This article guide you to resize the EBS volume without rebooting

1. Modify volume in AWS EC2 UI
After login to AWS console, navigate to EC2 -> Elastic Block Store -> Volumes. Click on the volume that you wist to resize, then select Actions -> Modify Volume. It will open a popup.

i) Enter the new size in the size field. Lets says we are resizing from 8 GB to 150 GB.
ii) Click Modify button
iii) Click Yes button in the confirm popup.

Now the volume has been resized, but it won’t reflect in the system. We need to do some more steps to make it work.

2. Resize the partition
Lets ssh into the machine.

i) List block devices attached to the machine.

lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 91M 1 loop /snap/core/6350
loop1 7:1 0 18M 1 loop /snap/amazon-ssm-agent/930
loop2 7:2 0 89.4M 1 loop /snap/core/6818
loop3 7:3 0 17.9M 1 loop /snap/amazon-ssm-agent/1068
xvda 202:0 0 150G 0 disk
└─xvda1 202:1 0 8G 0 part /

You can see that xvda1 is still 8 GB. Lets increase the partition to disk size.

ii) Install cloud-guest-utils

apt install cloud-guest-utils

iii) Grow the partition

growpart /dev/xvda 1

iv) Let’s check the partition size (you can see /dev/xvda1 is now 150 GB):

lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 91M 1 loop /snap/core/6350
loop1 7:1 0 18M 1 loop /snap/amazon-ssm-agent/930
loop2 7:2 0 89.4M 1 loop /snap/core/6818
loop3 7:3 0 17.9M 1 loop /snap/amazon-ssm-agent/1068
xvda 202:0 0 150G 0 disk
└─xvda1 202:1 0 150G 0 part /

3. Resize the file system

i) Check the file system size. (Still it shows only 8 GB)

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.8G 4.9G 2.6G 62% /

ii) Resize the filesystem

resize2fs /dev/xvda1

iii) Check after resizing

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 146G 4.9G 141G 3% /

So we have increased the EBS volume without rebooting and zero downtime.