Thursday, July 10, 2014

How to refresh your ldap name database in an ldap client

This is useful when, you have a server that is authenticated by ldap. After you have edited something in your ldap server, let's say you have edited a gid for a user, you would find out that it won't be reflected immediately on the client side. So in this case, how would you force your client to accept your newly changed settings? The answer is you need to restart nscd (name service cache daemon):

$ getent passwd pauld

pauld:x:1987:1987:Paul Daniels:/home/pauld:/bin/bash
So after you have made your changes in the server, let's say you want to change pauld's gid to 4000, run the above command again:

$ getent passwd pauld

pauld:x:1987:1987:Paul Daniels:/home/pauld:/bin/bash

Still the changes are not being reflected there. To solve this, simply restart nscd:

$ sudo /etc/init.d/nscd restart

Stopping nscd:                                             [  OK  ]

Starting nscd:                                             [  OK  ]

You should be seeing your change is now updated in the user database:

$ getent passwd pauld

pauld:x:1987:4000:Paul Daniels:/home/pauld:/bin/bash


PS: If for some reason you are still not seeing the new data, you can invalidate the nscd database by:
$ sudo nscd --invalidate=passwd 

where passwd is the name of the table name in nscd database. You can see all available table name in /var/db/nscd 

To look into what is the content of each table, please use strings command:
$ sudo strings /var/db/nscd/passwd




Tuesday, July 1, 2014

How to install custom upstart script

To install custom upstart script, please follow below steps (in this example, I'll be using a service call cat):

  1. Copy the script into /etc/init 
  2. To make upstart distinguish the new service, run: 
    • $ initctl reload-configuration 
  3. Check whether your script is already in upstart by running:
    • $ initctl list | grep cat 
      cat stop/waiting
  4. And you are done, you can check the status of your service by running:
    • $ service cat status 
      cat stop/waiting
  5. You can also do the same with start, stop and restart
    • $ service cat start
      * Starting cat .... [OK]
    • $ service cat stop
      * Stopping cat .... [OK]
    • $ service cat restart * Restarting cat .... [OK]