Graceful shutdown

 Graceful shutdown of a program involves

  • Sending SIGTERM(notify
    program that its going to be killed) ,upon receiving this signal the program stops receiving further requests(could be web requests, database operations etc)

  • Finalize ongoing/pending tasks(in-flight data)

  • Release resources (file locks, memory) and terminate(with exit status 0)

Process should be robust against sudden death(eg. power failure, hardware failures). Using robust message queue(beanstalkd) is recommended for such scenarios

Queue Concept-

  • producer puts job in the Queue(eg. json, xml)
  • consumer monitors that Queue and takes/reserve the available job
  • consumer deletes the job from Queue

Read disposability

Graceful shutdown example for golang
https://pkg.go.dev/os/signal#Notify

package main

import (
    "context"
    "fmt"
    "log"
    "net/http"
    "os"
    "os/signal"
    "syscall"
    "time"
)

func main() {
    // Hello world, the web server
    helloHandler := func(w http.ResponseWriter, req *http.Request) {
        fmt.Fprintf(w, "You requessted %s - %s", req.URL, req.Method)
        fmt.Println("Serving requests from hey...")
        time.Sleep(time.Second * 2)
        defer fmt.Println("remaining")  // acts as remaining requests 
    }
    api := &http.Server{
        Addr:           ":8080",
        Handler:        http.HandlerFunc(helloHandler),
        ReadTimeout:    10 * time.Second,
        WriteTimeout:   10 * time.Second,
        MaxHeaderBytes: 1 << 20,
    }

    serverErrors := make(chan error, 1)
    shutdown := make(chan os.Signal, 1)
    go func() {
        log.Printf("main api listening on %s", api.Addr)
        serverErrors <- api.ListenAndServe()
    }()

    signal.Notify(shutdown, os.Interrupt, syscall.SIGTERM)
    //above is not blocking operation although waiting on shutdown channel
    select {
    case err := <-serverErrors:
        log.Fatalf("Error while listening and starting http server: %v", err)

    case <-shutdown:
        log.Println("main: Starting shutdown")
        const timeout = 5 * time.Second
        // Context - it is used for Cancellation and propagation, the context.Background() gives empty context
        ctx, cancel := context.WithTimeout(context.Background(), timeout)
        defer cancel()
        err := api.Shutdown(ctx)
        /*Shutdown gracefully shuts down the server without interrupting any active connections. Shutdown works by first closing all open listeners, then closing all idle connections, and then waiting indefinitely for connections to return to idle and then shut down.If the provided context expires before the shutdown is complete, Shutdown returns the context's error, otherwise it returns any error returned from closing the Server's underlying Listener(s).*/
        if err != nil {
            log.Printf("main: Graceful shutdown didnot complete in %v:%v", timeout, err)
            err = api.Close()
            //Close() immediately closes all active net.Listeners and any connections in state StateNew, StateActive, or StateIdle. For a graceful shutdown, use Shutdown.
        }
        if err != nil {
            log.Fatalf("main: could not stop server gracefully Error: %v", err)
        }
    }
}


Image description
additional reading: link1(for context timeouts)

Context in go

Context allow you to send cancellation signal to asynchronous process/ go-routine.

context

Methods provided by context interface:-

Value(key) This method returns the value associated with the specified key.

**Done() **This method returns a channel that can be used to receive a cancelation notification.

Deadline() This method returns the Time that represents the deadline for the request and a bool value that will be false if no deadline has been specified.

Err() This method returns an error that indicates why the Done channel received a signal. The context package defines two variables that can be used to compare the error: Canceled indicates that the request was canceled, and DeadlineExeeded indicates that the deadline passed.

Functions https://pkg.go.dev/context#pkg-functions

  • Background()
  • WithCancel(ctx)
  • WithDeadline(ctx,time)
  • WithTimeout(ctx,duration)
  • WithValue(ctx, key,val)
package main

import (
    "sync"
    "time"
    "fmt"
    "context"
)

func processRequest(ctx context.Context, wg *sync.WaitGroup, count int) {
    total := 0
    for i := 0; i < count; i++ {
        select {
        case <-ctx.Done():
            fmt.Println("Stopping processing - request cancelled")
            goto end
        default:
            fmt.Printf("Processing request: %v \n", total)
            total++
            time.Sleep(time.Millisecond * 250)
        }
    }
    fmt.Println("%v Request processed...", total)
end:
    wg.Done()
}
func main() {
    waitGroup := sync.WaitGroup{}
    waitGroup.Add(1)
    fmt.Println("Request dispatched...")
    ctx, cancel := context.WithCancel(context.Background())

    go processRequest(ctx, &waitGroup, 10)
    time.Sleep(time.Second)
    fmt.Println("Canceling req")
        cancel()
    waitGroup.Wait()

}

---

% go run contxt.go
Request dispatched...
Processing request: 0 
Processing request: 1 
Processing request: 2 
Processing request: 3 
Canceling request
Stopping processing - request cancelled

Flamegraphs part 1

 

As a developer/sysadmin you can create flamegraphs to to create visualizations of system performance data recorded with the perf tool. This perf output shows a stack trace followed by a count, for a total of #N number of samples

git clone the flamegraph scripts:

cd /home/ubuntu
git clone https://github.com/brendangregg/FlameGraph

Sampling a go programme which downloads an linuxmint iso

package main
import (
    "fmt"
    "net/http"
    "io"
    "os"
)

func check(e error) {
    if e != nil {
        panic(e)
    }
}

func main() {
    d1 := []byte("helo world\n")
    for i := 0; i < 10000; i++ {
        resp, err := http.Get("https://mirrors.layeronline.com/linuxmint/stable/21/linuxmint-21-cinnamon-64bit.iso")
        //body, err := io.ReadAll(resp.Body)
        fmt.Println(resp.StatusCode)
        check(err)
        defer resp.Body.Close()
        file, err := os.Create("/tmp/hello.iso")
        size, err := io.Copy(file, resp.Body)
        defer file.Close()
        fmt.Printf("downloaded %s with size %d", file, size)
        err = os.WriteFile("/tmp/check.txt", d1, 0644)
        check(err)
    }
}

compile/build the main.go and run it ./main
Get the process id of main e.g ps aux | grep main

perf record -a -F 99 -g -p 1464 -- sleep 20
Running above command creates a perf.data file

perf script > perf.script //it will by default read perf.data from current working directory and redirects stdout to a file perf.script(ascii file)
This command reads the input file and displays the trace recorded.

Creating flame graph:-

./FlameGraph/stackcollapse-perf.pl perf.script  | ./FlameGraph/flamegraph.pl > flame1006.svg

Download and view flame1006.svg in browser

flamegraph for pid 1464

Here we can observe that io.copybuffer function is using most cpu time (io.copy source)
looking further net.(*netFD).Read is the function call using most cpu time. This net.(*netFD).Read implements func (*IPConn) Read
Conn is a generic stream-oriented network connection.
this function reads data from the connection. This func https://go.dev/src/net/http/transfer.go ¶
we also see ksys_read() is called. This function is responsible for retrieving the struct fd that corresponds with the file descriptor passed in by the user. The struct fd structure contains the struct file_operations structure within it.

Image description
sock_read_iter is fired when receiving a message on a socket
By looking at the graph we can conclude that the cpu usage by main programme is spent mostly on reading data from the connection.

legacy bios gpt and disk 2.2TB +

 You may want to review just how Linux boots from BIOS. It's a multi-step process, and the first few steps all require that the BIOS speak to the drive in the binary language of moisture vaporators (which are very similar to binary load lifters in most respects.)

Specifically, the boot process starts with BIOS looking for the MBR, then loading and executing whatever code it finds there. This code then reads the next part of the boot loader, and executes that, and then that loads your kernel and transfers control to it.

Because the BIOS code for reading from the disk is so old, it deals only with 512 byte blocks and uses a 32 bit unsigned integer to store block numbers. That means that any operations involving the boot loader can only see up to 232 * 512 bytes into the drive, or 2.2 terabytes. If you are still booting from BIOS then your /boot partition needs to exist entirely below the 2TiB barrier, or the boot loader will not be able to load from it. The start and end of the partition need to both have block numbers less than 232 or the filesystem will not be readable by the boot loader.

The same limit applies to old fashioned MBR partition tables. This is why your disk is formatted in the newer GPT style, which uses 64 bit numbers giving it a limit of 9400000000 TB. While you may be able to buy a drive bigger than that on Amazon, you may find that it isn't quite as reliable as you would hope.

Modern systems no longer use BIOS for booting but use UEFI instead. UEFI also uses 64 bit numbers to address disk blocks, so it is not affected by the 2.2 terabyte limit, only the 9.4 zettabyte limit that GPT disks have.

So, to answer your question, here are the risks associated with using oversized disks on a legacy BIOS system:

  • If the disk is used for booting and the /boot partition is not located entirely within the first 2.2 TB, it will not boot.

  • That's it. Once your BIOS reads the /boot partition it transfers control to the Linux kernel, which has no limitations on what blocks it can read. Every other filesystem can be as large as it likes, and wherever it wants to be.

 Reservation & Ref Reservation 

ZFS has two provided methods of determining used and free space. The first is at a non-granular pool level, and the second is at a dataset level. There are some very big differences in how these two viewpoints behave. Pool-wide statistics are provided by the 'zpool' command, as evidenced by this example:


root@myhost:/# zpool list
NAME           SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
example-pool  3.94G   121K  3.94G     0%  1.00x  ONLINE  -

Of note here are 'SIZE', 'ALLOC', and 'FREE'. You'll notice my brand new, completely empty 'example-pool' is 3.94 GB in size, and has allocated 121 KB of space (metadata and such). Now let's create a filesystem.

root@myhost:/# zfs create example-pool/noquota-noreserve-filesystem
root@myhost:/# zpool list
NAME           SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
example-pool  3.94G   160K  3.94G     0%  1.00x  ONLINE  -
syspool       15.9G  3.15G  12.7G    19%  1.00x  ONLINE  -

Now we've got one empty filesystem on our pool - and as some may expect, a few extra KB of allocated space (again, metadata and such). So let's see what the second viewpoint of looking at this has to say, and that's the 'zfs' command. Let's concentrate just on the important stuff for now, with a command like this:

root@myhost:/# zfs list -o name,used,avail,refer,usedds,usedchild
NAME                                        USED  AVAIL  REFER  USEDDS  USEDCHILD
example-pool                                160K  3.88G    32K     32K       128K
example-pool/noquota-noreserve-filesystem    31K  3.88G    31K     31K          0

I apologize for all the fields - but believe it or not, they're all informative (eventually). As you can see, in addition to seeing the filesystem I created a moment ago, we also see the pool itself. Or do we? Do not be fooled, gentle reader, for the 'example-pool' entry you see in 'zfs list' is not exactly equivalent to the 'example-pool' you'll see in 'zpool list'. Where 'zpool list' is showing you the pools and pool-level statistics, 'zfs list' is only showing you datasets and dataset statistics. That's right, your pool is also a filesystem dataset (indeed, all filesystems created under it are children of it).

This is important to note, because it means that 'example-pool' in 'zfs list' is going to be factoring in the used space of all the filesystems on the pool. You would think this would be pretty much the same as 'zpool list', then, right? And indeed, in the above example, both 'zpool list' and 'zfs list' are showing a used (alloc) space of 160 KB. Where this will bite you is simple: 'zpool list' does not take into account anything but actual, physically allocated blocks of data on the disks -- and 'zfs list' takes not only those into account, but also reservations as well. So what are reservations? Well, to answer that, let's first look at what ZFS' manpage has to say about them (and there 2, not one):

       reservation=size | none

           The  minimum  amount  of  space guaranteed to a dataset and its descendents. When the amount of space used is below this value, the dataset is treated as if it were taking up the amount of space specified by its reservation. Reservations are accounted for in the parent datasets' space used, and count against the parent datasets' quotas and reservations.

           This property can also be referred to by its shortened column name, reserv.

       refreservation=size | none

           The minimum amount of space guaranteed to a dataset, not including its descendents. When the amount of space used is below this value, the dataset is treated as if it were taking up  the  amount  of space specified by refreservation. The refreservation reservation is accounted for in the parent datasets' space used, and counts against the parent datasets' quotas and reservations.

           If refreservation is set, a snapshot is only allowed if there is enough free pool space outside of this reservation to accommodate the current number of "referenced" bytes in the dataset.

           This property can also be referred to by its shortened column name, refreserv.

Now, some people wax over these definitions and don't notice that 'reservation' and 'refreservation' do not actually have identical first paragraphs. The key different cam be found in the very first sentence, where 'reservation' says "and its descendents" and referservation says "not including its descendents". This is key. A hint to how important this distinction is comes in the form of the extra paragraph you find in the referservation description, but we'll get back to that in a minute. First, an initial, simple example of both. Remember our pool? Let's created another dataset, but this time, specify a reservation (as opposed to a refreservation).

root@myhost:/# zfs create -o reserv=500M example-pool/noquota-reserv-filesystem
root@myhost:/# zfs list -o name,used,avail,refer,usedds,usedchild
NAME                                        USED  AVAIL  REFER  USEDDS  USEDCHILD
example-pool                                500M  3.39G    33K     33K       500M
example-pool/noquota-noreserve-filesystem    31K  3.39G    31K     31K          0
example-pool/noquota-reserv-filesystem       31K  3.88G    31K     31K          0

Now, the keen-eyed amongst you may have noticed that while this new filesystem looks pretty much like the other one we created, suddenly the root filesystem (example-pool) is reporting USED of 500M! What? But the new filesystem isn't using 500 MB! In a panic, we check 'zpool list' to verify our assumption:

root@myhost:/# zpool list
NAME           SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
example-pool  3.94G   394K  3.94G     0%  1.00x  ONLINE  -
syspool       15.9G  3.15G  12.7G    19%  1.00x  ONLINE  -

