quinta-feira, 19 de novembro de 2009

Ubuntu Server: Can't shutdown from power button - Ubuntu Forums

Thread Tools Display Modes
Old May 13th, 2006 #1
bullgr
Gee! These Aren't Roasted!

bullgr's Avatar

Join Date: Apr 2006
Location: Greece
Beans: 198
Ubuntu 9.04 Jaunty Jackalope
Send a message via ICQ to bullgr Send a message via AIM to bullgr
Ubuntu Server: Can't shutdown from power button

Hi...

Need help... please, it's important for me...

I have setup a Ubuntu file server with ubuntu server cd 5.10 "Breezy Badger" in my workplace.

Because the other co workers are "winblows zombies" i want to start and shutdown the pc from the power button.

Starting is ok... i power on the pc and leave it as it is in the login prompt without login and all works fine.

But to shutdown, the power button are not respond. I must login and shutdown from the command line.

For me its ok but for the "winblows zombies" is this unacceptable.
And i can't always there to shutdown the pc (vacation, sik etc).

In my home the power button works fine and for shutdown, but there i have the ubuntu desktop version installed.

The server pc is a P4 1.8

Thank's
bullgr is offline Reply With Quote
Old May 13th, 2006 #2
skippy81
Way Too Much Ubuntu

Join Date: May 2006
Beans: 224
Dapper Drake Testing/
Re: Ubuntu Server: Can't shutdown from power button

Firstly you need to focus on ACPI, since it the powerbutton produces an ACPI event. Therefore you want to have ACPI enabled in BIOS and in the Kernel - if you installed your server using "noacpi" as a boot option, then that would explain the problem.

Try doing this from a terminal

Quote:
sudo gedit /etc/acpi/events/powerbtn
This is what my file looks like:-

Quote:
# /etc/acpi/events/powerbtn
# This is called when the user presses the power button and calls
# /etc/acpi/powerbtn.sh for further processing.

# Optionally you can specify the placeholder %e. It will pass
# through the whole kernel event message to the program you've
# specified.

# We need to react on "button power.*" and "button/power.*" because
# of kernel changes.

event=button[ /]power
action=/etc/acpi/powerbtn.sh
as you can see it runs a script called powerbtn.sh that looks like this

Quote:
#!/bin/sh
# /etc/acpi/powerbtn.sh
# Initiates a shutdown when the power putton has been
# pressed.

[ -f /var/lock/acpisleep ] && exit 0

# If gnome-power-manager is running, let it handle policy
if [ `pidof gnome-power-manager` ]; then
exit
fi

# Check for kpowersave
if [ `pidof kpowersave` ]; then
exit
fi

# And for kded/klaptopdaemon
if test -f /usr/bin/dcop; then
if [ "x$(dcop kded | grep klaptopdaemon)" != x ]; then
exit
fi
fi

# Otherwise, if KDE is found, try to ask it to logout.
# If KDE is not found, just shutdown now.
if ps -Af | grep -q '[k]desktop' && test -f /usr/bin/dcop
then
dcop --all-sessions --all-users ksmserver ksmserver logout 0 2 0 && exit 0
else
/sbin/shutdown -h now "Power button pressed"
fi
Check if your files look the same as mine.
skippy81 is offline Reply With Quote
Old May 13th, 2006 #3
bullgr
Gee! These Aren't Roasted!

bullgr's Avatar

Join Date: Apr 2006
Location: Greece
Beans: 198
Ubuntu 9.04 Jaunty Jackalope
Send a message via ICQ to bullgr Send a message via AIM to bullgr
Re: Ubuntu Server: Can't shutdown from power button

thank's for the quick response...

The problem is that were is not any
/etc/acpi
the folder does not exist...

Don't forget, i have Ubuntu Server installed
bullgr is offline Reply With Quote
Old May 13th, 2006 #4
jtibau
Just Give Me the Beans!

jtibau's Avatar

Join Date: Apr 2006
Location: Guayaquil, Ecuador
Beans: 74
Ubuntu 6.10 Edgy
Send a message via MSN to jtibau Send a message via Skype™ to jtibau
Re: Ubuntu Server: Can't shutdown from power button

Since the file server is used at an office I guess you want it to shutdown everyday at the same time... After everyone leaves.
Sounds to me like you could try setting up a task that shuts it down every day after office hours. I think the cron service manages that kind of stuff but I don't know how to configure it yet . I'll let you know if I figure it out soon...
jtibau is offline Reply With Quote
Old May 13th, 2006 #5
bullgr
Gee! These Aren't Roasted!

bullgr's Avatar

Join Date: Apr 2006
Location: Greece
Beans: 198
Ubuntu 9.04 Jaunty Jackalope
Send a message via ICQ to bullgr Send a message via AIM to bullgr
Re: Ubuntu Server: Can't shutdown from power button

I find the solution... because a install from "Ubuntu Server cd" don't install acpi by default (like the desktop version), i must install it manualy

Quote:
sudo apt-get install acpid
and all is done... now everyone can shutdown the server from the power button (even the winblows zombies) without the need to login first.

Thank's for the help and for the quick response
bullgr is offline Reply With Quote
Old July 15th, 2008 #6
nexxus07
5 Cups of Ubuntu

Join Date: Apr 2008
Beans: 15
Re: Ubuntu Server: Can't shutdown from power button

Thank you, this was very helpful for stopping my virtualbox machines which are set up to start with the init.d.

This script helped me a great deal in setting it up:
http://farfewertoes.com/code/vboxcontrol/

and now they shut down and start up completely automatically which is just what I need.
nexxus07 is offline Reply With Quote

quarta-feira, 4 de novembro de 2009

MySQL: “Access denied for user ‘debian-sys-maint’@’localhost’” « RU-FI-OOOOOH!

MySQL: “Access denied for user ‘debian-sys-maint’@’localhost’” « RU-FI-OOOOOH!: "RU-FI-OOOOOH!

Sohail Mirza, standing in for Peter.
MySQL: “Access denied for user ‘debian-sys-maint’@'localhost’”

with 3 comments

For all you Ubuntu/MySQL developers out there, have you ever seen the following?

neo@thematrix:~$ sudo /etc/init.d/mysql restart
* Stopping MySQL database server mysqld [fail]
* Starting MySQL database server mysqld [ OK ]
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)'

So, what is this “debian-sys-maint” user? Well, this MySQL user is created for the Ubuntu to be able to start/stop the database and to carry out other maintenance operations.

Sounds well enough, but then why do I keep running into the “access denied” problem for this user? Well, the issue is that with each update to MySQL, the user’s password in the database is overwritten. Ubuntu seems to go to the file /etc/mysql/debian.cnf in order to find this user’s password, but obviously the password is out of sync after the update has been applied.

As a result of this behaviour, I’ll run into the “access denied” problem every so often. Thankfully, the solution to this issue is fairly simple.

First, list the contents of the /etc/mysql/debian.cnf file:

neo@thematrix:~$ sudo cat /etc/mysql/debian.cnf

The contents of the file should look something like the following:

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = n4aSHUP04s1J32X5
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
user = debian-sys-maint
password = n4aSHUP04s1J32X5
socket = /var/run/mysqld/mysqld.sock
basedir = /usr

See that password? That’s what we’re looking for!

Next, we want to issue a command to MySQL that tells it to grant the debian-sys-maint user all necessary privileges using the new password.

Login to your mysql server using your root account and the root password you had originally set:

neo@thematrix:~$ mysql -u root -p <password>

Issue the GRANT command now to grant those permissions:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY 'n4aSHUP04s1J32X5';

Voila! If you restart MySQL, you’ll find that you should no longer be getting the “access denied” error message.

neo@thematrix:~$ sudo /etc/init.d/mysql restart
* Stopping MySQL database server mysqld [ OK ]
* Starting MySQL database server mysqld [ OK ]
* Checking for corrupt, not cleanly closed and upgrade needing tables.

