This method may be a bit easier, and its already built into Windows 7+ (and maybe Vista... don't have a box to check all the details on).
Before you do anything else, you want to get a working CPS install (try following Joel's setup guide linked above). Make sure everything is working 100% with an interactive install before moving on to the below.
Once you have it working, be sure you REBOOT your windows box before moving onto the steps below. There are some strange things that can happen with GIT and reported version numbers with this method if you don't reboot after install.
Installing CouchPotatoServer as a Scheduled Task (psuedo-service)
First thing I like to do is relocate the CP data. By default this gets stored under your user profile (%appdata%). So, if you are user JSmith it would be here (on Vista+):
If you want to run as a service it generally isn't a good idea to have your data associated with any particular user. So, to move the data we need to do the following:
1) Create a directory to house the CouchPotato configuration data
Windows already provides a "standard" directory for non user-specific application data:
On Vista/Win7 this is: c:\ProgramData
So, on my Windows 7 system I would create the following:
2) Update CP with the new config file location
Go into CP and go to Settings > About. You will see a section that shows something similar to the following
Code: Select all
Namespace(config_file='C:\\Users\\jsmith\\AppData\\Roaming\\CouchPotato\\settings.conf', console_log=False, daemon=False, data_dir='C:\\Users\\jsmith\\AppData\\Roaming\\CouchPotato', debug=False, pid_file='C:\\Users\\jsmith\\AppData\\Roaming\\CouchPotato\\couchpotato.pid', quiet=False)
You can see above that it is loading the settings.conf file from your user's application directory. We want to change this to the new location we have created. To do this:
- Click on the "Show Advanced Settings" box on the top right and then on the "General" settings.
- Under the "Advanced" section you will see a "Data Dir" option.
- Navigate to the new directory you created and click on Save. You will most likely have to check the "Hidden Folders" option in order to see the ProgramData directory.
Once you have saved the settings, go ahead and SHUT DOWN CouchPotato by using either the shutdown option in the settings menu, or (less preferable) by killing the python process.
3) Copy the configuration data
Copy the entire contents of the old %appdata% directory to the new location. The data contents you are copying will be your settings.conf file as well as a few subdirectories (cache, db_backup,logs) and your couchpotato.db If there is any data in your new directory, you should overwrite it with the copied data.
I recommend using a COPY instead of a move so that the new location contents will inherit the permissions of the parent folder - this should cut down on some possible permissions issues. Once you have copied all the data you should have a directory structure similar to the following:
as well as your settings.conf and couchpotato.db in the root.
Once that is copied over you can optionally go ahead delete the original C:\Users\xxxxx\AppData\Roaming\CouchPotato directory.
4) Restart CP - Now that all our configuration information is moved out of the user's appdata and into a common folder, we need to tell CP to startup with the new config file. This is done with some special switches for the python file.
Start CP with the following:
CouchPotato.py --data_dir "path to your data directory" --config_file "path to your settings.conf" --pid_file "pid path"
--data_dir "c:\ProgramData\CouchPotato" --config_file "c:\ProgramData\CouchPotato\settings.conf" --pid_file "c:\ProgramData\CouchPotato\couchpotato.pid"
Once CP launches you can go into the Settings menu and look at the Startup Args again and it should be reflective of your new location.
5) Prevent CP from opening a browser - Since we are going to run as a service, you don't want a hidden browser window popping up. So, simply record the URL to access CP then go to Settings > General > Basic and uncheck the Launch Browser button.
If things aren't working at this point - STOP. Go back and re-read and try again. If you can't get CP running properly from an interactive prompt, we don't want to try and run it all hidden in the background as a service!
Now that all that is done, we can go ahead and actually configure CP to startup like a service. Technically, we won't be configuring it as a service, but as a scheduled task, to run on system startup
To create a startup task, open the Windows Task Scheduler (built into Windows...under Administrative Tools or Control Panel)
Inside the Task Scheduler do the following:
- Right-click on Task Scheduler Library
- Choose New Folder - give it a name of your choosing
- Right-click on new folder and choose Create Task (not basic!)
- On the GENERAL tab, give a name and description like "CouchPotato". Click on the "Change User or Group" and type in "SYSTEM" and click OK.*
- On the TRIGGERS tab, click New and then choose to begin the task "At Startup". Click OK.
- On the ACTIONS tab, click New and then choose "Start a Program". In the Program/Script, browse to and select your CouchPotatoServer.py file. In the Add Arguments field enter in --data_dir "c:\ProgramData\CouchPotato" --config_file "c:\ProgramData\CouchPotato\settings.conf" --pid_file "c:\ProgramData\CouchPotato\couchpotato.pid" as we did in step #4 above. Click OK.
- On the CONDITIONS tab uncheck everything you can
- On the SETTINGS tab check ONLY "Allow task to run on demand" and then from the drop down on the bottom select "Stop the Existing Instance".
- Click OK to create the task
Now, find your newly created task in the folder you created in Task Scheduler. Right-click and select "Run". If you followed the instructions properly then it should run the python script as the system account in the background and within a few seconds you should be able to go to your CP URL and access your server. Next time you boot up your computer this task should automatically run even before login!
If you have any problems look at the "Last Run Result" column in Task Scheduler to see what errors are there. Review the steps posted here to be sure you have typed everything properly. You can also check out MS references on the Task Scheduler here and here.
Other things to check:
- That the python.exe process is running when you start the task.
- That you can run it via the command line (interactively) as we did in step #4
- The CP log files (in the data directory)
* In the above example we configured the Scheduled Task to run as the SYSTEM account. The SYSTEM account generally has full access to everything running on the box and therefore is a good account to use to ensure that everything can be accessed. There are a few issues with this however that you should be aware of.
#1 - As SYSTEM, the service can do anything it wants. As mentioned, this can be good (no permissions problems), but it also means that the service (in this case CouchPotato) has full access to your box. Should the developer (wittingly or otherwise) write code that could compromise your computer, you would be allowing it to run unchecked.
#2 - SYSTEM does not have any network access (and can't normally be granted it). This might cause a problem if you are running CP across multiple systems. For instance you install CP on one machine but want it to download to, or pull data from another. If you are running in this configuration you will probably need to make a special "service" account. A service account is a user account that is used to only run a service. You can of course use a normal user account that is used for other things, although this isn't recommended. If you have a windows Domain you should use a windows account. Otherwise, you should create an account with the same name and password on all boxes. Ensure that the Scheduled Task is set to run as that user account instead of SYSTEM and also that it has permissions to all necessary files/folders.
You may also have to ensure that the user's profile environment is properly set up (e.g. mapped drives). For more info see the following threads: