Disable automatic restart in MS Windows

At my current work, MS Windows is a corporate standard, so I have to spend my days in a VMware virtual machine.  With two large monitors, that’s not a big issue at all.  However there is one really annoying bit about my Windows machine.  If I leave it on overnight, it sometimes reboots by itself.  Yes, it tries to save the state of most applications and even my virtual machine state is restored more often than not, but it is still annoying and unnecessary.   Gladly, there is a solution:

Alright, first off let’s click the Start button. Once the menu pulls up we can click on “Run”. Now you should have a field to type in, let’s type “gpedit.msc” and hit enter. Once the screen comes up click the + next to “Local Group Policy” than “Computer Configuration” than “Administrative Template” than click on the “Windows Updates” folder. In here you will find a bunch of different variables. If you click on them in the right pane there should be some definitions of what each one does. I will not go in-depth on all of them because you can obviously read. The key we are looking for is “No auto-restart for scheduled Automatic Updates Installations”. Right click on that value and hit properties. Now click on Enabled, than hit “Apply” and “Ok”. Now close the Console1 window. It will prompt you to save, choose “Yes” and than “Save”. Now that you have saved the settings a reboot is necessary for the policy to take effect.

 

MySQL export CSV into OUTFILE triggers “access denied” error

I came across a weird problem today.  Gladly, the web is full of solutions, but I’m going to post this anyway, just to have it nearby for the next time.  I needed to export the results of some query into a CSV file directly from MySQL.  I prepared my query, made sure that I can see the correct results and than changed it to export into the file. The query looked something like this:

SELECT id, field1, field2, field3
INTO OUTFILE '/tmp/data.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM data_table
WHERE field1 = 0;

I was quite surprised to find myself staring at:

ERROR 1045 (28000): Access denied for user ‘db_user’@’localhost’ (using password: YES)

My database user definitely had full access to the database.  I definitely could see the results of the query before the redirect to the file.  And I definitely had enough permissions to create files in /tmp directory.  And on top of that, I’m sure I used MySQL export functionality a gadzillion times and it always worked without any problems.   What’s wrong this time?

A quick search around got me to this Stack Overflow question.  Apparently, database user has to be given a FILE privilege, which is global (not per-database).   Here is what I did to solve the problem (you’ll need to use MySQL root user of course):

USE mysql;
UPDATE user SET File_priv = 'Y' WHERE User = 'db_user';
FLUSH PRIVILEGES;

I think that it worked for me before was because I exported as root, who does have this permission set to ‘Y’.

Upgrading to PHP 5.2.x on CentOS

Today while setting up yet another project on my hosting server.  The server runs CentOS 5.6, which means PHP 5.1.6 is used.  However the new project required PHP 5.2.0+.  It turned out upgrading PHP is trivial.  There is even a Howto Guide in CentOS wiki.  The steps are:

  1. Add CentOS Testing repository to yum.
  2. yum update PHP packages.

That’s all folks!

RT3 : Automatically assign owner by queue

There is one bit of functionality that I keep reusing for pretty much every installation of RT3 – automatic assignment of tickets to specific users based on queue.  There are a few solutions to this problem and some are documented in RT3 wiki.  But I always keep forgetting which solution to use and where I found it.  So, in hopes not to ever spend more than 3 seconds searching for such a solution, I’m posting it here.

We’ll be using a global scrip instead of a per-queue scrip.  This will simplify maintenance for those installations that use a lot of queues – you’ll need to change settings only in one place rather than all over the place.  Create the new global scrip with the following settings:

  • Description: AutoSetOwnerForQueue
  • Condition: On Create
  • Action: User Defined
  • Template: Global Template : Blank
  • Stage: TransactionCreate
  • Custom condition: return 1;
  • Custom action preparation code: return 1;
  • Custom action cleanup code:
my %owners = (
  'queue_name1' => 'username1',
  'queue_name2' => 'username1',
  'queue_name3' => 'username2',
);
my $QueueName = $self->TicketObj->QueueObj->Name;
return 1 unless defined($owners{$QueueName});
my $Actor = $self->TransactionObj->Creator;
return 1 if $Actor == $RT::SystemUser->id;
return 1 unless $self->TicketObj->Owner == $RT::Nobody->id;

my $MyUser = $owners{$QueueName};

$RT::Logger->info("Auto assigning ticket #". $self->TicketObj->id ." to user $MyUser" );
my ($status, $msg) = $self->TicketObj->SetOwner( $MyUser );
unless( $status ) {
  $RT::Logger->warning( "Impossible to assign the ticket to $MyUser: $msg" );
return undef;
}
1;

Last time I’ve used this was on RT 3.8.8. Adjust accordingly for the earlier and later versions.