running deluged as another user (and service)

Specific support for Deluge on Microsoft Windows OS
Post Reply
mindthemonkey
New User
New User
Posts: 6
Joined: Mon Jan 31, 2011 11:02 am

running deluged as another user (and service)

Post by mindthemonkey »

hello.

i'm trying to setup deluged on a windows 2003 server to run as the user "deluged" via the srvany tool included in the windows resource kit.

The following error occurs when running as a service

[ERROR ] 21:59:59 __init__:1080 object of type 'NoneType' has no len()
Traceback (most recent call last):
File "deluge\main.py", line 214, in start_daemon
File "deluge\core\daemon.py", line 52, in __init__
File "deluge\configmanager.py", line 130, in get_config_dir
File "deluge\configmanager.py", line 93, in get_config_dir
File "deluge\configmanager.py", line 51, in config_directory
File "deluge\common.py", line 151, in get_default_config_dir
File "ntpath.py", line 96, in join
TypeError: object of type 'NoneType' has no len()

The same error occurs when trying to run deluged while logged in as another user via runas

so i think it's just not able to run as a user other than that currently logged in.
The application runs fine when logged in to the computer as my "deluged" user.

Has anyone been able to run it as another user? or a service?

[ http://dev.deluge-torrent.org/ticket/1504 ]
Last edited by Cas on Thu Feb 03, 2011 5:42 pm, edited 1 time in total.
Reason: Added ticket link
mindthemonkey
New User
New User
Posts: 6
Joined: Mon Jan 31, 2011 11:02 am

Re: running deluged as another user (and service)

Post by mindthemonkey »

It looks like the APPDATA environment variable is not available when the process is launched via runas or via the service which i assume uses the same windows functionality.

same issue discussed for another language here: http://groups.google.com/group/microsof ... a197?fwc=1

i can't submit it as a bug as im getting an error registering for the trac site as well...

"Trac detected an internal error:
RuntimeError: input() already active"

!
mindthemonkey
New User
New User
Posts: 6
Joined: Mon Jan 31, 2011 11:02 am

Re: running deluged as another user (and service)

Post by mindthemonkey »

sorry for my internal dialogue here...

going by that google groups page, the directory name could be pulled, if os.environ.get("APPDATA") is undefined with something like:

Code: Select all

appdatapath = _winreg.QueryValueEx(hkey, "AppData")
hkey = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders")
appdatapath = _winreg.QueryValueEx(hkey, "AppData")
_winreg.CloseKey(hkey)
Cas
Top Bloke
Top Bloke
Posts: 3681
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: running deluged as another user (and service)

Post by Cas »

I am trying to test and fix this but since I don't use windows anymore I am struggling with the details of how to replicate.

What args do you pass to instsrv to install the service?

Where do you see the error, are there logs?
Cas
Top Bloke
Top Bloke
Posts: 3681
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: running deluged as another user (and service)

Post by Cas »

I have put those changes for you into the code but I cannot test it, so I'm putting it here for you to test.

Three files in the archive, one is the patch just show what has changed.

The other is common.py with those changes applied. This file can be simply copied into C:\Program Files\Deluge\deluge-1.3.1-py2.6.egg\deluge\ and will be used by Deluge next time it is run.

The final file is the original common.py and if the above changes don't work or cause problems simply rename it to common.py and use it to replace the above file.
Attachments
testFix_1504.7z
(10.49 KiB) Downloaded 462 times
mindthemonkey
New User
New User
Posts: 6
Joined: Mon Jan 31, 2011 11:02 am

Re: running deluged as another user (and service)

Post by mindthemonkey »

sorry i didn't realise it was that easy to modify the running code here otherwise i would have put together a full patch.

thanks for that, although deluge was producing an error as the returned appDataPath object didn't have a .len:

[ERROR ] 15:45:52 __init__:1080 object of type 'NoneType' has no len()
Traceback (most recent call last):
File "deluge\main.py", line 214, in start_daemon
File "deluge\core\daemon.py", line 52, in __init__
File "deluge\configmanager.py", line 130, in get_config_dir
File "deluge\configmanager.py", line 93, in get_config_dir
File "deluge\configmanager.py", line 51, in config_directory
File "c:\programs\net\deluge-1.3.1\deluge-1.3.1-py2.6.egg\deluge\common.py", line 151, in get_default_config_dir
if len(appDataPath) == 0:
TypeError: object of type 'NoneType' has no len()


I have the attached common.py I have running now.
One more change was the value returned by _winreg.QueryValueEx was a tuple so had to access just the string portion of it.
Attachments
testfix2_1504.7z
patched common.py running as another user
(5 KiB) Downloaded 658 times
Last edited by mindthemonkey on Sat Mar 05, 2011 5:56 am, edited 1 time in total.
mindthemonkey
New User
New User
Posts: 6
Joined: Mon Jan 31, 2011 11:02 am

Re: running deluged as another user (and service)

Post by mindthemonkey »

For the service setup, you need the Windows Resource Kit tools instsrv.exe and srvany.exe

Install a new service called "deluged" on the command line with:

Code: Select all

"C:\Program Files\Windows Resource Kits\Tools\instsrv.exe" deluged "C:\Program Files\Windows Resource Kits\Tools\srvany.exe"
Run regedit, Create a new key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\deluged\Parameters\Application
with a string (REG_SZ) value of the deluged command you want to run:
C:\programs\net\deluge-1.3.1\deluged.exe -L debug -l C:\programs\net\deluge-1.3.1\deluged.log

Code: Select all

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\deluged\Parameters]
"Application"="C:\\programs\\net\\deluge-1.3.1\\deluged.exe -L debug -l C:\\programs\\net\\deluge-1.3.1\\deluged.log"