Whew. We're right - we're not suddenly using 500 MB of disk space. So why is 'zfs list' claiming we are? Are we? The short answer is -- no, you're not. And yes, you are. See, a reservation is us telling ZFS that the filesystem have 500 MB reserved for the use of that filesystem (and its children, since its a reservation), and only for that filesystem and its children. This doesn't go write 500 MB of data to the drive.. but from the perspective of any other filesystem on that pool, it may as well have. Notice how our first fileystem, has an available space of 3.39 GB (as does 'example-pool')? Yet our new filesystem has 3.88 GB? That's 500 MB of difference (basically). 

The reason for this new discrepancy is simple - by reserving 500 MB, we've told ZFS that our new filesystem may use all of the pool and has 500 MB reserved for its use, and that any other filesystem (including our first one) cannot use 500 MB of the pool. Now, this reservation is just that -- a reservation up to that amount. It isn't 'above and beyond' what we're actually using. If I put 50 MB of data into that second filesystem, 550 MB won't be unavailable to other filesystems -- it will still be only 500. Let's test that assertion:

root@myhost:/# cd /volumes/example-pool/noquota-reserv-filesystem/
root@myhost:/volumes/example-pool/noquota-reserv-filesystem# dd if=/dev/zero of=50MB-testfile bs=1M count=50
50+0 records in
50+0 records out
52428800 bytes (52 MB) copied, 0.218335 seconds, 240 MB/s
root@myhost:/volumes/example-pool/noquota-reserv-filesystem# zfs list -o name,used,avail,refer,usedds,usedchild
NAME                                        USED  AVAIL  REFER  USEDDS  USEDCHILD
example-pool                                500M  3.39G    33K     33K       500M
example-pool/noquota-noreserve-filesystem    31K  3.39G    31K     31K          0
example-pool/noquota-reserv-filesystem     50.0M  3.83G  50.0M   50.0M          0

See? Despite adding 50 MB to the new filesystem, the old filesystem (and root filesystem) still show 500 MB used and 3.39 GB available. They won't change, in fact, until we've put 501 MB or more into that second filesystem (at which point, the reservation is almost pointless, unless we delete things and go back below 500 MB used in the filesystem).

So with our current layout, what if we add in a snapshot? What would that do?

root@myhost:/volumes/example-pool/noquota-reserv-filesystem# zfs list -t all -o name,used,avail,refer,usedds,usedchild
NAME                                                USED  AVAIL  REFER  USEDDS  USEDCHILD
example-pool                                        500M  3.39G    33K     33K       500M
example-pool/noquota-noreserve-filesystem            31K  3.39G    31K     31K          0
example-pool/noquota-reserv-filesystem             50.0M  3.83G  50.0M   50.0M          0
example-pool/noquota-reserv-filesystem@first-snap      0      -  50.0M       -          -

As expected - nothing, really. Still 500 MB used and 3.39 GB available to the pool. I'm not trying to explain how snapshots work in this post, only in how reservations can affect them - so let's move on. Time for refreservations! Let's make a new filesystem, and see what we get:

root@myhost:/# zfs list -t all -o name,used,avail,refer,usedds,usedchild
NAME                                                USED  AVAIL  REFER  USEDDS  USEDCHILD
example-pool                                       2.49G  1.39G    35K     35K      2.49G
example-pool/noquota-noreserve-filesystem            31K  1.39G    31K     31K          0
example-pool/noquota-refreserv-filesystem             2G  3.39G    31K     31K          0
example-pool/noquota-reserv-filesystem             50.0M  1.83G  50.0M   50.0M          0
example-pool/noquota-reserv-filesystem@first-snap      0      -  50.0M       -          -

So this is interesting - when we made a filesystem with a 500 MB reservation, it ate up 500 MB from the root filesystem availability - but the 'USED' on the filesystem was nil until we added a file. Yet now we've made a new filesystem with a 2 GB refreservation, and the 'USED' on the actual filesystem is 2 GB! Once again in a panic, we look at 'zpool list':

root@myhost:/# zpool list
NAME           SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
example-pool  3.94G  50.5M  3.89G     1%  1.00x  ONLINE  -
syspool       15.9G  3.15G  12.7G    19%  1.00x  ONLINE  -

Nope -- we're still only using 50 MB, from that one file we made. Whew. Ok. So does it act different? If we make a 1.5 GB file inside there, is it going to show 3.5 GB used? Let's see:

root@myhost:/# cd /volumes/example-pool/noquota-refreserv-filesystem/
root@myhost:/volumes/example-pool/noquota-refreserv-filesystem# dd if=/dev/zero of=1.5Gtest bs=1M count=1536
1536+0 records in
1536+0 records out
1610612736 bytes (1.6 GB) copied, 16.6138 seconds, 96.9 MB/s
root@myhost:/volumes/example-pool/noquota-refreserv-filesystem# zfs list -t all -o name,used,avail,refer,usedds,usedchild
NAME                                                USED  AVAIL  REFER  USEDDS  USEDCHILD
example-pool                                       2.49G  1.39G    35K     35K      2.49G
example-pool/noquota-noreserve-filesystem            31K  1.39G    31K     31K          0
example-pool/noquota-refreserv-filesystem             2G  1.89G  1.50G   1.50G          0
example-pool/noquota-reserv-filesystem             50.0M  1.83G  50.0M   50.0M          0
example-pool/noquota-reserv-filesystem@first-snap      0      -  50.0M       -          -

Hrm, nope. Looks like just as with a reservation, the 'refreserv's 2 GB isn't 'above and beyond' actual usage. As you can see, USEDDS (used dataset) and REFER have gone up to 1.5 GB on that new filesystem, but the USED remains at 2 GB. So unlike 'reserv', 'refreserv' is visually displaying the refreservation in USED, but in terms of functionality, it still is just a reservation, right? Well, mostly - but the reason for the aesthetic difference and the gotchya to 'reserv' vs 'refreserv' now comes into play as I take a snapshot of this new filesystem. Let's see what happens:

root@myhost:/volumes/example-pool/noquota-refreserv-filesystem# zfs snapshot example-pool/noquota-refreserv-filesystem@second-snap
cannot create snapshot 'example-pool/noquota-refreserv-filesystem@second-snap': out of space

What?! Out of space?? No I'm not! Quick, check 'zpool list'!

root@myhost:/volumes/example-pool/noquota-refreserv-filesystem# zpool list
NAME           SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
example-pool  3.94G  1.55G  2.39G    39%  1.00x  ONLINE  -
syspool       15.9G  3.14G  12.7G    19%  1.00x  ONLINE  -

See?! I have 2.39 GB free! Heck, even looking at the 'zfs list' we did a moment ago, I have 1.39 GB available in the root 'example-pool'! Why can't I take a snapshot? If this was a reservation, instead of a refreservation, you would be able to take that snapshot. However, this is a refreservation. It is a reservation on the dataset NOT including its children. It is a reservation stating that absolutely under no circumstances will there not be 2 GB of space available on 'example-pool' for this filesystem, ever, not even because of snapshots on this filesystem.

See, I have 1.5 GB of referenced data (REFER) in 'example-pool/noquota-refreserv-filesystem', and 1.39 GB of available space in 'example-pool' right now, and 1.5 is greater than 1.39 -- and the second I make a snapshot of this filesystem, all the existing referred data becomes referenced from the child, so I need 1.5 GB of free space outside of my 2 GB reservation, because I must still be able to meet my 2 GB commitment. Since I don't have it, the snapshot attempt fails. 

Now, let's be clear here - when you take this snapshot, you're not adding 1.5 GB of new data to the pool. Right away, all that happened was a snapshot begins referencing the existing 1.5 GB file - there's no new space usage. But the whole point of a 'refreservation' is to protect the filesystem the refreservation is on from running out of space (up to the refreservation) for ANY REASON, so it has to assume that you might want to delete that 1.5 GB file and make a new one, all while that snapshot is still there retaining a link to all the blocks of that original 1.5 GB file.

I've seen many users hit this 'no space' message, or even worse, have just barely sufficient space in their pool to take that snapshot, and then all their other datasets quickly started running out of space, even though their pool may have had tons of space left from a physical perspective. A proper understanding of refreserv would have saved them a lot of headache.

So given how potentially dangerous 'refreserv' can be from an administrative perspective, why does ZFS have it, and not just 'reserv'? There are probably a few reasons, but let me give you one (which I believe to be the main one) - zvols. 

The most common use of a zvol is as a backend 'device' then shared up over iSCSI to some client that formats it with a filesystem and treats it like any other hard drive. That client makes a few expectations about that drive -- it expects that the entirety of that drive will be available to it, and that if it thinks it is 40% full, it isn't going to suddenly get an 'out of space' error when it goes to write to it. Most clients really don't behave well when their disk suddenly starts claiming its out of space when it shouldn't. So 'refreservation' is provided by ZFS to the admin as a method of making guarantees about available space above and beyond 'reservation'.

See, with a simple 'reservation' (or with nothing at all), a zvol of 50 GB could eat up 50 GB and then, because of snapshots, eat up even more. If I was doing something crazy on the zvol that completely changed it every day, and was keeping 7 days of snapshots, I'd realistically end up with over 350 GB of used space on my pool between the base dataset and the snapshots. What if my pool only had 200 GB of total space? I'd be out of luck -- and I may very well end up sending 'out of space' errors to my client. But if that same zvol had a 'refreserv' set of 50 GB, then it is my snapshot creation attempts that would fail, and at no time would my zvol ever be in risk of running out of its 50 GB of needed space.

