rah has asked for the wisdom of the Perl Monks concerning the following question:
Not sure this is a perl issue. It may just as easily be a Win32 or Samba problem. I have built a service using Win32::Daemon (more correctly using Win32::Daemon::Simple) The service functions correctly, in that it installs, starts, stops, uninstalls, etc. However, when it executes its call back, I have a sub that needs to access files in a remote directory. The service starts off in C:\WINNT\System32 after ctaaempting to chdir to the remote share, I'm still there. An "or die" in the code doesn't help - it may die during the callback, but the service re-execs at specified intervals. Unfortunately that means I'm also not getting much feedback. Could this be a perl problem? Is it a restriction on Win32 services? A Samba configuration issuue? Any ideas? Thanks.
Re: Can Win32::Daemon access remote shares?
by Jenda (Abbot) on Apr 13, 2003 at 18:43 UTC
|
As buk said, the problem is most likely in the premissions. If your service runs under the LocalSystem account it doesn't have acccess the WINDOWS networking. You have to run the service under some different account.
On "the re-execing": Win32::Daemon::Simple tries its best to prevent the service from crashing. It will write the error into the log file and try to continue. If you want to make more noise at this time you can either
- use your own custom Die() procedure that'll send a network message or an email and then stop the service
- wrap your code in an eval block, catch the exceptions, send the alert and stop the service.
Just a note. You should call
Win32::Daemon::StopService(); before you exit().
If you think it would be helpfull I can update Win32::Daemon::Simple to send a network message ("net send ...") to somewhere if your callback dies and optionaly to even stop the service. I'd say ... if the Params=> option of use Win32::Daemon::Simple contains MessageOnError=> it would send the network alert to the specified username/computer. And then another option StopOnError would control whether to "re-exec" or stop. Something like this:
use Win32::Daemon::Simple
Service => 'SERVICENAME',
Name => 'SERVICE NAME',
Version => 'x.x',
StopOnError => 1,
Info => {
...
},
Params => {
MsgOnError => Win32::NodeName(), # send to local console
Tick => 0,
Talkative => 0,
...
};
Does that look OK? If anyone has some other suggestions, send them to me. I might even implement them ;-)
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature | [reply] [d/l] [select] |
|
Failed to install: The account name is invalid or does not exist.
If you or anyone could suggest a way around that, I'd appreciate it. Even if you just send me off in search of some other resources. :> | [reply] [d/l] |
|
That's why it would be optional. The reason why I do not want the die to really die is that IMHO most often the reason of the die is something temporary. Something I forgot the check for and that will eventualy work again. Like for example that the remote computer/database is temporarily inaccessible, because it's being rebooted or something similar. Therefore I only want to write the error into the log file and try to continue.
Since I have scripts that process the log files each night, archive them and report any errors or unexpected messages, I do notice there was something uncaught at worst the next morning.
To get back to your problem, did you specify the domain of the user? Or if the account is local then you should use either "computername\user" or ".\user". I think the only computer where you would not have to specify the domain would be a domain controler (Erm ... I don't know how Active Directory works in regard to this. I'm talking about the good old NT domain controlers.)
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature
| [reply] [d/l] [select] |
|
|
|
Re: Can Win32::Daemon access remote shares?
by Corion (Patriarch) on Apr 13, 2003 at 18:08 UTC
|
If you're running as a service, you will face the problem that you can either run with system privileges, or access the network, but not both at the same time. AFAIK there are no nice ways around this, and in a certain sense, this is also what you want, security wise.
The thing is, I don't know of a solution for your problem, except either switching the user or having two services running as different users, which communicate through files or named pipes.
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The
$d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider
($c = $d->accept())->get_request(); $c->send_response( new #in the
HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
| [reply] [d/l] |
Re: Can Win32::Daemon access remote shares?
by AcidHawk (Vicar) on Apr 13, 2003 at 19:03 UTC
|
I have had some permission issues when trying to chdir to a \\SERVERNAME\SHARENAME before. Keep in mind the cmd.exe does NOT support UNC paths so you can try and map a network drive. I.e. net use \\servername\sharename /user:DOMAIN\username password
Something else to keep in mind is that in your script you may need to escape the \'s i.e. \\\\servername\\sharename, or alternately use /'s i.e. //servername/sharename You did however mention Samba, so I asume that you are trying to access files, FROM a Win32 system, ON a Linux/Unix system. Could you not FTP the files you need to your Win32 system.
-----
Of all the things I've lost in my life, its my mind I miss the most.
| [reply] [d/l] [select] |
Re: Can Win32::Daemon access remote shares?
by Anonymous Monk on Apr 13, 2003 at 16:27 UTC
|
Are you supplying the user & pass parameters to the CreateService() call? If not, the default userid is LocalSystem, which probably doesn't have permission to access the remote share.
buk
| [reply] |
Re: Can Win32::Daemon access remote shares?
by Limbic~Region (Chancellor) on Apr 13, 2003 at 15:02 UTC
|
rah,
It could be a lot of things, but without code it is hard to say. Have you tried to chdir to a local directory and verified that it works as you expect? Have you verified that the remote shares are accessible from within your program (perhaps by invoking net use)? There may be something obvious I am missing and I am sure another monk will correct me if I am, but code would be helpful.
Cheers - L~R | [reply] |
Re: Can Win32::Daemon access remote shares?
by rah (Monk) on Apr 15, 2003 at 02:22 UTC
|
Thanks to all good monks for their helpful suggestions, but especially to Jenda for responding quickly and helping me dig myself out of a hole - and on a Sunday afternoon/evening no less!In the end I had to recreate the user account with domain admin permissions. I also had to re-enter the password in the Service Setup Dialog (per MS!), despite not having changed it. I found some rather vague notes about this, on a number of web pages, including some MS help sites. Jenda - Win32::Daemon::Simple rocks! It makes Dave Roth's excellent Win32::Daemon a joy to work with. | [reply] |
|
|