Bug 7491 - fix startup parameter when SC is run as Windows service
: fix startup parameter when SC is run as Windows service
Status: RESOLVED FIXED
Product: Logitech Media Server
Classification: Unclassified
Component: Windows Service
: 7.4.0
: PC Windows XP
: P4 minor with 2 votes (vote)
: 7.9.x
Assigned To: Michael Herger
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-03-12 01:37 UTC by Michael Herger
Modified: 2015-02-27 12:50 UTC (History)
3 users (show)

See Also:
Category: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Herger 2008-03-12 01:37:24 UTC
Some of the startup parameter seem to be ignored when SC is run as a service on Windows.
Comment 1 Jim McAtee 2008-03-12 13:56:46 UTC
I recently installed the SqueezeCenter 7.0 release version on Windows XP Pro SP2 using the installer EXE.  Then I ran the service enabler to install the Windows service.

Editing the service's ImagePath entry in the registry to add the startup options, this is what I now have (it's also necessary to specify the server's IP address, since there are other SlimServers and SqueezeCenters running on the same machine):

"C:\Program Files\SqueezeCenter\server\squeezecenter.exe" --prefsdir D:\slim\dot2\prefs --cachedir D:\slim\dot2\cache --logdir D:\slim\dot2\logs --playeraddr 192.168.9.2 --cliaddr 192.168.9.2 --streamaddr 192.168.9.2 --httpaddr 192.168.9.2

My experience is that of the three directory options --prefsdir, --cachedir, and --logdir, only --logdir is recognized.
Comment 2 Michael Herger 2008-04-23 04:07:40 UTC
Jim - could you please try again with some recent build? I did a few changes to silence warnings which could have fixed this as a side effect. 
Comment 3 Jim McAtee 2008-04-23 04:24:14 UTC
Where will I find it?  Since this bug is targeted for 7.1, is the fix only in the 7.1 nightlies, or also in 7.0.1?  And will it be in the current 4/23 nightlies?  I can't use SVN since I need to test the Win EXE.
Comment 4 Michael Herger 2008-04-23 04:30:28 UTC
It would be in 7.0.1 (bug 5833)
Comment 5 Michael Herger 2008-05-06 05:50:58 UTC
Jim - any news?
Comment 6 sc 2008-05-07 14:39:50 UTC
Hi Michael, 

Ok  I have tried using the startup line:

"C:\Program Files\SqueezeCenter\server\squeezecenter.exe" ---prefsdir D:\Server Data\Squeeze\Center\prefs --cachedir D:\Server Data\SqueezeCenter\cache --logdir D:\Server Data\SqueezeCenter\logs" 

under the "imagepath" in the currentcontrol set for the squeezebox service on version "SqueezeCenter Version: 7.0.1 - 19522 @ Wed May 7 06:16:01 PDT 2008 - Windows Server 2003 - EN - cp1252" and I am sorry to say that it still does not appear to work. It appears that know of "relocations" work for me.  Also tried 7.1 from a couple of nights back and that also did not work.