By default, when you create a zvol in ZFS, if you don't specify 'sparse' (with -s on the command line option), ZFS will make it a 'thick provisioned' zvol. All that actually is is ZFS making a 'refreservation' equivalent to the 'volsize' you specified for the zvol. Create one some time, and take a look for yourself. The fact is, if you're not planning on making snapshots, refreservations are a very sane way of not only guaranteeing space to your clients, but of easily keeping yourself from overprovisioning your pool. If you want to skip them, don't set a refreservation -- but be warned; if you do so, the onus is now on you as the administrator to keep a close eye on the pool utilization and take action before it gets too full. 

android device as an SMS Gateway?

 How to use your old android device as an SMS Gateway?

To use your old android device as an SMS gateway, there are some requirements.
  1. An android device that can connect to the internet and at least can run an app.
  2. 2. An active internet connection, can be both Wi-Fi or Cellular Data.
  3. An adapter for powering that device because it's going to run for 24/7/365.
Now, let's start the process
First, visit this link, sms-gateway.app/ and register a new account there. Registration is quite easy, Just type your full name, email address and again write the same email address for confirmation. And click register.
After that, you will get an email with your login credentials.
Now visit the same link and login with your credentials. After that You will see the dashboard.
Move over to devices tab and click add device. After that, a popup will appear, and you will find an APK download link along with some steps to link your android device.
Although, I am sharing here how to your android device.
Download the Android app from the given link, and Install it on your phone. Open the app after the installation, you will be asked to give the bunch of permissions. Just click Allow or Yes on all prompts you receive, and you will be presented with a login window. Touch the "SIGN IN USING QR CODE" button to scan the QR code shown below.
After that, move to your dashboard and reload it. And also don't forget to change your time zone because you may be using SMS schedule function in near future, which can send SMS in given date and time.
Now you can enjoy your own SMS gateway. Make sure you have enough balance to send SMS.
Some feature of this SMS gateway:
  1. API Access
  2. Auto Responder
  3. Dynamic SMS
  4. Bulk SMS
  5. Contacts
  6. SMS Templates
Make sure you read the Privacy Policy and use this service at your own risk. I will not be responsible for any damage or loss. Also, don't forgot to visit pricing page.
traccar sms gateway

kafka basics part1

 kafka is message streaming platform /central repository to handle high volume messages. its written in scala. it is scalable , performant , persistent,realtime streaming. Here producer generate data to kafka while consumers pull the data from kafka making kafka a Central Repository.

Streaming Data is data that is generated continuously by thousands of data sources, which typically send in the data records simultaneously. We use streaming data when data needs to be processed sequentially and incrementally on a record-by-record.
1- Sensors in transportation vehicles, industrial equipment, and farm machinery send data to a streaming application.
2 -IoT data sent by connected vehicles and use that data to monitor the traffic on different routes.








tar complete system backup

#!/bin/bash tar -zcvpf /backups/fullbackup-`date +"%F"`.tar.gz / --exclude=/proc --exclude=/sys --exclude=/dev/pts --exclude=/backups --exclude=/tmp --exclude=/run --exclude=/var/run --exclude=/lost+found  --exclude=/dev --exclude=/sys --exclude=/boot/grub --exclude=/etc/fstab --exclude=/etc/network/interfaces --exclude=/etc/udev/rules.d/70-persistent-net.rules

nxlog ssl tls

nxlog.conf file for sending logs over ssl. Copy this file from server /opt/data/etc/remote_connection/certificates/ca.crt
to windows machine . c:\Program Files\nxlog\cert

Replace 192.168.15.118 ip with your siem server ip then restart the nxlog service from the Window system.



Panic Soft

define ROOT C:\Program Files\nxlog

#ModuleDir %ROOT%\modules
#CacheDir %ROOT%\data
#SpoolDir %ROOT%\data

define CERTDIR %ROOT%\cert
define CONFDIR %ROOT%\conf

# Note that these two lines define constants only; the log file location
# is ultimately set by the `LogFile` directive (see below). The
# `MYLOGFILE` define is also used to rotate the log file automatically
# (see the `_fileop` block).
define LOGDIR %ROOT%\data
define MYLOGFILE %LOGDIR%\nxlog.log

# By default, `LogFile %MYLOGFILE%` is set in log4ensics.conf. This
# allows the log file location to be modified via NXLog Manager. If you
# are not using NXLog Manager, you can instead set `LogFile` below and
# disable the `include` line.
#LogFile %MYLOGFILE%
LogLevel INFO
LogFile %MYLOGFILE%
#include %CONFDIR%\log4ensics.conf