I'm running the service with a specific user called "deluged" created in local user manager with a password that never expires. If you do this remember that settings/user config will be stored in the deluged users profile C:\Documents and Settings\deluged\Application Data\deluge
b1u3m3th

Re: running deluged as another user (and service)

Post by b1u3m3th »

mindthemonkey wrote:For the service setup, you need the Windows Resource Kit tools instsrv.exe and srvany.exe

Install a new service called "deluged" on the command line with:

Code: Select all

"C:\Program Files\Windows Resource Kits\Tools\instsrv.exe" deluged "C:\Program Files\Windows Resource Kits\Tools\srvany.exe"
Run regedit, Create a new key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\deluged\Parameters\Application
with a string (REG_SZ) value of the deluged command you want to run:
C:\programs\net\deluge-1.3.1\deluged.exe -L debug -l C:\programs\net\deluge-1.3.1\deluged.log

Code: Select all

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\deluged\Parameters]
"Application"="C:\\programs\\net\\deluge-1.3.1\\deluged.exe -L debug -l C:\\programs\\net\\deluge-1.3.1\\deluged.log"

I'm running the service with a specific user called "deluged" created in local user manager with a password that never expires. If you do this remember that settings/user config will be stored in the deluged users profile C:\Documents and Settings\deluged\Application Data\deluge
I am running Windows Server 2008 SP2 and Deluge 1.3.1

I followed the steps above and had everything working last night.

However, my server apparently rebooted last night and I can no longer get the service to start.

I get the following in the Event Viewer every time I try to start it:

Log Name: System
Source: Service Control Manager
Date: 3/25/2011 10:31:36 AM
Event ID: 7000
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: home-server
Description:
The Deluge service failed to start due to the following error:
Deluge is not a valid Win32 application.
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Service Control Manager" Guid="{555908D1-A6D7-4695-8E1E-26931D2012F4}" EventSourceName="Service Control Manager" />
<EventID Qualifiers="49152">7000</EventID>
<Version>0</Version>
<Level>2</Level>
<Task>0</Task>
<Opcode>0</Opcode>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2011-03-25T15:31:36.000Z" />
<EventRecordID>33558</EventRecordID>
<Correlation />
<Execution ProcessID="0" ThreadID="0" />
<Channel>System</Channel>
<Computer>home-server.bryantfamily.ws</Computer>
<Security />
</System>
<EventData>
<Data Name="param1">Deluge</Data>
<Data Name="param2">%%193</Data>
</EventData>
</Event>

I have confirmed I can start the daemon just fine from the executable, via CLI or Explorer, but the service no longer wants to start. I can not restart the server at the moment, but I will as soon as I can to see if that fixes it.

I have also tried creating other services for deluge to see if something was wrong with that service, and it does not work.

Thanks for any help.
Post Reply