Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add systemstart task scripts to installer repo, fix bug #322

Merged
merged 7 commits into from
Jan 5, 2016

Conversation

MCGallaspy
Copy link
Contributor

Fixes #106 -- should start at boot now.
These scripts are updated, and should be removed from the ka-lite repo... they do no good there!

commitmsg

Copy them, and instead of referencing the now defunct bin/windows/kalite.bat
script, use the included kalite.bat script in the ..\Python27\Scripts\ dir.

Copy them, and instead of referencing the now defunct bin/windows/kalite.bat
script, use the included kalite.bat script in the ..\Python27\Scripts\ dir.
@MCGallaspy MCGallaspy added the bug label Dec 18, 2015
@MCGallaspy MCGallaspy added this to the 0.16.0 milestone Dec 18, 2015
@MCGallaspy
Copy link
Contributor Author

Check out this build to test it out!

@MCGallaspy
Copy link
Contributor Author

@radinamatic let's give it a shot

@radinamatic
Copy link
Member

Gottit! Downloading...

@radinamatic
Copy link
Member

No luck, @MCGallaspy, at least on Windows 8:

  • I still get "Failed to create config file/option" alerts
  • Scheduled task is created correctly, and at least according to system, it is executed correctly too, but KA Lite does not run at startup.

ie11 - win8 1 py 3 5 1 first running - oracle vm virtualbox_114

@radinamatic
Copy link
Member

Windows XP:

  • No "Failed to create config file/option" alerts
  • Scheduled task is created correctly, but KA Lite does not run at startup.

wxp

@radinamatic
Copy link
Member

However, if I activate all three options and restart the machine, both KA Lite and server are started! :)

@MCGallaspy
Copy link
Contributor Author

I still get "Failed to create config file/option" alerts

That's expected -- this only addresses the "start at boot" option

@radinamatic
Copy link
Member

Windows 7 yields the same as result as 8: Scheduled task is created correctly, but KA Lite does not run at startup.

Under "Last Run results" it has (0x1) - not sure if that counts as "success", as it's different from tasks above it.

General
ie9 - win7 pre ka lite running - oracle vm virtualbox_115

Triggers
selection_116

Actions
selection_117

Conditions
selection_118

Settings
selection_119

@radinamatic
Copy link
Member

However, as noted before for XP, if I activate the "Run KA Lite when the user logs in" and restart, that task gives us the desired result (KA Lite is run at startup). Could this be a user problem?

@MCGallaspy
Copy link
Contributor Author

if I activate the "Run KA Lite when the user logs in" and restart, that task gives us the desired result (KA Lite is run at startup).

Does it truly run when the system starts? Or just when that user logs in? I'm specifically trying to debug the "at system start" option. If the "when user logs in" options works ok, try logging in as a different user and seeing if it starts -- I do not expect it to.

@radinamatic
Copy link
Member

You are probably right, I'll create another user (this one came with VM image by default), and check that out.

@MCGallaspy
Copy link
Contributor Author

I'm attempting to install & replicate, but in the meantime it could be informative to run the script which the scheduled task is configured to run, to see if there is any error output.

@radinamatic
Copy link
Member

Running (double clicking) kalite.bat opens and immediately closes the command prompt window, so to be able to see the output, I made a copy of the .bat file, edited it in Notepad adding @pause at the end and run it again. This is a output:

selection_120

@MCGallaspy
Copy link
Contributor Author

yeah, kalite.bat is meant to be run from the command line

@MCGallaspy
Copy link
Contributor Author

Believe I know why, @radinamatic if you can confirm. During installation, we create the scheduled task using the script from this PR, which relies on expanding the variable %KALITE_SCRIPT_DIR%. But that variable is not expanded because the environment will not be updated until the setup exe exits. The result is a misconfigured scheduled task:

virtualbox_ie9 - win7_18_12_2015_14_04_20

Note that the full path to the script is missing. Radina, can you confirm that post-installation, having checked the "start at system startup" option, that the scheduled task is misconfigured the same way it is here?

Don't use the external script, which relies on the expansion of
KALITE_SCRIPT_DIR -- the env won't be updated until *after* the
installer exits, so the scheduled task will be misconfigured.

In the installer, create the task from the cmd line and fetch
KALITE_SCRIPT_DIR directly from the registry.
@radinamatic
Copy link
Member