<Extension _syslog>
Module xm_syslog
</Extension>
<Extension _exec>
Module xm_exec
</Extension>

<Extension _json>
Module xm_json
</Extension>

<Input in>
Module im_msvistalog
ReadFromLast TRUE
<QueryXML>
<QueryList>
<Query Id='1'>
<Select Path='Application'>*</Select>
<Select Path='Security'>*</Select>
<Select Path='System'>*</Select>
</Query>
</QueryList>
</QueryXML>
</Input>

<Output out>
#Module om_tcp
Module om_ssl
Host 192.168.15.118
Port 515
CAFile %CERTDIR%/ca.crt
AllowUntrusted TRUE
Exec to_json();$Message=$raw_event;to_syslog_bsd();
</Output>

<Route 1>
Path in => out
</Route>

Please let us know if this helped you or not.

Recover LVM metadata

Recovery of lvm metadata in case of mishaps while modifying partition or corruption


root@myserver:~# apt install lvm2
root@myserver:~# head /root/lvm/archive/SIEM-vg_00002-106947711.vg

# Generated by LVM2 version 2.03.07(2) (2019-11-30): Wed Aug 4 14:54:30 2021



contents = "Text Format Volume Group"

version = 1



description = "Created *before* executing 'lvextend -l +100%FREE /dev/SIEM-vg/data'"



creation_host = "MC-UKHC1-LPSH-MAP" # Linux MC-UKHC1-LPSH-MAP 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64

creation_time = 1628088870 # Wed Aug 4 14:54:30 2021



root@myserver:~# head /root/lvm/archive/SIEM-vg_00002-106947711.vg -n 40

# Generated by LVM2 version 2.03.07(2) (2019-11-30): Wed Aug 4 14:54:30 2021



contents = "Text Format Volume Group"

version = 1



description = "Created *before* executing 'lvextend -l +100%FREE /dev/SIEM-vg/data'"



creation_host = "MC-UKHC1-LPSH-MAP" # Linux MC-UKHC1-LPSH-MAP 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64

creation_time = 1628088870 # Wed Aug 4 14:54:30 2021



