Tag: devops

  • What to do with the one-shot scripts

    I can’t really answer this question, but I am really curious.

    During work, I often have small(ish) tasks to solve, and when it is possible I’d rather write small one-shot scripts instead of doing some manual labor.

    These scripts are rough. They are not made perfect because they don’t have to, they have one purpose, and they have to do it right. Sometimes they have small mistakes in them, sometimes they just aren’t perfect, sometimes they are awful. There are always compromises when creating these like ‘is this task worth the extra hours, or should I just aim for a solution to the problem’.

    Let me show this in an example. Today I am working on a script that copies big amounts of data between two servers. I want to do it with multiple threads, but I also want to limit the number of threads.

    My quick and dirty solution looks like this:
    for row in cursor:
    while len(threading.enumerate()) > MAXTHREADS + 1:
    time.sleep(.1)
    worker = Worker(row)

    Yes, I know, civilized people don’t use ‘sleep’, because that is a waste of CPU, but hey, I will run this script on an ephemeral EC2 instance, so I really don’t care. This will do it, so deal with it.

    But after the migration, I do want to keep this script somewhere because it is possible that I’ll need something like this in the future, and I don’t want to reinvent the wheel then.

    My GitHub account would be a perfect place for them, but I am not sure if I can put them there. I mean, a GitHub account is like a business card (remember Patrick Bateman), I don’t want to put ugly code there – I mean if I want to find a new workplace, then it will be possible that they will check my GitHub stuff, and I don’t want them to think I am a bad coder.

    If I had a paid account (which I don’t have) then I’d put these into a private repo.

    Nowadays I put these into gists, but gists are not easy to search, so that is not perfect as well.

    I am not sure what would be the best.

     

  • MySQL replication module for ansible

    We maintain a lot of servers under Kinja, so we have to use some orchestrator software to perform some tasks on a lot of servers. The Ansible software is used by us because it is cool.

    We also have a lot of MySQL servers (and counting!) under Kinja, so we have some tasks to perform on them, such as managing replication. Of course, there are some ways to do this, for example by using multiplexed terminals or running ansible shell commands that perform mysql queries (e.g. ansible mysql-master1 -m shell -a “mysql -e “SOME SQL QUERY HERE”) but it is not too comfy and needs a lot of manual work.

    So, there is a way to make it easier for us, and that’s why I made a mysql_replication module for Ansible. (And I made a pull request for that on GitHub, so I hope it will be merged into the ‘official’ branch soon.)

    The mysql_replication module helps you to

    • Query slave status
    • Query master status
    • Change the replication slave’s parameters (such as master server IP, master_log_pos, etc.)
    • Stop the slave thread
    • Start the slave thread

    The module can be found in my GitHub repo here.