Bear in mind, because we just switched the password, and the change hasn’t been affected yet, you may need to kill the MySQL server processes in order to get MySQL to shut down at all.

Possibly related posts: (automatically generated)

* MySQL create an Anonymous or limited access only account
* Connecting from windows to MYSQL on Ubuntu

Written by Sohail Mirza

January 16, 2009 at 6:51 pm

Posted in Development, Ubuntu

Tagged with debian, error, mysql, Ubuntu
« dpkg problems relating to ‘cups’ in Ubuntu
Riding Tokyo »
3 Responses

Subscribe to comments with RSS.

1.

Right tf on!

Oogliby

February 11, 2009 at 8:44 am
Reply
*

I see this is an older post, but just ran into this, myself. Reseting the debian-sys-maint password in mysql to match the debian.cnf file takes care of it – but do you know if there is a bug filed against this?

No other mysql passwords are reset during updates – so this seems odd to me.

Jere

October 16, 2009 at 11:47 am
Reply
o

In my research of the solution, I can’t say I did come across a bug filed for this issue.

Sohail Mirza

October 16, 2009 at 11:57 am


Leave a Reply
Click here to cancel reply.

Name (required)

E-mail (will not be published) (required)

Website

Notify me of follow-up comments via email.
Who am I?
Sohail Mirza is a software professional with a background in both design and development. He blogs about both, as well as other matters, real & virtual.
Search for:
Top Posts

* Helpful Hints - Apple Movie Trailers download using Firefox, Greasemonkey, and User Agent hack
* Star Trek beams onto Apple Movie Trailers
* Helpful Hints - Downloading HD Trailers from Apple Trailers
* MySQL: 'Access denied for user 'debian-sys-maint'@'localhost''
* Helpful Hints - Running multiple instances of Firefox

Browse a category
My del.icio.us

* BBC NEWS | Middle East | Israel 'cuts Palestinian water'
* Asia Sentinel - Pakistan's Persecuted Minority
* Michael Jordan's Top 23 Moments
* Why AI is a dangerous dream - opinion - 01 September 2009 - New Scientist
* Build an Insanely Great Web Service - ReadWriteStart
* BBC NEWS | Middle East | Gaza sewage 'a threat to Israel'
* Django Con High Performance Django
* PreciseJava.com - The path to improvement
* Django-Socialauth - GitHub
* Andy Kessler: Why AT&T Killed Google Voice - WSJ.com

Archives

Blog at WordPress.com. — Journalist theme by Lucian E. Marin"

sexta-feira, 16 de outubro de 2009

How to Install Freenx Server on Ubuntu 9.04 Jaunty: 9 steps - wikiHow

How to Install Freenx Server on Ubuntu 9.04 Jaunty: 9 steps - wikiHow: "Add FreeNX PPA

1. gksudo gedit /etc/apt/sources.list
2. deb http://ppa.launchpad.net/freenx-team/ppa/ubuntu jaunty main
3. deb-src http://ppa.launchpad.net/freenx-team/ppa/ubuntu jaunty main
4. sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 2a8e3034d018a4ce

Install FreeNX Server

1. sudo apt-get update
2. sudo apt-get install freenx
3. (y)

Configure FreeNX Server

1. sudo /usr/lib/nx/nxsetup --install
2. For server behind a firewall, default key may be okay, (n) for any public system or for greater security, Generate a custom Key Pair (y)


[edit] Tips

* A custom SSH key is recommended for publicly accessible servers


[edit] Things You'll Need

* Ubuntu 9.04 Jaunty
* Internet connection


[edit] Related wikiHows

* How to Update from Ubuntu Warty Warthog to Hoary Hedgehog
* How to Set up a Network in Ubuntu
* How to Burn a CD in Ubuntu Linux
* How to Install Beagle on Ubuntu"

quarta-feira, 7 de outubro de 2009

