Running with Ruby

Tag: Linux (page 2 of 14)

Ubuntu 14.04 Gnome keyring (Seahorse) auto unlock when auto login

Seahorse doesn’t unlock your keyring when you have auto login enabled. The funny thing is that even if you set up an empty password, you will still have to unlock it manually. Maybe it’s a bug, maybe it’s a security feature. Either way, if you have an encrypted LVM like I do, and you shutdown your computer when you don’t need it having to unlock keyring each time can be a real pain in the ass. First you need to unlock whole system, then you skip login (because of the auto login), but you still need to unlock keyring.

Luckily there’s a really simple solution to this:

Change your keyring password

First, you need to change your keyring password. Use unique pass-phrase that you don’t use anywhere else because it’s going to be stored in plain text. To do this, press ALT+F2, type seahorse and press enter. You will see following window:

keyring1

Go to View and select By keyring. You should see something like this:

keyring2Right click on Login Keyring (the first one) and Change password. Then just provide an old one (should be the same as you account password) and a new one.

Create a simple Python script

Now you have a new keyring password. To unlock it automatically, we will use a simple Python script, that will be executed each time you are auto logged in:

#!/usr/bin/python

import gnomekeyring
gnomekeyring.unlock_sync(None, 'your keyring password');

save it as a hidden file somewhere in your home directory (I used ~/.keyring).

Now add executing rights:

chmod +x ./.keyring

You can also execute it to check if it’s working:

[~]$ ./.keyring 

If it doesn’t you will see an error explanation:

[~]$ ./.keyring
Gkr-Message: secret service operation failed: The password was invalid
Traceback (most recent call last):
  File "./.keyring", line 3, in <module>
    gnomekeyring.unlock_sync(None, 'PyGaCQbiacPUPgFcJrwjIsEcz');
gnomekeyring.IOError

Add your keyring script to autostart (auto startup)

Just ffollow this article and in a command field put: /home/mencio/.keyring

That’s all. After that, you should have automatically unlocked keyring after your auto login.

Ruby & Rails: Making sure rake task won’t slow the site down

If you don’t have multiple cores and/or you have a small VPN, you may end up with a huge slow down of your web app, when rake tasks are executed. This can be a big issue especially when you use something like whenever to perform periodic tasks. Luckily there’s a nice program:

nice is a program found on Unix and Unix-like operating systems such as Linux. It directly maps to a kernel call of the same name. nice is used to invoke a utility or shell script with a particular priority, thus giving the process more or less CPU time than other processes. A niceness of −20 is the highest priority and 19 or 20 is the lowest priority. The default niceness for processes is inherited from its parent process and is usually 0.

With nice you can tell your Linux kernel to give your rake tasks the lowest priority possible. Thanks to that, you can make sure, that any task with higher priority (like web UI server) won’t get stuck because of the background rake task.

Here’s how you can use it:

RAILS_ENV=:environment nice -n 19 bundle exec rake :your_task 

If you use a gem like whenever, you can easily integrate nice with it:

job_type :runner, "cd :path && nice -n 19 script/rails runner -e :environment ':task' :output"

every 30.minutes do
  runner 'Worker.new.perform'
end

or for a rake task with whenever, you can use this:

job_type :runner, "cd :path && :environment_variable=:environment nice -19 bundle exec rake :task --silent :output"

every 15.minutes do
  runner 'your_task'
end

Note: Of course this will help, when CPU is your bottleneck. Keep in mind that you’re rake task might slow down your website because of many more reasons (IO, DB, etc).

Olderposts Newerposts

Copyright © 2017 Running with Ruby

Theme by Anders NorenUp ↑