Tag Archives: Linux

Linux – Preserve Environment Variables when using sudo

Sometimes we may want to preserve the environment variables of the original user when using sudo.

If you want to preserve all env variables, you could use the -E option. But use it with caution.

sudo -E bash -c 'echo $PATH'

 

A better approach is to list those env variables which u want to preserve in the sudoers config file. For example, i want to keep the HTTP_PROXY and HTTPS_PROXY.

Defaults env_keep +="HTTP_PROXY"
Defaults env_keep +="HTTPS_PROXY"

 

So every time you use the sudo command, the HTTP_PROXY and HTTPS_PROXY are kept.

Done =)

Reference:

Advertisement

collectd – Cannot send out matrics

collectd is a statistics gathering tools which helps system admin to analysis the system conditions. It includes both server and client implementations. The collectd client send metrics to the collectd server.

 

I installed the collectd on a CentOS 7 machine and try to send the metrics to a Graphite instance. But no matter how i changed the setup, the Graphite couldn’t receive any data. Finally, i realized that it is blocked by the SELinux policy.
Continue reading collectd – Cannot send out matrics

Artifactory – Upload artifact through command line

Jenkins works well with Artifactory and the built artifact will be upload to the Artifactory repository automatically.

One day, i found that the artifact is built but it is not uploaded. The Linux server doesn’t have the desktop interface so i couldn’t upload the artifact through browser. An alternative way is to use the curl command to post the artifact to the repository.

curl -X POST <target url> --data <artifact>

 

Example:

curl -X POST http://localhost:8081/artifactory/dev-snapshot-local/eureka-v0.0.1.tar.gz --data eureka-v0.0.1.tar.gz

 

Done =)

Reference: StackOverflow – How do I deploy a file to Artifactory using the command line

Django – Schedule django-admin command using django-chronograph

Previously we talked about setting up some custom command in a Django project.

 

I would like to run the custom command in a regular interval. I could use Linux cronjob but it’s hard to manage and check the run history. It would be great if i could setup and manage these scheduled commands on the Django web portal.

django-chronograph, written by wnielson, is a Python Package which allows us to schedule any django-admin command through the web interface. It works well with the UTC timezone but if you have set the TIME_ZONE in your Django project setting.py, there would be time discrepancy.

For more detail about the bug, you can refer to the Issue #36 – Job doesn’t follow the Django’s TIME_ZONE setting.
Continue reading Django – Schedule django-admin command using django-chronograph

Install Graphite under pyenv virtualenv on Ubuntu

It took me one and an half day to get the Graphite working…

1. Make sure you have pyenv and pyenv-virtualenv installed.

 

2. Install the following packages.

sudo apt-get install python-dev pkg-config libcairo2-dev memcached

 

3. Install Python 2.7 with enable-shared.

env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 2.7.8

Continue reading Install Graphite under pyenv virtualenv on Ubuntu

Ubuntu – Install Monit

Monit is a opensource monitoring tool on Unix system. The simplest use case would be restarting your service if there is failure.

On Ubuntu, simply run apt-get to install Monit.

sudo apt-get install monit

 

The Monit folder is at /etc/monit. Before you can read anything from Monit, create the /etc/monit/conf.d/monit.conf in order to setup the Monit web interface.

set httpd port 2812 and
  use address localhost
  allow localhost

Continue reading Ubuntu – Install Monit

Housekeeping Puppet Master

Yesterday i used a Puppet master as an example to talk about purging old files on Linux.

Of course we can setup a cron job and run the shell command daily for housekeeping. But as we are using Puppet, we don’t we do that thru Puppet manifest?

tidy { 'puppet::reports':
  path => '/var/lib/puppet/reports',
  matches => '*.yaml',
  age => '14d',
  backup => false,
  recurse => true,
  rmdirs => false,
  type => 'ctime',
}

 

The above tidy type will delete those .yaml which is older than 14 days.

Done =)

Reference: Google Groups – Purge puppet’s reports