Any ideas?
Comment 7 Jim McAtee 2008-05-07 14:52:45 UTC
(In reply to comment #6)
> Any ideas?

Make sure you enclose any command line arguments containing spaces in double quotes.  I think I'd try:

"C:\Program Files\SqueezeCenter\server\squeezecenter.exe" ---prefsdir "D:\Server
Data\Squeeze\Center\prefs" --cachedir "D:\Server Data\SqueezeCenter\cache"
--logdir D:\Server Data\SqueezeCenter\logs" 

I purposely avoided spaces in the directory names for the relocated cache, prefs and log directories, as I've always had some problems with these command line arguments and sought to eliminate one possible hangup.
Comment 8 Jim McAtee 2008-05-07 15:41:33 UTC
(In reply to comment #5)
> Jim - any news?

I just tried the May 7 nightly of 7.0.1, installed using the Window installer.  It looks like --logdir and --cachedir are now recognized, but still not --prefsdir.

Any way to get some debugging information for command line options?  What was read, what options were set, etc...  If when these things are parsed it's too early to write the info to the log (maybe the log file hasn't been initiated yet) then could the logging info be held in a string variable and then written out once the log is opened for writing?
Comment 9 Michael Herger 2008-05-07 21:55:50 UTC
> I just tried the May 7 nightly of 7.0.1, installed using the Window installer. 
> It looks like --logdir and --cachedir are now recognized, but still not
> --prefsdir.

Thanks for testing. I'll have to do some more analysis. Just hoped the issue had vanished by some other change.
Comment 10 Michael Herger 2008-05-27 08:28:27 UTC
Ok, I've run a few more tests. 

Contrary to what you said in comment #7 I think _all_ options but prefsdir are read correctly. This value is read in Slim::Utils::Prefs, _before_ the others are read. But it seems that if SC is run as a service, it has different entry points. And @ARGV isn't available yet under this condition.

I have contacted ActiveState support. We'll see what they have to say about this behaviour.
Comment 11 sc 2008-05-27 09:02:20 UTC
Thanks for looking at this issue still .... let me know when you need some more testing done.
Comment 12 Jim McAtee 2008-05-27 13:12:16 UTC
(In reply to comment #10)
> Contrary to what you said in comment #7 I think _all_ options but prefsdir are
> read correctly.

I thought that was what I said in comment #8. :-)

Some more data, if it's worth anything: I'm seeing something again with SC 7.2, although I'm not running the EXE.  I've run SlimServer/SqueezeCenter in three different ways:

1. Running the Perl code as a Windows service using srvany.exe.
2. Running the Perl code from the command line console.
3. Running the bundled EXE as a Windows service.

And at any given time, any one of them may not work with respect to picking up all the command line options.  It may be only the prefsdir/file option, but I believe I've also had problems with the other directory options in the past.

SlimServer 6.5.x, which I still run using the method 1 above, fails to read the prefsfile option.  Both 7.0.x and 7.1 seem to be OK, but 7.2 also doesn't see the prefsdir option when run using method 1.
Comment 13 Michael Herger 2008-06-11 09:07:51 UTC
Ok, ActiveState confirm the issue. Will take a look at the workaround later this week:

------------------------------
 
It is correct that the stored commandline parameters are not set up until
the Startup() function is being called.  This is due to the fact that the
Service Control Manager is not passing in those arguments (He means that this
is a limitation of Service Control Manager -GS), and we have to
extract them ourselves, which is only done directly before we call the
Startup() callback.
 
I guess we could change PerlSvc so that @ARGV is set up earlier, but that
will need a new release.
 
A workaround for dealing with this right now would be to load the additional
modules from inside the Startup() callback using require():
 
sub Startup {
main::require_all();
main::initOptions();
main::init();
 
# here's where your startup code will go
while (ContinueRun() && !main::idle()) { }
 
main::stopServer();
}
 
sub Interactive {
main::require_all();
main::not_a_service();
}
 
package main;
 
my $prefs;
 
sub require_all {
    doALotOfInitialization();
    require Slim::Utils::Prefs;
    require Slim::Many::MoreModules;
    $prefs = Slim::Utils::Prefs::preferences();
}
 
 
sub init {}
 
sub initOptions {
Getopt::Long::GetOptions();
}
 
sub not_a_service {
# running interactively
}
 
------------------------------
Comment 14 Michael Herger 2008-06-18 02:57:32 UTC
I'm sorry, punting once again... this needs major changes in the main startup code.
Comment 15 Jim McAtee 2008-06-18 09:48:10 UTC
Just one question:  Why does the behavior change?  Almost randomly with any given revision.  Sometimes is works, sometimes it doesn't.  Something is happening within SC, independant of limitations within ActivState's Perl.
Comment 16 Michael Herger 2008-06-18 10:03:42 UTC
The behaviour doesn't change, or didn't in a while. It depends on the Perl Development Kit and how it's handling parameters. While we've upgraded from PDK 7.0 (used up to SC7.0.1) to PDK 7.2 (SC7.1+) I didn't see a change in behaviour.
Comment 17 Jim McAtee 2008-06-18 10:15:53 UTC
The SC EXE may be fairly consistent (I've seldom run the EXE) in never picking up the --prefsfile option.

The Perl code, when run as a service, is inconsistent.  My experience:

6.5 broken
7.0 ok
7.1 ok
7.2 broken

I realize that running the Perl code as a service may be unsupported.  But if the behavior is changing like this, it would seem to indicate something going on within SC.

My server is down right now.  When it's back up I'll double-check whether the list above is completely accurate.
Comment 18 Michael Herger 2008-06-18 11:35:36 UTC
> The Perl code, when run as a service, is inconsistent.  My experience:
> 
> 6.5 broken
> 7.0 ok
> 7.1 ok
> 7.2 broken

Jim - please get me some facts here. Just saying it's broken won't tell us in which way it is. I'd be surprised if 7.2 was, as there are basically no changes to the general code compared to 7.1.
Comment 19 Michael Herger 2008-07-24 04:00:06 UTC
I'm sorry, need to prioritize...
Comment 20 Michael Herger 2008-08-11 08:21:40 UTC
Waiting for new ActiveState PDK
Comment 21 Michael Herger 2008-11-06 08:49:34 UTC
New PDK has arrived. Let's give it another try.
Comment 22 Michael Herger 2009-01-14 05:49:00 UTC
Is this still an issue? Six months and no feedback have me doubt it.
Comment 23 Jim McAtee 2009-01-14 12:58:34 UTC
(In reply to comment #22)
> Is this still an issue? Six months and no feedback have me doubt it.
> 

It's only an issue with the EXE, correct?  The Perl code via ActivePerl works fine.  I don't run the EXE except for occasional testing, but it only takes a few minutes to install it and see if it's still broken.  I'll do so tonight or tomorrow.
Comment 24 Michael Herger 2009-01-22 05:48:35 UTC
We'll have to test this whenever a new PDK is available.
Comment 25 Jim McAtee 2009-07-11 21:39:33 UTC
FYI, with the 2009-04-11 r27509 build of 7.4, the --prefsdir option is still unrecognized when run as a Windows service.

Isn't someone working on changes to the startup code to permit running up without a database?  Maybe it would be a good opportunity to fix this bug.
Comment 26 Michael Herger 2009-09-23 04:04:11 UTC
Jim - now at PDK 8.0.1 are you still seeing this issue?
Comment 27 Jim McAtee 2009-09-23 06:44:39 UTC
Version: 7.4.0 - r28607 @ Wed Sep 23 06:01:56 PDT 2009, still ignoring --prefsdir.
Comment 28 Jim McAtee 2011-11-08 17:54:59 UTC
Update on latest release: Logitech Media Server Version: 7.7.0 - r33614 @ Tue Oct 18 11:17:52 PDT 2011. Still doesn't see --prefsdir option.
Comment 29 Michael Herger 2015-02-27 12:50:03 UTC
Try to work around PerlSvc issue causing @ARGV to be empty. Read the parameters from Windows' registry instead.