Restrições em parâmetros de tipo (Guia de programação C#)

Restrições em parâmetros de tipo (Guia de programação C#)

Constraints on Type Parameters (C# Programming Guide)

Updated: July 2008

When you define a generic class, you can apply restrictions to the kinds of types that client code can use for type arguments when it instantiates your class. If client code tries to instantiate your class by using a type that is not allowed by a constraint, the result is a compile-time error. These restrictions are called constraints. Constraints are specified by using the where contextual keyword. The following table lists the six types of constraints:

Constraint

Description

where T: struct

The type argument must be a value type. Any value type except Nullable can be specified. See Using Nullable Types (C# Programming Guide) for more information.

where T : class

The type argument must be a reference type; this applies also to any class, interface, delegate, or array type.

where T : new()

The type argument must have a public parameterless constructor. When used together with other constraints, the new() constraint must be specified last.

where T :

The type argument must be or derive from the specified base class.

where T :

The type argument must be or implement the specified interface. Multiple interface constraints can be specified. The constraining interface can also be generic.

where T : U

The type argument supplied for T must be or derive from the argument supplied for U. This is called a naked type constraint.

If you want to examine an item in a generic list to determine whether it is valid or to compare it to some other item, the compiler must have some guarantee that the operator or method it has to call will be supported by any type argument that might be specified by client code. This guarantee is obtained by applying one or more constraints to your generic class definition. For example, the base class constraint tells the compiler that only objects of this type or derived from this type will be used as type arguments. Once the compiler has this guarantee, it can allow methods of that type to be called in the generic class. Constraints are applied by using the contextual keyword where. The following code example demonstrates the functionality we can add to the GenericList class (in Introduction to Generics (C# Programming Guide)) by applying a base class constraint.

C#
public class Employee

{
private string name;
private int id;

public Employee(string s, int i)
{
name = s;
id = i;
}

public string Name
{
get { return name; }
set { name = value; }
}

public int ID
{
get { return id; }
set { id = value; }
}
}

public class GenericList where T : Employee
{
private class Node
{
private Node next;
private T data;

public Node(T t)
{
next = null;
data = t;
}

public Node Next
{
get { return next; }
set { next = value; }
}

public T Data
{
get { return data; }
set { data = value; }
}
}

private Node head;

public GenericList() //constructor
{
head = null;
}

public void AddHead(T t)
{
Node n = new Node(t);
n.Next = head;
head = n;
}

public IEnumerator GetEnumerator()
{
Node current = head;

while (current != null)
{
yield return current.Data;
current = current.Next;
}
}

public T FindFirstOccurrence(string s)
{
Node current = head;
T t = null;

while (current != null)
{
//The constraint enables access to the Name property.
if (current.Data.Name == s)
{
t = current.Data;
break;
}
else
{
current = current.Next;
}
}
return t;
}
}

The constraint enables the generic class to use the Employee.Name property because all items of type T are guaranteed to be either an Employee object or an object that inherits from Employee.

Multiple constraints can be applied to the same type parameter, and the constraints themselves can be generic types, as follows:

C#
class EmployeeList where T : Employee, IEmployee, System.IComparable, new()

{
// ...
}

By constraining the type parameter, you increase the number of allowable operations and method calls to those supported by the constraining type and all types in its inheritance hierarchy. Therefore, when you design generic classes or methods, if you will be performing any operation on the generic members beyond simple assignment or calling any methods not supported by System.Object, you will have to apply constraints to the type parameter.

When applying the where T : class constraint, avoid the == and != operators on the type parameter because these operators will test for reference identity only, not for value equality. This is the case even if these operators are overloaded in a type that is used as an argument. The following code illustrates this point; the output is false even though the String class overloads the == operator.

C#
public static void OpTest(T s, T t) where T : class

{
System.Console.WriteLine(s == t);
}
static void Main()
{
string s1 = "foo";
System.Text.StringBuilder sb = new System.Text.StringBuilder("foo");
string s2 = sb.ToString();
OpTest<string>(s1, s2);
}

The reason for this behavior is that, at compile time, the compiler only knows that T is a reference type, and therefore must use the default operators that are valid for all reference types. If you must test for value equality, the recommended way is to also apply the where T : IComparable constraint and implement that interface in any class that will be used to construct the generic class.

You can apply constraints to multiple parameters, and multiple constraints to a single parameter, as shown in the following example:

C#
class Base { }

class Test
where U : struct
where T : Base, new() { }

Type parameters that have no constraints, such as T in public class SampleClass{}, are called unbounded type parameters. Unbounded type parameters have the following rules:

  • The != and == operators cannot be used because there is no guarantee that the concrete type argument will support these operators.

  • They can be converted to and from System.Object or explicitly converted to any interface type.

  • You can compare to null. If an unbounded parameter is compared to null, the comparison will always return false if the type argument is a value type.

When a generic type parameter is used as a constraint, it is called a naked type constraint. Naked type constraints are useful when a member function with its own type parameter has to constrain that parameter to the type parameter of the containing type, as shown in the following example:

C#
class List

{
void Add(List items) where U : T {/*...*/}
}

In the previous example, T is a naked type constraint in the context of the Add method, and an unbounded type parameter in the context of the List class.

Naked type constraints can also be used in generic class definitions. Note that the naked type constraint must also have been declared within the angle brackets together with any other type parameters:

C#
//naked type constraint

public class SampleClass where T : V { }

The usefulness of naked type constraints with generic classes is very limited because the compiler can assume nothing about a naked type constraint except that it derives from System.Object. Use naked type constraints on generic classes in scenarios in which you want to enforce an inheritance relationship between two type parameters.

Date

History

Reason

July 2008

Added paragraph on multiple constraints.

Content bug fix.


CodeKeep Snippet : Reflection within a method call. (C#)

CodeKeep Snippet : Reflection within a method call. (C#)

Title: Reflection within a method call. Language: C#
Description: Calling assembly, current method name, current method's class. Views: 326
Author: digitalWraith .net Date Added: 5/9/2007
Copy Code
1string callingAssemblyName = System.Reflection.Assembly.GetCallingAssembly().FullName;
2string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
3string className = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString();
4
5

CodeProject: Logging method name in .NET. Free source code and programming help

CodeProject: Logging method name in .NET. Free source code and programming help

Introduction

Before .NET, we were always looking for a way to log current method name in a log file for better logging. But, there were no functionalities that could have helped in this, and it was left as an uncompleted job.

But, with .NET, we could easily find out the name of the current method or parent method. This has been accomplished by StackFrame, StackTrace, and MethodBase classes in System.Diagnostics and System.Reflection namespaces.

  • StackFrame provides information about function call on stack call for current process.
  • StackTrace is a collection of StackFrame.
  • MethodBase is an abstract class containing information about current method.

Note: When an exception occurs in the method, exception object contains a reference to the StackTrace object that could be used to log the method name. But for logging a method name without an error generated, we need to read it from the stack, using StackFrame class.

In the sample, MethodBase object would reference to current function on stack call returned by StackFrame object. To get the parent method, we would use StackTrace to get parent�s StackFrame object.

Create a new console application:

Add namespaces:

Collapse
using System.Diagnostics;
using System.Reflection;

Create a new static function named WhatsMyName and call it from the Main function.

Collapse
[STAThread]
static void Main(string[] args)
{
WhatsMyName();
}
// function to display its name

private static void WhatsMyName()
{
StackFrame stackFrame = new StackFrame();
MethodBase methodBase = stackFrame.GetMethod();
Console.WriteLine(methodBase.Name ); // Displays �WhatsmyName�

WhoCalledMe();
}
// Function to display parent function

private static void WhoCalledMe()
{
StackTrace stackTrace = new StackTrace();
StackFrame stackFrame = stackTrace.GetFrame(1);
MethodBase methodBase = stackFrame.GetMethod();
// Displays �WhatsmyName�

Console.WriteLine( " Parent Method Name {0} ", methodBase.Name );
}

Note: This feature is not available in .NET Compact Framework as StackFrame class is unavailable. For that, you would need to use same old method of manually passing method name to the logging function.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here