Monday, February 4, 2013

Using GO in Ubuntu 12.04

I'm writing this down so that when I have to do it all over again that I have a reference to guide me.

Go comes pre-installed in Ubuntu 12.04. This means that some of the instructions on golang.org require a little bit of modification when you're running Ubuntu. The biggest thing to remember is that the Go packages live at /usr/lib/go. 

If I've left anything out please add to the comments and I'll amend this entry until it's correct.

Syntax Highlighting


This took me awhile to figure out but in the end the steps required to make syntax highlighting work for Go in Ubuntu 12.04 are easy. 

Create some folders off of your home folder:

.vim
.vim/syntax
.vim/ftdetect


Then install "vim-syntax-go" b/c the files normally in "go/misc" files aren't part of the pre-installed Go version for 12.04. All of the instructions for non-Ubuntu installations make the assumption that "go/misc" files are present.


As the directions here specify:

"Place $GOROOT/misc/vim/syntax/go.vim in ~/.vim/syntax/" This is confusing because the go.vim file specified above isn't where the instructions say it is. You'll find go.vim at /usr/share/vim/addons/syntax (this is where the vim-syntax-go package put it). Just copy /usr/share/vim/addons/syntax/go.vim to $HOME/.vim/syntax/ and it should work.

And then put the following in ~/.vim/ftdetect/go.vim (create the go.vim file manually).

"au BufRead,BufNewFile *.go set filetype=go"

This has been enough for me to get syntax highlighting to work on two different machines.

AutoCompletion via the gocode daemon by nsf


This also took awhile to figure out but in the end it's easy to get running. Nsf's directions can be found here, they are very straightforward but you have to make allowances for the fact that Ubuntu's pre-installed Go packages are installed in /usr/lib/go. The difference between the normal install and the Ubuntu version for me was that when I ran "go env" to get the Go environment variables my $GOBIN path was blank. So I ran "export GOBIN=/usr/lib/go/bin" to set it and then "export PATH=$PATH:/usr/lib/go/bin" to make sure $GOBIN was in my $PATH because Vim would look for the gocode executable there. Next I ran "go get -u github.com/nsf/gocode" per nsf's instructions. Then, I went to /usr/share/go/src/pkg/github.com/nsf/gocode/vim" and ran "./update.bash". Finally I added to my .vimrc file "filetype plugin on". That was enough to make it work for me. 

Also, I added this line to my $HOME/.profile file at the end:
"export PATH=$PATH:/usr/lib/go/bin"
This makes sure that /usr/lib/go/bin is part of my $PATH environment variable every time I login.

Thursday, July 14, 2011

SQL Server Fails To Start After Reboot - Using DOMAIN\user Service Account




Recently, I was trying to get a SQL server installation to backup to a network drive. This won't work unless SQL is configured to run under an account that has network priviledges. So to fix this I opened the service control panel and switched the logon properties for Sql Server (MSSQLSERVER) to a known domain\user account that has access to the network folder I wanted to back up to. After I did this everything worked fine, SQL was running, backups ran, I could even stop and start the service with the newly stored credentials. Life was good until the next time the server rebooted and SQL didn't automatically start like it was supposed to. To fix this I opened the service control panel and tried the start SQL and received this message "The service did not start due to a logon failure". 


When that happens this message is also written to the event viewer:


Event Type: Error
Event Source: Service Control Manager
Event Category: None
Event ID: 7000
Date: 7/14/2011
Time: 7:46:11 AM
User: N/A
Computer: RCX-FLEET
Description:
The SQL Server (MSSQLSERVER) service failed to start due to the following error: 
The service did not start due to a logon failure. 


For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.


My first thought was that I must have entered the logon credentials incorrectly. So again, I entered the password, clicked "apply" and started SQL thinking that everything was fine. But on the next reboot the same problem occured again. This time I dug deeper into the Event Viewer and found this entry buried in the System log section:


Event Type: Error
Event Source: Service Control Manager
Event Category: None
Event ID: 7041
Date: 7/14/2011
Time: 4:04:25 AM
User: N/A
Computer: RCX-FLEET
Description:
The MSSQLSERVER service was unable to log on as DOMAIN\user with the currently configured password due to the following error: 
Logon failure: the user has not been granted the requested logon type at this computer.


Service: MSSQLSERVER 
Domain and account: DOMAIN\user


This service account does not have the required user right "Log on as a service."


User Action


Assign "Log on as a service" to the service account on this computer. You can use Local Security Settings (Secpol.msc) to do this. If this computer is a node in a cluster, check that this user right is assigned to the Cluster service account on all nodes in the cluster.


If you have already assigned this user right to the service account, and the user right appears to be removed, check with your domain administrator to find out if a Group Policy object associated with this node might be removing the right.


For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.


This message is pretty straight forward. It tells you what the problem in and how to fix it, most messages aren't this good. Following the instructions I opened the Security Setting snap in (Secpol.msc), navigated to "Local Policies" -> "User Rights Assignment" -> "Log on as a Service." I right-clicked "Log on as a Service" selected "Properties" so I could add the domain\user account I used to start SQL. But to my surprise I found "Add User or Group" greyed out. Well it turns out that sometimes this is set at the Group Policy level and the only place you can add users is by logging on to the Domain Controller, going to "Domain Security Policy" -> "Local Policies" -> "User Right Assignment" -> "Log on as a Service". Once you get here you should be able to add the DOMAIN\user account you want SQL to run under.