My above "Actions" screenshot from W7 seems identical @MCGallaspy.
I restarted the W8 VM and this is what's inside the KA Lite task:

ie11 - win8 1 py 3 5 1 first running - oracle vm virtualbox_121

I'm gonna revert and do another fresh install, just in case I meddled with the above one.

@radinamatic
Copy link
Member

After fresh install on W8, it seems the same as in your example @MCGallaspy:

ie11 - win8 1 pre ka lite running - oracle vm virtualbox_124

@MCGallaspy
Copy link
Contributor Author

Yeah, I see. I just submitted a patch, should be the latest build on bamboo. Let's try installing that one "fresh".

@radinamatic
Copy link
Member

Ok, tomorrow I'll be testing build # 90 on all the machines, and report back! @MCGallaspy

Removes invalid option on removal, and suppresses prompt on add.
@MCGallaspy
Copy link
Contributor Author

TODO: once this is merged, I need to modify the repos used on the build server.

@MCGallaspy
Copy link
Contributor Author

Looking more closely at your screenshots, there's some bizarre options for the tasks (like only running when on AC power). Seems to be the default, however... Will address those here as well.

@radinamatic
Copy link
Member

Win XP tested today with build #91, still no luck with start on boot... :(

xp-build91

@@ -444,7 +444,7 @@ begin

if StartupPage.SelectedValueIndex = 0 then
begin
if ShellExec('open','guitools.vbs','4', ExpandConstant('{app}'), SW_HIDE, ewWaitUntilTerminated, StartupCode) then
if Exec(ExpandConstant('{cmd}'), '/C "schtasks /create /tn "KALite" /tr "\"{reg:HKLM\System\CurrentControlSet\Control\Session Manager\Environment,KALITE_SCRIPT_DIR}\kalite.bat\" start" /sc onstart /ru SYSTEM"', '', SW_HIDE, ewWaitUntilTerminated, StartupCode) then

This comment was marked as spam.

This comment was marked as spam.

@radinamatic
Copy link
Member

Regarding XP, though, seems that it's the only one that fills in the "Start in:" option of the "Actions" tab by default, from the script that you have in the installer, while Windows 7 & 8 have only the "Program/Script" option after the installation. So, a part from figuring out why that reg:HKLM fails to grab the value of KALITE_SCRIPT_DIR env var (and I did check, it is in the registry), try forcing the "Start in:" option, because it is mentioned on several places that I checked as a potential cause of scheduled task fail.

@MCGallaspy
Copy link
Contributor Author

Looks like you've been busy, so I'm addressing comment by comment:

Re: #322 (comment)

The values enclosed in { & } should be expanded by IS -- but it seems they weren't. I'll double check. After installation finishes, what is the value of that registry key? You can check using regedit, and the path is given, i.e. the root key is HKLM, then System, etc, and you can follow it until you get to Environment.

@radinamatic
Copy link
Member

If I recall well, the value of the registry key was the (correct) Python scripts path on that machine.

I'll fire up the VM and recheck.

@MCGallaspy
Copy link
Contributor Author

I read up, looks like the registry value is set properly -- is it substituted correctly in the scheduled task on other version of Windows? In other words, does it fail to substitute only on XP?

You also mentioned that you added C:\Python27\Scripts to your PATH, and the scheduled task ran properly -- did you edit the scheduled task prior to changing the PATH value? In other words, there are four cases. Can you fill in the values in the table below?

bad schtask good schtask
Scripts dir in PATH ? ? .
Scripts dir not in PATH Does not work ?

Edit: By "bad schtask" I mean that the values in curly braces will not be substituted by Windows -- that's an error. They should be substituted by IS when the schtask is created during installation.

Edit edit: Substitution syntax for IS

@radinamatic
Copy link
Member

Yes, registry value is set correctly on all versions (XP, 7, 8), and No, it's not substituted correctly in scheduled task, so Yes, task fails on all the versions.

I did not edit/add Python to the path, installer does that correctly, I just edited the task itself, substituting the unexpanded {...} in the task with C:\Python27\Scripts.

ie9 - win7 ready pinned tasks running - oracle vm virtualbox_131

It might be in one of the links that I posted above, but there might have been a suggestion somewhere that in order for it to expand correctly, you must set the reg value type REG_EXPAND_SZ instead of REG_SZ.

@radinamatic
Copy link
Member

