How to run sudo application on startup in Ubuntu without asking for password

April 30th, 2012

Option 1 - Startup Applications

Step 1: Use Ubuntu UI for configuring Startup Applications. Depending on the Ubuntu version you can either go to System > Preferences > Startup Applications or type “Startup Applications” in Dash. From there you can simply edit the list of applications that you want to run on startup. More about Startup Application UI.

Step 2: Configure your application to start with sudo without asking for password. For that you need to add your application to the list of sudoers and disable  password just for your app. Let’s open the sudoers configuration file. This can be done with visudo command like this:

sudo visudo

The reason visudo commend is recommended over using a regular text editor is because it locks sudoers configuration file while you are editing it.

Now let’s say your user name is user1 and app name is my_app.jar, then add the following line to the configuration file:

user1 ALL=NOPASSWD: java -jar /usr/local/my_app.jar

All done. Now you can restart Ubuntu and enjoy your app running.

Option 2 - Add your app to rc.local

Option 1 will start your application only after user has logged in. What if need to start your application before that or regardless if user has logged in or not? The one of the simplest options is to add your application to the rc.local file. Open editor:

gksu gedit /etc/rc.local

And add your command to execute application just before the exit 0 statement.

Option 3 - Run your app as a Service

Most common approach in Linux world is to add your app to the /etc/init.d script. You can do the same in Ubuntu too, but Ubuntu has something even better. It’s called Upstart. You can find the mode details on how it work in this blog post and on Ubuntu help page.

The beauty of this approach is that you can easily control your service from command like using start and stop command. It also allows you to configure dependencies on other services.

-=Oleg=-

Sending bulk emails from your web application – the right way

June 3rd, 2011

For us, developers, it’s easy to deal with situations when your application needs to send one or two emails at a time, but is it okay to send hundreds of emails from your hosting server? Usually not and here is why.

First of all there are technical challenges. For example you have to make sure you are not exceeding the limits set by hosting providers (which are not always officially advertised).

Second and the most challenging part is getting around spam filters. If high deliverability is important to you (otherwise why would you even bother sending emails) then you need to start thinking about playing by the rules and implementing techniques like double opt-in, unsubscribe functionality and many other little things.

Unfortunately for you and fortunately for users, anti spam filters are very suspicions and it’s not that hard to get blacklisted. So if are interested in your emails being delivered into your users’ inbox, then the safest bet is let the professionals deal with that and focus on other not less important tasks.

So, now, where should you look for professional services if you need to send bulk emails? Such service is usually called email marketing. Pick carefully. There are many variations and different price points. If you don’t know where to start here are the two companies I had very good experience with: AWeber (www.aweber.com) and iContact (www.icontact.com) . As I already mentioned, I like both companies. I’d say they break even in the set of features they provide. AWeber seems to be the most popular choice – not sure why. Pricing wise iContact is a little bit cheaper, but that’s where you have to make your own comparison based on your needs.

If are not bored to death yet, I just want to mention that respectful companies like those mentioned above have API(s) for developer so if you need to send emails from your web site, you can, but now via reliable service.

Hey one more thing to consider is that email marketing companies can collects stats for you so you can actually see how many people opened your newsletter. Isn’t it cool? ;-)

Amazon ES2 Error “Configuration information could not be read from the domain controller” SOLVED

June 3rd, 2011

I’ve got this error when I tried to change the password on Windows Server 2008 running on  Amazon ES2.

The thing is, I never changed this error before even though I had to change my password many times. What was different this time is that I had problem with server and had to Stop and Start the instance. As a result the name of the instance has changed.  The problem is Remote Desktop had saved the name of the previous instance in the username field in a form “instance name\my name”.

Soution:  I deleted the instance name in Remote Desktop and the error has gone away. Hurray!

-=Oleg=-

How to Vacuum Indexes (Java) on App Engine

February 14th, 2011

Note, you need App Engine SDK 1.4.2 or higher.

On Linux:

./appengine-java-sdk/bin/appcfg.sh vacuum_indexes myapp/war

On Windows

appengine-java-sdk\bin\appcfg.cmd vacuum_indexes myapp/war

You need to run this from command line on your local PC. This command deletes all indexes for the app that are not mentioned in the local versions of datastore-indexes.xml and generated/datastore-indexes-auto.xml.

About parameters:

  • appcfg.cmd file is part of GAE SDK and so you have to look for it in the folder where SDK is installed. If you use Eclipse then App Engine plugin is installed under “eclipse\plugins\” folder. There might be several GAE SDK folders in there, so make sure you pick the right version. For example for version 1.4.2 the folder name starts with “com.google.appengine.eclipse.sdkbundle.1.4.2″.
  • vacuum_indexes - name of the action.
  • myapp/war  – path to the war folder of your application. You need to specify the full path in there.

 Here is corresponding App Engine doc.

After you execute this command, it’s going to ask you if you actually want to delete index or not. See screenshot below. 

Delete index confirmation

Delete index confirmation

-=Oleg=-

How to download App Engine logs in Windows

February 14th, 2011

The web interface provided by admin console does not provide a lot of flexibility for analyzing your logs and sometimes you just need to have them locally to study carefully. If you are working on Windows and you feel that information provided in App Engine docs is too short, then this blog is for you.

App Engine Docs say you need to run this:

./appengine-java-sdk/bin/appcfg.sh request_logs myapp/war mylogs.txt

Well this is for Linux. If you are on Windows, here what you need to do:

  1. Find the location of the “appcfg.cmd” on your computer. I use Eclipse and in my case it was here:
    “c:\Program Files\eclipse\plugins\com.google.appengine.eclipse.
    sdkbundle.1.4.0_1.4.0.v201012021502\appengine-java-sdk-1.4.0\bin\appcfg.cmd”.
  2. Find the location of your app. You need the “war” folder. Here is what I have on my machine:
    “c:\svn\mysource\myapp\trunk\war”
  3. And the final step is to put it all together. Open command prompt and type:
    “c:\Program Files\eclipse\plugins\com.google.appengine.eclipse.
    sdkbundle.1.4.0_1.4.0.v201012021502\appengine-java-sdk-1.4.0\bin\appcfg.cmd” request_logs c:\svn\mysource\myapp\trunk\war mylogs.txt

This will do the magic of downloading your application logs to your computer. Just be patient because it may take a while. In my case downloading 9 hours of logs (~1,000,000 records) took about 30 minutes.

BTW, if you don’t specify the destination folder then file is downloaded into “c:\Documents and Settings\username\” folder.

BTW2, running appcfg.cmd without parameters will show you a help page where you can read how to specify number of days and minimum log level if you need to. By default it will be 1 day of request logs only.

-=Oleg=-

GWT – Unicode Characters

December 2nd, 2009

Sometimes simple 1 minute tasks make you stop and spend 20 minutes figuring solution out.

I’ve got a request to replace the label “Up” by this arrow “▲” . What could be simpler? I quickly replaced “Up” by “▲” in my Java source code. Then I tried to save my code and got the Eclipse error “Some characters cannot be mapped using “Cp1252″ character encoding”…

The solution is simple. I used a nice online converter http://people.w3.org/rishida/scripts/uniview/conversion.php to get the Unicode code for the arrow character and then pasted it in my Java code like this:

String upArrrow = “\u25B2″;

-=Oleg=-

GWT – best practices

October 8th, 2009

GWT tutorials is a good way to learn basics and even to build simple prototypes, but it’s certainly not enough information to start building real life application. That’s why I was so glad to find this video from Google I/O 2009 which describes best practices for architectecting GWT application.

-=Oleg=-

New Direction – Google App Engine

October 2nd, 2009

As it often happened in developers life, as soon as you become an expert in something, the life throws you a new project which requires you to learn brand new  languages, platforms, frameworks, technologies, etc… Suddenly your work day routine changes from 80% coding and 20% research to 99% of learning and researching.

Only six month ago I started working with Silverlight. We had some fun playing with new power tool, we’ve built the a series of prototypes… and that was the end of Silverlight journey.

New mission is Google App Engine.  Our language of choice is Java. My experience with Java - none. So far looking at zillions of Java frameworks makes me dizzy. After spending 2 days on learning Struts 2 I’ve realized that the learning curve is expected to be very deep. I’m diving in… – wish me good luck.

-=Oleg=-

More about IIS performance

August 24th, 2009

One more article about IIS performance from trusted source i.e. from Microsoft:

http://blogs.technet.com/mscom/archive/2008/06/09/microsoft-com-operations-performance-analysis-of-iis-7-0-windows-server-2008.aspx

-=Oleg=-

SVN Rollback – restoring deleted files and folders

August 24th, 2009

Preface

I’m not an expert in SVN version control and I don’t like using command line. I’m regular Windows user and so it was easy for me to learn how to use “Commit” and “Update” buttons in TortoiseSVN. It was easy until one day when I had to figure out how to restore delete folders.

A day when sources disappeared

One beautiful morning I checked out my sources from SVN and discovered that the most of the files and folders are gone. Apparently the night before one of the developers was cleaning SVN working folder on his machine and … Well, if you don’t know what that big red button is for it might be not a good idea to press it…

So, if don’t know what to do - ask Google. Google said – don’t worry, it’s impossible to lose anything in SVN, just do the reverse merge using following command line params… 

The problem is I didn’t want to use command line. I wanted to use beautiful TortoiseSVN UI for that. So, I found “Revert to this revision” and “Revert changes from this revision” and thought my problem is solved, but for some reason SVN was failing this task with an error “‘/svn/sources/!svn/bc/373/Test’ path not found“. Finally, after asking an SVN expert, I figured that there was a small detail which I was missing. The revision of your working copy has to be a “HEAD”.

Steps to recover deleted files or undo the submit in SVN:

  1. Get the HEAD revision from SVN it to your working folder. Working folder is the key word here. (I suggest using temporary folder)
  2. Click on Show Log
  3. In the Log window, select revision you want to undo and click on the “Revert changes from this version” in the popup menu. This will execute the merge command of the corresponding revisions.
  4. Wait for SVN to update your working folder. Working folder is the key word again. SVN updates your working folder first, so you can review the change before you commit it to SVN.
  5. Make sure your sources merged correctly and then commit the change to SVN.

Best luck recovering your sources!

-=Oleg=-