SIEM-vg {

id = "fKhTFb-Uyy5-gnKu-R6Dv-keXh-73xZ-mRj31X"

seqno = 4

format = "lvm2" # informational

status = ["RESIZEABLE", "READ", "WRITE"]

flags = []

extent_size = 8192 # 4 Megabytes

max_lv = 0

max_pv = 0

metadata_copies = 0



physical_volumes {



pv0 {

id = "wKDxJk-B5tL-cMZH-aPNW-1FyP-8KAy-ozWwQA"

device = "/dev/sda4" # Hint only



status = ["ALLOCATABLE"]

flags = []

dev_size = 156342272 # 74.5498 Gigabytes

pe_start = 2048

pe_count = 19084 # 74.5469 Gigabytes

}



pv1 {

id = "FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd"

device = "/dev/sdb" # Hint only



status = ["ALLOCATABLE"]

flags = []

...





root@myserver:~# pvcreate --uuid "FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd" --restorefile /root/lvm/archive/SIEM-vg_00002-106947711.vg /dev/sdc

WARNING: Couldn't find device with uuid wKDxJk-B5tL-cMZH-aPNW-1FyP-8KAy-ozWwQA.

WARNING: Couldn't find device with uuid FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd.

Cannot use /dev/sdc: device is partitioned

root@myserver:~# sfdisk -l /dev/sdc

Disk /dev/sdc: 2 TiB, 2199023255552 bytes, 4294967296 sectors

Disk model: Virtual Disk

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disklabel type: gpt

Disk identifier: D174C1CF-EC08-42F9-A7E6-F9B838671444

root@myserver:~# sfdisk -d /dev/sdc >> sdcparttablebackup

root@myserver:~# cat sdcparttablebackup

label: gpt

label-id: D174C1CF-EC08-42F9-A7E6-F9B838671444

device: /dev/sdc

unit: sectors

first-lba: 34

last-lba: 4294967262

sector-size: 512

root@myserver:~# gdisk /dev/sdc



Command (? for help): x

z zap (destroy) GPT data structures and exit

Expert command (? for help): z

About to wipe out GPT on /dev/sdc. Proceed? (Y/N): Y

GPT data structures destroyed! You may now partition the disk using fdisk or

other utilities.

Blank out MBR? (Y/N): Y

root@myserver:~# pvcreate --uuid "FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd" --restorefile /root/lvm/archive/SIEM-vg_00002-106947711.vg /dev/sdc

WARNING: Couldn't find device with uuid wKDxJk-B5tL-cMZH-aPNW-1FyP-8KAy-ozWwQA.

WARNING: Couldn't find device with uuid FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd.

Physical volume "/dev/sdc" successfully created.

root@myserver:~# pvscan

WARNING: PV /dev/sdc in VG SIEM-vg is missing the used flag in PV header.

PV /dev/sdb4 VG SIEM-vg lvm2 [<74.55 GiB / 0 free]

PV /dev/sdc VG SIEM-vg lvm2 [<1024.00 GiB / 0 free]

Total: 2 [1.07 TiB] / in use: 2 [1.07 TiB] / in no VG: 0 [0 ]



root@myserver:~# vgcfgrestore -f /root/lvm/backup/SIEM-vg SIEM-vg

Volume group SIEM-vg has active volume: app.

WARNING: Found 1 active volume(s) in volume group "SIEM-vg".

Restoring VG with active LVs, may cause mismatch with its metadata.

Do you really want to proceed with restore of volume group "SIEM-vg", while 1 volume(s) are active? [y/n]: y

Restored volume group SIEM-vg.



root@myserver:~# blkid

/dev/sda3: UUID="dfc2bdb0-6f36-470a-9dfc-c98924b332b1" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="5e192eda-6b4c-4fa0-ae8d-8a53d91020ad"

/dev/loop0: TYPE="squashfs"

/dev/loop1: TYPE="squashfs"

/dev/loop2: TYPE="squashfs"

/dev/loop3: TYPE="squashfs"

/dev/loop4: TYPE="squashfs"

/dev/loop5: TYPE="squashfs"

/dev/loop6: TYPE="squashfs"

/dev/sdb2: UUID="43abf87d-d093-4a77-a3b6-e1faab8d0c65" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="9ddcbbe8-dca3-4236-9612-569eb7e13da0"

/dev/sdb3: UUID="3d066f7e-9ca3-46d7-afd0-021373bdb159" TYPE="swap" PARTUUID="a46bf250-cd06-4d6b-a965-1215d3610e73"

/dev/sdb4: UUID="wKDxJk-B5tL-cMZH-aPNW-1FyP-8KAy-ozWwQA" TYPE="LVM2_member" PARTUUID="1f7270a4-0caa-4025-9d3c-2fae2a801ef0"

/dev/sda2: UUID="B474-DDD0" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="d413ec6f-39c4-47d2-8a5b-06b48847f215"

/dev/mapper/SIEM--vg-app: UUID="ac421fd4-dd0f-4aa0-874b-ae4a6554ff96" BLOCK_SIZE="4096" TYPE="ext4"

/dev/sdb1: PARTUUID="a95b528d-a529-4ea8-92de-ea8b46fd67f3"

/dev/sdc: UUID="FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd" TYPE="LVM2_member"

/dev/sda1: PARTUUID="18b705bc-4c32-4391-ab95-0b47ab67e831"





root@myserver:~# vgchange -ay SIEM-vg

2 logical volume(s) in volume group "SIEM-vg" now active









Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors

Disk model: Virtual Disk

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: gpt

Disk identifier: 7F434980-3FBB-4D7D-9770-F446936F74FE



Device Start End Sectors Size Type

/dev/sdb1 2048 63487 61440 30M BIOS boot

/dev/sdb2 63488 37746687 37683200 18G EFI System

/dev/sdb3 37746688 53370879 15624192 7.5G Linux swap

/dev/sdb4 53370880 209713151 156342272 74.5G Linux LVM





Disk /dev/sdc: 2 TiB, 2199023255552 bytes, 4294967296 sectors

Disk model: Virtual Disk

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes





Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors

Disk model: Virtual Disk

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: gpt

Disk identifier: 12D18C3D-9E89-4B69-8FB3-E163A97BD783



Device Start End Sectors Size Type

/dev/sda1 2048 4095 2048 1M BIOS boot

/dev/sda2 4096 1054719 1050624 513M EFI System

/dev/sda3 1054720 209713151 208658432 99.5G Linux filesystem





Disk /dev/mapper/SIEM--vg-app: 18.63 GiB, 19998441472 bytes, 39059456 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes





Disk /dev/mapper/SIEM--vg-data: 1.05 TiB, 1159553089536 bytes, 2264752128 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

root@myserver:~# pvs

PV VG Fmt Attr PSize PFree

/dev/sdb4 SIEM-vg lvm2 a-- <74.55g 0

/dev/sdc SIEM-vg lvm2 a-- <1024.00g 0



root@myserver:~# pvre

pvremove pvresize

root@myserver:~# pvresize -t /dev/sdc

TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.

Physical volume "/dev/sdc" changed

1 physical volume(s) resized or updated / 0 physical volume(s) not resized