Addendum to the above comment: C:\Python27\Scripts is added to the PATH IF the user ticks the appropriate checkbox during the installation. If they do not, or Python 2 is the sole one installed, it's not the problem, as it is taken by default. This only becomes a problem when there is a Python 3 in the mix too, and its path is added (see #296).

@MCGallaspy
Copy link
Contributor Author

Okay, this latest commit should expand the constant if you picked the "Start at boot" option initially. We can test it out from this build: http://dungeon.learningequality.org:8085/browse/KL-KALITE016-WIN-93

@radinamatic
Copy link
Member

Good news @MCGallaspy, so far it seems to be working on Windows 7, raising the Python process correctly upon restart... :)

I'll test on rest of the versions and report back!

@radinamatic
Copy link
Member

We are not out of the woods just yet... :(

Build # 93 Worked flawlessly on Windows 7 & 8, but not on XP. Scheduled task seems OK (C:\Python27\Scripts is expanded correctly), but Python process is not raised, and server never starts. kalite.bat works when run from Terminal.

ie8 - winxp ready for ka lite running - oracle vm virtualbox_132

I've been at this for a while, can't figure out why. If you have any ideas, yell!

@MCGallaspy
Copy link
Contributor Author

It may be the user that the scheduled task is run as (SYSTEM) -- if it works when you run as yourself, can you try opening a cmd.exe prompt as SYSTEM (this option should be available from the "Run as..." context menu when you right click) then running kalite.bat to see what happens?

Edit: It might be helpful to check the scheduled tasks log. You can find instructions for viewing it on XP here: https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/agent_view_log.mspx?mfr=true

@MCGallaspy
Copy link
Contributor Author

Yeah, after experimenting with it I think the solution is to run the scheduled task as a different user on XP only -- looking in to it.

@radinamatic
Copy link
Member

If I try to open cmd.exe prompt from the "Run as...", I don't get to choose SYSTEM, it's not available as an option. There is only "Administrator" user alongside the default VM user, and if I choose it, it demands a password that I'm unaware of (VM only offers password for the default user).

ie8 - winxp ready for ka lite running - oracle vm virtualbox_135

Scheduled tasks log shows the following:

"KALite.job" (kalite.bat)
    Finished 12/30/2015 8:29:37 AM
    Result: The task completed with an exit code of (1).

1 or 0x1 exit code implies incorrect or unknown function called, if I recall well. Could it be the that the argument start is not passed correctly? In XP it does not have a separate field in the task properties window as for 7 or 8.

@MCGallaspy
Copy link
Contributor Author

I'm not sure what the error code precisely means without looking at the output of the script, which I'm not really sure how to do. However, I found that when the task is run as a different user (not SYSTEM) then it works without error.

@radinamatic
Copy link
Member

True, if I change the scheduled task (or make a new one) with Run as: set for the default VM user, task is executed correctly, python process is raised and server starts on boot no prob...

So does that mean that for XP we'll have to configure the installer to run kalite.bat task set for the logged-in user?

@MCGallaspy
Copy link
Contributor Author

@radinamatic okay, this should start the task in Windows XP. For XP only, the scheduled task is set to run as the installing user -- in this case it should be the admin, since the installer is run with elevated privileges. I'm afraid this might make upgrading on XP a little tricky, since it may mean moving files from one location to another. But for later versions of Windows, this should introduce no change. If this works well for a regular install, then I'll merge this and we can begin testing upgrade scenarios, with an emphasis on XP.

@radinamatic
Copy link
Member

Ok, waiting on build # 94 to test this @MCGallaspy.

@radinamatic
Copy link
Member

Build # 94 seems to be problematic only on XP, on Windows 7 installer finishes correctly, and starts the server Ok on restart.

@MCGallaspy
Copy link
Contributor Author

Yeah, on XP it prompts the user for a password.

@MCGallaspy
Copy link
Contributor Author

I'm disabling the start at boot option from the task tray program on XP. Shortly I'll remove the option from the installer.

@MCGallaspy
Copy link
Contributor Author

@radinamatic I'm merging this so we can start working on #321.

MCGallaspy added a commit that referenced this pull request Jan 5, 2016
Add systemstart task scripts to installer repo, fix bug
@MCGallaspy MCGallaspy merged commit abdad1e into learningequality:develop Jan 5, 2016
@MCGallaspy MCGallaspy removed the has PR label Jan 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants