Problem
When i upgraded Prestashop 1.5 to 1.6.0.11 the product and category SEF / Friendly URLs do not work but the CMS pages do.
Cause
In my case i believe it was because i had custom Friendly URLs set so this solution might for everyone, in which case use the Useful Links.
Solution
Other Things to Try
There are several tutorials out there that tell you to experiment by turning the apache multiviews on/off and the same with mod_security. After you change either of these you need to disable the freiendly urls and then re-enable them, this causes the .htaccess to be regenerated correctely. These methods will only help a few people and you really should not disable mod_security.
Useful Links
Problem
When i upgraded Prestashop 1.5 to 1.6.0.11 there were no carriers available even though they were setup correctely in PS 1.5
Cause
This is caused by prestashop changing how they handled the shipping matrix. The matrices that are present after upgrade reflect he carriers that you had there before but the costing data and ranges have not be preserved.
Solution
Go into the shipping methods and repopulated the costing data into the ranges and add ranges as needed as if you were setting these up from fresh
This is what I did to get mantis to work with SourceSVN
Install Subversion
Install Xampp
Install Mantis
Create Repository
This is far as I got, more errors and bugs. Mantis is free but needs a serious GUI upgrade
My notes on using and configuring Redmine.
Textile:
!{width: 400px;}.clipboard-202402030959-abcde.png!
CommonMark Markdown:
<img src="/clipboard-202402030959-abcde.png" width="400">
Deprecated Redcarpet-based Markdown:

(size specifications are not supported)
Email delivery is not configured, and notifications are disabled. Configure your SMTP server in config/configuration.yml and restart the application to enable them.
configure redmine@quantumwarp.com as the system email
Create the email account
configure email in configuration.xml, you must restart redmine to see the changes.
now go back to the emails settings in redmine app as they will be available.
when you first run Redmine you are presented with the following message. You should load the default configuratioin.

If you are using this on a real website you might want to use SSL and make your installation secure. There are a few things you can do. For most people running on their local machine that do not want it on the internet do not require any of these settings, but it will not harm if they did. Following the instructions above you should already be using ProxyRequests Off
<Directory> / <Location>
SSL on non default port
The optional protocol argument is not required for most configurations. If not specified, https is the default for port 443 and http the default for all other ports. The protocol is used to determine which module should handle a request, and to apply protocol specific optimizations with the AcceptFilter directive.
You only need to set the protocol if you are running on non-standard ports. For example, running an https site on port 8443:
Listen 192.170.2.1:8443 https
Hooks
Secure Proxy
apache httpd.conf
<Proxy *> Order Deny,Allow Deny from all Allow from 192.168.0 </Proxy>
When you have a webserver running you probably would like redmine through that server aswell to keep things easier, reducing port forwarding requirements and the number of addresses you hand out. You could just hand out the new address which usually looks like http://localhost:3000/ if you want, but why not do a proper integration.
These methods will allow you to run redmine from your normal webserver or localhost, http://localhost/ with no port number on the end (this assumes that your webserver does not have a port number, using port 80).
Tthere are 2 parts of this process to consider:
With the following instructions i will assume the following
If you just want the code, click here, this will take you to the bottom where you can just get the code for a quick start without any of the history.
Files
This section is not required reading but might help if you have issues or question later on.
During my research i cam across references to Redmine files where you could put code. I am going to list them here and what i think they do.
This techniques is the best an i have taken most of the information from Defect #12102: Installed Redmine in a sub-URI: Links are generated not correctly - Redmine
This method also utilises the inbuilt WebBrick Webserver, This is an excellent simple solution but if you are going to use this for a lot of users you should perhaps think about using Thin Server, this will require slightly different instructions and some more work. WebBrick is classed as a reference server and if you are going to server more than 20 people at a time there will be large performance issues. For the most of us WebBrick will be fine.
config.ru
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
map '/redmine' do
run RedmineApp::Application
end
Replace the contents of {redmine}/config.ru with this code. This also assumes you have not already made any alterations to this file.
This code does 2 things
The root folder effectively no longer exists, you get page not found supplied by the webserver if you browse to http://localhost:3000/ and this is normal.
Other Static Asset Commands
You can also change the dynamic urls by using the 2 following commands:
which cause the following issues:
enviroment.rb
ActionController::Base.relative_url_root = '/redmine'
Add this to the end of {redmine}config/enviroment.rb. I also think you can put this in either development.rb or production.rb, this change will then only occur in that particular enviroment.
This code alters the path of the links pointing to the static files such as javascripts and CSS. Currently all paths for these still point to the root http://localhost:3000/ but they actual ar now present at http://localhost:3000/redmine/ and even though we have added the code in config.ru these paths are not altered so we need this code to correct that.
NB:
You now have moved your Redmine installation to a subfolder
this will be for my Thin server notes when i do them, there is also the Passenger Webserver to consider. Each has there own method. Basically youo can run these servers with switches to perform the directory change, You can then proxy this over to your main webserver as in the instructions below. Check my General Links section for resources.
This is the easiest of the methods to implement. You can simply proxy Remine to your apache server using the following code, this assumes redmine is at http://localhost:3000/
httpd.conf
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so
Make sure these modules are enabled in httpd.conf, they are required.
ProxyRequests Off ProxyPreserveHost On ProxyPass / http://localhost:3000/ ProxyPassReverse / http://localhost:3000/
Add these lines to the end your apache httpd.conf , if you do this you will not be able to run any other stuff from your apache webserver because all requests will get forwarded to the Redmine server.
Or Alter the Redmine Server port directely
Simply run the Redmine server on port 80 by using the following switch which will give the same effect
-p 80
These instructions will assume the subfolder on apache you want is http://localhost/redmine/
.htaccess file
# Redirects /redmine to /redmine/ RedirectMatch ^/redmine$ /redmine/ RedirectMatch ^/$ /redmine/
add this code to ..../htdocs/.htaccess in your apache server.
You can redirect the non-slashed version, but this is to make sure we have a correct URL. A directory is denoted by having a slash at the end of the URL (ie /redmine/ ) wheresas if you dont, it denotes a page (ie /redmine ).
What we are directing to is more akin to a directory/default index file like a normal webserver, http://www.example.com/ You dont often see http://www.example.com/index.html , but they are the same page. Notice the slash at the end, this is intentional.
httpd.conf
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so
Make sure these modules are enabled in httpd.conf, they are required.
ProxyRequests Off ProxyPreserveHost On ProxyPass /redmine/ http://localhost:3000/redmine/ ProxyPassReverse /redmine/ http://localhost:3000/redmine/
This is code that actualy passes the information/request between Redmine Server and your Apache server.
The commands above will work site wide so are a bit blunt, the following methods will allow you to apply these rules to a specific locations.
<Location> works on the URLs presented to the server
httpd.conf
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so
Make sure these modules are enabled in httpd.conf, they are required.
ProxyRequests Off <Location /redmine/> RedirectMatch ^/redmine$ /redmine/ RedirectMatch ^/$ /redmine/ ProxyPreserveHost On ProxyPass http://localhost:3000/redmine/ ProxyPassReverse http://localhost:3000/redmine/ </Location>
With this method you have to split the commands, ProxyRequests will not work in location so needs to be put in the normal flow of the httpd.conf (i.e. not in <location>)
Directory works on the physical path of the accessed files and is better to be used for security because several URLs can point to a single directory or file whereas the <Directory> command is very specific.
httpd.conf
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so
Make sure these modules are enabled in httpd.conf, they are required.
ProxyRequests Off <Directory "d:\Documents\Developer\xampp\htdocs\redmine\"> RedirectMatch ^/redmine$ /redmine/ RedirectMatch ^/$ /redmine/ ProxyPreserveHost On ProxyPass http://localhost:3000/redmine/ ProxyPassReverse http://localhost:3000/redmine/ </Directory>
With Virtualhost you can run a another domain name on the 1 xampp/apache server. This is very useful. You can also just use it to apply rules to the server and keep the code neater, easier for copying and pasting.
httpd.conf
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so
Make sure these modules are enabled in httpd.conf, they are required.
<VirtualHost *:80> ## This is for setting a domain name ServerName rails.localhost.com DocumentRoot "D:\Documents\Developer\RubyRoot\redmine\public\" # Make sure there is a trailing slash in the root RedirectMatch ^/redmine$ /redmine/ RedirectMatch ^/$ /redmine/ # The proxying code ProxyRequests Off ProxyPreserveHost On ProxyPass /redmine/ http://localhost:3000/redmine/ ProxyPassReverse /redmine/ http://localhost:3000/redmine/ </VirtualHost>
Including the rules in the <VirtualHost> tags is not required but can make handling the code easier and if you do want apply this to a specific domain it is easy to enable it.
So you have arrived here at the code, just following the simple instructions and edit the files. Redmine will then run at http://localhost/redmine/ on you xampp installation. This does of course assume you have Redmine already running on your Windows PC.
Redmine - config.ru
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
map '/redmine' do
run RedmineApp::Application
end
Replace the contents of {redmine}/config.ru with this code. This also assumes you have not already made any alterations to this file.
Redmine - enviroment.rb
ActionController::Base.relative_url_root = '/redmine'
Add this to the end of {redmine}config/enviroment.rb. I also think you can put this in either development.rb or production.rb, this change will then only occur in that particular enviroment.
Apache / Xampp - httpd.conf
Edit your Apache / Xampp httpd.conf file
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so
Make sure these modules are enabled in httpd.conf file, they are required.
################################# # RUBY SETUP ################################# # Enforces a trailing slash for the /redmine/ directory RedirectMatch ^/redmine$ /redmine/ RedirectMatch ^/$ /redmine/ # The proxying code ProxyRequests Off ProxyPreserveHost On ProxyPass /redmine/ http://localhost:3000/redmine/ ProxyPassReverse /redmine/ http://localhost:3000/redmine/ ################################# # RUBY SETUP #################################
Add these lines at the bottom of the httpd.conf file.
Done
All the changes are now done, you will find that Redmine will be served from http://localhost/redmine/ and http://localhost:3000/redmine/ , this is normal.
If you had your servers running while making these changes you need to restart them both.
You should note that this setup is non-SSL version so is not secure.
These are the links i used for my research and might be of use.
Redmine / Ruby
Reverse Proxy
Apache
These are my instructions to upgrade your Redmine install on windows and also assumes you have used my instructions for installing redmine, however this is not mandatory but will explain where the filepaths come from.
I will be upgrading Redmine 2.6.1 to Redmine 3.0.0 but i am sure they will be almost the same for other version.
Notes
The first step to upgrading Redmine is to check that you meet the requirements for the version you're about to install.
You can easily check what version of Redmine, Ruby and Rails by browsing to Administration/Information and you will see the following information.
Environment: Redmine version 2.6.1.stable Ruby version 2.1.5-p273 (2014-11-13) [i386-mingw32] Rails version 3.2.21 Environment production Database adapter Mysql2 SCM: Subversion 1.8.11 Filesystem Redmine plugins: no plugin installed
Redmine 3.0.0 requires, Ruby 1.9.3 or higher (and now supports ruby 2.2).
bundle install --without development test
================================================================================ You've installed the binary version of mysql2. It was built using MySQL Connector/C version 6.1.5. It's recommended to use the exact same version to avoid potential issues. At the time of building this gem, the necessary DLL files were retrieved from: http://cdn.mysql.com/Downloads/Connector-C/mysql-connector-c-6.1.5-win32.zip This gem *includes* vendor/libmysql.dll with redistribution notice in vendor/README. ================================================================================
bundle exec rake generate_secret_token
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
bundle exec rake tmp:cache:clear tmp:sessions:clear RAILS_ENV=production
If you discover that your log file is filling up with lots of uneeded information you can change the logging level from the default.
in the {redmine}/config/additional_enviroment.rb file you can change the logging level. By either adding the line or un-remming one that is present. When you set the error loggin level to error you will only get errors logged to the log file. This will affect both enviroments.
The log levels available are: :debug, :info, :warn, :error, :fatal, and :unknown, which correspond to the integers 0-5.
Logging Links
Installation of Subversion with redmine can be straight forward if you have some easy toread instructions, so here they are.
There are several levels of integration
Read the official Instructions - RedmineSettings - Repositories
According to the instructions this only works if Redmine and the Subversion Server are on the sam physical machine (this needs 100% clarifying but for now we will assume it is true).
This feature allows you to grab the commits from a predefined SVN Repository (most protocols are supported) and this repository is attached to a project, by doing this when you submit a commit to a repository with a message with correct issue reference syntax, redmine will close the related isse(s) in the project. Git , SVN and other SCM are available. This feature also allows you to perfomr comparisons of different revisions and you eben get the choice to see the changes side-by-side or on top of each other, this feature can be useful depending on how your code looks. There is also a repository browse feature built in to redmine. You can have multiple repositorys per project
Enable Fetch Commits Automatically
In Redmine Administration/Settings/Repositories make sure that Fetch Commits Automatically is ticked. If this option is activated, the application automatically retrieves the new revisions when a user consults the repository.
Official article here
Instructions to add a repository
make sure u use a network version for the repository so you can move it if you want.
SCM Subversion
Main repository checked
identifier test-identifier (dont know what this is for, Repository Identifier)
URL https://svn.exampleserver.com:18080/svn/Test/
user svn-redmine
password xxwhateverxxxx
* when the repository is set you cannot change the details after you have created it except for the surname and password.I have read on the redmine official documentation that you should use a network location for you Subversion repository
Now that you have configured these settings you can close jobs via a svn commit (see below for forming a correct message for closing jobs) but the draw back is that the changes/commits are only retrieved at certain times
In the step above you configured Redmine to interact with Subversion and to retrieve any changes/commits. Redmine currently parses the commit messages for keywords which reference issue, it does this so it can automatically change these keywords into links. These links are found by using a set of default rules and keywords which can be chamged in the admin panel but the default options should be fine for most people.
The one thing Redmine does not do by default is close issues. You need to specify the keywords that you want to be used as closing keywords and enable the option in the Redmine settings via the admin panel.
Links
fix,fixes,fixed,close,closed,patches,patched
You can configure whatever rule you want but at least this will get you going. Read the official Documentation for the syntax of closing statements you should use in your commit messages.
NB:
Better Issue Referencing
Redmine has a list of keywords it scans for to identify issues as follows:
refs,references,IssueID
I want to extend that to the following list
refs,references,IssueID,bug,bugs,defect,defects,feature,features,issue,issues,patch
I dont know about whether yoou can close multiple issues but i will add the plural version here anyway
Resolve Issue Keywords (optional)
These are different status and have different uses so require their own settings in the'Referencing and fixing issues in commit messages'.
If you want to have the resolved option set from commit messages you need to do the following:
resolve,resolves,resolved
To reference and issue use a command using any of the issue referencing keywords as below:
issue #1234
To close a job use the following or similiar command with any of the other closing keywords
close #1234
The key thing with these is that that the command is in a certain format
{keyword}{a space}{a hash}{issue number}
Resolved Vs Closed Links
To get jobs to close when you actually submit the commit further integration is required which is in the next section.
This is a very useful feature because in my opinion this is how everyone will think this integration works, when you submit a commit with closing statements in the message that issue will be immediately closed. In the 'Basic SVN Integration' this does not happen until you browse the repository or your cron job is fired so the commits get parsed and redmine closes the jobs so there could potentially be a gap between closing the jobs and this apopearing on the Redmine installation.
In this method you basically create a post-commit hook that polls the Redmine installation which then instructs Redmine that some changes have been made and that it should fetch them. It should be noted that this can cause a slight slow down in the commiting of the changes to the repository.
There are 2 types of polls you can use:
And several delivery methods for the hook:
My Instructions
I will be using cURL for these instructions because it is the easiest solution.
Do this once
Required For Each Repository
For each repository you need create add an exectuable post-commit hook with the commands in it to trigger Redmine in to checking for changes. I will use a Hook that updates only the repositories in that particular project. It will also be very easy to change to refresh all repositories.
post-commit.bat
@ECHO OFF curl "http://<redmine url>/sys/fetch_changesets?id=<project identifier>&key=<your service key>"
This is the example code from Redmine's official instructions on calling a URL that will trigger Redmine to refresh all Repositories for that chosen Project.
Create the 'post-commit' Hook
I will assume
@ECHO OFF curl "http://localhost/redmine/sys/fetch_changesets?id=TestProject&key=Password123"
Upon a successful commit to your Subversion Repository, Redmine will check all of the Repositories that belong to the specified project for changes.
You might be asking why cannot i not just update only a specified repository in Redmine rather than all of the repositories that belong to a project. This is a requested feature but for some reason it has not been added yet. Considering things most people will not notice this and if you use the command that refreshes all repositories in Redmine upon a successful commit you will never need this. If you use the 'Refresh All' command you can just copy this to other repository hook folders without alteration.
Useful Links
This is the final level of integration but it is not easy and seems to come with its own issues. You have to edit code and do this and that to get it to work. It is quicker to create the SVN Repository in Subversion Edge and then enter the details into redmine as in 'Basic SVN Integration'
I will not be implementing this aas i have easy control over my Subversion Server
See the official page for more information
This can be a tricky thing to get working if you have no knowledge of Ruby or assume that all the scripts you come across actually work. I have found a lot of information about getting Redmine to run as a windows service is quite old and ruby ahs changed a lot since they were written. This article hold all my research from googling around the internet which includes those key niggets of information to help me get the scripts working.
As ever you have come across another article saying how things should work but never just give you the code so you can get Redmine working and worry about other things. This article is diffrerent, i have included all my research so if there are any problems i have not seen or issues that come along later you will be able to fix them withou pulling your hair out and lastly this article has the working scripts. If you just want the scripts so you can get running please scroll to 'The Scripts' and follow the installations instructions and you will be running very quickly.
There are currently a few methods that I have found to create a service:
When you start the service it can take up to 60 seconds to properly start and if you look in task manager it is normal to see to instances of ruby either ruby.exe or rubyw.exe
This is what happens:
When trying to configure redmine to run as a service you might come across some of the issues I am going to outline below but the good thing is I am going to tell you why they occur which will make fixing them stress free.
Error 1053
Windows could not start the redmine service on Local Computer. Error 1053: The service did not respond to the start or control request in a timely fashion.

Error 1067
Windows could not stop the redmine service on Local Computer. Error 1067: The process terminated unexpectedly.

Normal Script
Using Windows Resource Kit
Mongrel
Misc Relevant
The simple script is the absolute basic version of the script but does work as expected.
These are my notes on using the script found on redmine.org, HowTo run Redmine as a Windows service (win32-service + taskill approach) - Redmine. This script has issues with it so i have listed them below and then you will find my corrected version which does work.
sc create redmine binPath= "D:\Documents\Developer\RailsInstaller\Ruby2.1.0\bin\rubyw -C D:\Documents\Developer\RubyRoot\redmine\ redmine-service.rb"
When you fill in the command make sure you leave the space inbetween ...\redmine\ redmine-service.rb , the reason for this is that ...\redmine\ beongs with the -C switch which is telling the code to change to the redmine directory before running the script. you can actually add a full path to redmine-service.rb if you wanted to make it easier to read.
The Script
REDMINE_DIR = 'D:\Documents\Developer\RubyRoot\redmine'
LOG_FILE = "#{REDMINE_DIR}\\log\\redmine-service.log"
begin
require 'win32/daemon'
include Win32
class RedmineService < Daemon
def service_init
File.open(LOG_FILE, 'a'){ |f| f.puts "Initializing service #{Time.now}" }
@server_pid = Process.spawn 'D:\Documents\Developer\RailsInstaller\Ruby2.1.0\bin\rubyw script/rails s -e production', :chdir => REDMINE_DIR, :err => [LOG_FILE, 'a']
end
def service_main
File.open(LOG_FILE, 'a'){ |f| f.puts "Service is running #{Time.now} with pid #{@server_pid}" }
while running?
sleep 10
end
end
def service_stop
File.open(LOG_FILE, 'a'){ |f| f.puts "Stopping server thread #{Time.now} with pid #{@server_pid}" }
system "taskkill /PID #{@server_pid} /T /F"
Process.waitall
File.open(LOG_FILE, 'a'){ |f| f.puts "Service stopped #{Time.now}" }
pid_file = 'tmp/pids/server.pid'
File.file?(pid_file) && File.delete(pid_file)
#exit! # can cause a bad exit
end
end
RedmineService.mainloop
rescue Exception => e
File.open(LOG_FILE,'a+'){ |f| f.puts " ***Daemon failure #{Time.now} exception=#{e.inspect}\n#{e.backtrace.join($/)}" }
raise
end
This is my script that i have made from several scripts. This is a modern daemon code with logging and a controller file to make install/running/deleting the script as a service. The script will also populate most of the variables if your Ruby path is set and you run the redmine_service_ctl.rb from the root of your redmine installation.
My script might not handle paths with spaces in them correctely. This should be easily fixed by using quotes (") where needed. I might update the scripts if there is any interest.
The script configures itself automatically.
If the installation does not work as expected you might need to
Controller Script
This script should be called redmine_service_ctl.rb and this is the service management script, it is used to install/stop/start/delete the service from the command line.
############################################################################
#
# redmine_service_ctl.rb
#
# This is a command line script for installing and/or running a small
# Ruby program as a service, in this case it is Redmine.
#
# The service will run Redmine and will record certain events to a log file.
# If enabled, the service can also write a small bit of text
# to the log file every 20 seconds to show it is running.
# Some text will bve written to the log file during the initialization (service_init) step.
#
# It should take about 10 seconds to start, which is intentional - it's a test
# of the service_init hook, so don't be surprised if you see "one moment,
# start pending" about 10 times on the command line.
#
# The Log File is {redmine_dir}/log/test.log. Feel free to delete it when finished.
#
# To run the service, you must install it first.
#
# Usage: ruby redmine_service_ctl.rb <option>
#
# Note that you *must* pass this program an option
#
# Options:
# install - Installs the service. The service name is "RedmineService"
# and the display name is "Redmine Windows Service".
# start - Starts the service. Make sure you stop it at some point or
# you will eventually fill up your filesystem!.
# stop - Stops the service.
# pause - Pauses the service.
# resume - Resumes the service.
# uninstall - Uninstalls the service.
# delete - Same as uninstall.
#
# You can also used the Windows Services GUI to start and stop the service.
#
# To get to the Windows Services GUI just follow:
# Start -> Control Panel -> Administrative Tools -> Services
#
# by shoulders @ QuantumWarp.com
# used code from
# http://stackoverflow.com/questions/877943/how-to-configure-a-rails-app-redmine-to-run-as-a-service-on-windows
#
############################################################################
#---------------------------------------------------------------------------
# Includes
#---------------------------------------------------------------------------
# require 'rubygems' # only for < ruby 1.9
require 'win32/service'
require 'rbconfig'
include Win32
include RbConfig
# Make sure you're using the version you think you're using.
puts 'VERSION: ' + Service::VERSION
SERVICE_NAME = 'RedmineService'
SERVICE_DISPLAY_NAME = 'Redmine Windows Service'
SERVICE_DESCRIPTION = 'This is my Windows Redmine Service'
#---------------------------------------------------------------------------
# Automatically Create Windows Service Binary Path
#---------------------------------------------------------------------------
RUBY_BINARY = File.join(CONFIG['bindir'], 'rubyw').tr('/', '\\')
PATH = ' -C ' + File.dirname(File.expand_path($0)).tr('/', '\\') + '\\ ' + 'redmine_service.rb'
CMD = RUBY_BINARY + PATH
# MANUAL OVERIDE
# This builds the windows binaryPath ="" in the format:
# CMD = 'D:\Documents\Developer\RailsInstaller\Ruby2.1.0\bin\rubyw -C D:\Documents\Developer\RubyRoot\redmine\ redmine_service.rb'
# CMD = 'D:\Documents\Developer\RailsInstaller\Ruby2.1.0\bin\rubyw -C D:\Documents\Developer\RubyRoot\redmine\ D:\Documents\Developer\RubyRoot\redmine\redmine_service.rb'
# if you want to uses spaces in your path you need to enclose in each path in quotes ("")
# possibly
# CMD = '"D:\Documents\Developer\RailsInstaller\Ruby2.1.0\bin\rubyw" -C "D:\Documents\Developer\RubyRoot\redmine\ " "redmine_service.rb"'
# CMD = '"D:\Documents\Developer\RailsInstaller\Ruby2.1.0\bin\rubyw" -C "D:\Documents\Developer\RubyRoot\redmine\" "D:\Documents\Developer\RubyRoot\redmine\redmine_service.rb"'
#---------------------------------------------------------------------------
# Perform Service Action Based on Argument supplied
#---------------------------------------------------------------------------
# You must provide at least one argument.
raise ArgumentError, 'No argument provided' unless ARGV[0]
# These are the actions performed for the various windows service tasks/functions
case ARGV[0].downcase
when 'install'
Service.new(
# These are the service configuration settings that are written to the registry
# will run automatically without a user being logged in
:service_name => SERVICE_NAME,
:display_name => SERVICE_DISPLAY_NAME,
:description => SERVICE_DESCRIPTION,
:start_type => Service::AUTO_START,
:service_type => Service::WIN32_OWN_PROCESS,
:load_order_group => 'Network',
:dependencies => nil,
#:dependencies => ['Developer-Apache2.4','Developer-MySQL'],
#:error_control => Service::ERROR_NORMAL,
#:service_start_name => 'SomeDomain\\User',
#:password => 'XXXXXXX',
:binary_path_name => CMD,
)
puts CMD
puts 'Service ' + SERVICE_NAME + ' installed'
# One of following code sections, which all match to their corresponding 'Windows Service Function' is
# triggered depending on what argument is supplied in the oommand line.
when 'start'
if Service.status(SERVICE_NAME).current_state != 'running'
Service.start(SERVICE_NAME, nil, 'hello', 'world')
while Service.status(SERVICE_NAME).current_state != 'running'
puts 'One moment...' + Service.status(SERVICE_NAME).current_state
sleep 1
end
puts 'Service ' + SERVICE_NAME + ' started'
else
puts 'Already running'
end
when 'stop'
if Service.status(SERVICE_NAME).current_state != 'stopped'
Service.stop(SERVICE_NAME)
while Service.status(SERVICE_NAME).current_state != 'stopped'
puts 'One moment...' + Service.status(SERVICE_NAME).current_state
sleep 1
end
puts 'Service ' + SERVICE_NAME + ' stopped'
else
puts 'Already stopped'
end
when 'uninstall', 'delete'
if Service.status(SERVICE_NAME).current_state != 'stopped'
Service.stop(SERVICE_NAME)
end
while Service.status(SERVICE_NAME).current_state != 'stopped'
puts 'One moment...' + Service.status(SERVICE_NAME).current_state
sleep 1
end
Service.delete(SERVICE_NAME)
puts 'Service ' + SERVICE_NAME + ' deleted'
when 'pause'
if Service.status(SERVICE_NAME).current_state != 'paused'
Service.pause(SERVICE_NAME)
while Service.status(SERVICE_NAME).current_state != 'paused'
puts 'One moment...' + Service.status(SERVICE_NAME).current_state
sleep 1
end
puts 'Service ' + SERVICE_NAME + ' paused'
else
puts 'Already paused'
end
when 'resume'
if Service.status(SERVICE_NAME).current_state != 'running'
Service.resume(SERVICE_NAME)
while Service.status(SERVICE_NAME).current_state != 'running'
puts 'One moment...' + Service.status(SERVICE_NAME).current_state
sleep 1
end
puts 'Service ' + SERVICE_NAME + ' resumed'
else
puts 'Already running'
end
else
raise ArgumentError, 'unknown option: ' + ARGV[0]
end
Daemon / Service Script (the actual service)
This should be called redmine_service.rb
############################################################################
#
# redmine_service.rb
#
# This script should automatically configure itself.
#
# The only thing you might need to alter are the RUBY_BINARY_ARGUMENTS.
# -e is the enviroment and the options are development/production
# -p is the port number to run Redmine on
#
# by shoulders @ QuantumWarp.com
# used code from
# http://stackoverflow.com/questions/877943/how-to-configure-a-rails-app-redmine-to-run-as-a-service-on-windows
#
############################################################################
#---------------------------------------------------------------------------
# Includes
#---------------------------------------------------------------------------
include RbConfig
#---------------------------------------------------------------------------
# Automatically Create File Paths
#---------------------------------------------------------------------------
RUBY_BINARY = File.join(CONFIG['bindir'], 'rubyw').tr('/', '\\')
#RUBY_BINARY = 'D:\Documents\Developer\RailsInstaller\Ruby2.1.0\bin\rubyw'
# Redmine 2.x
#RUBY_BINARY_ARGUMENTS = ' ' + 'script/rails s -e production -p 3000'
#RUBY_BINARY_ARGUMENTS = ' script/rails s -e production -p 3000'
# Redmine 3.x
RUBY_BINARY_ARGUMENTS = ' ' + 'bin/rails s -e production -p 3000'
#RUBY_BINARY_ARGUMENTS = ' bin/rails s -e production -p 3000'
REDMINE_DIR = File.dirname(File.expand_path($0)).tr('/', '\\')
#REDMINE_DIR = 'D:\Documents\Developer\RubyRoot\redmine'
LOG_FILE = "#{REDMINE_DIR}\\log\\redmine-service.log"
#LOG_FILE = 'D:\Documents\Developer\RubyRoot\redmine\log\redmine-service.log'
#---------------------------------------------------------------------------
# The Actual Service
#---------------------------------------------------------------------------
begin
require 'win32/daemon'
include Win32
class RedmineDaemon < Daemon
# This method fires off before the +service_main+ mainloop is entered.
# Any pre-setup code you need to run before your service's mainloop
# starts should be put here. Otherwise the service might fail with a
# timeout error when you try to start it.
#
def service_init
File.open(LOG_FILE, 'a'){ |f| f.puts "Initializing service #{Time.now.to_s}" }
@server_pid = Process.spawn RUBY_BINARY + RUBY_BINARY_ARGUMENTS, :chdir => REDMINE_DIR, :err => [LOG_FILE, 'a']
# MANUAL COMMANDS
# Redmine 2.x
#@server_pid = Process.spawn 'D:\Documents\Developer\RailsInstaller\Ruby2.1.0\bin\rubyw script/rails s -e production -p 3000', :chdir => REDMINE_DIR, :err => [LOG_FILE, 'a']
# Redmine 3.0
#@server_pid = Process.spawn 'D:\Documents\Developer\RailsInstaller\Ruby2.1.0\bin\rubyw bin/rails s -e production -p 3000', :chdir => REDMINE_DIR, :err => [LOG_FILE, 'a']
end
# This is the daemon's mainloop. In other words, whatever runs here
# is the code that runs while your service is running. Note that the
# loop is not implicit.
#
# You must setup a loop as I've done here with the 'while running?'
# code, or setup your own loop. Otherwise your service will exit and
# won't be especially useful.
#
# In this particular case, I've setup a loop to append a short message
# and timestamp to the log file every 20 seconds. Remove the logging
# when you are using this as a real service otherwise you logfile will
# become large quickly.
#
# not sure what the (*args) means
def service_main(*args)
File.open(LOG_FILE, 'a'){ |f| f.puts "Service is running #{Time.now} with pid #{@server_pid}" }
msg = 'application started at: ' + Time.now.to_s
File.open(LOG_FILE, 'a'){ |f|
f.puts msg
f.puts "Args: " + args.join(',')
}
# While the daemon is running
while running?
if state == RUNNING
sleep 20
# write constantly to log file while running for diagnostics only
#msg = 'Service is running as of: ' + Time.now.to_s
#File.open(LOG_FILE, 'a'){ |f| f.puts msg }
else # PAUSED or IDLE
sleep 0.5
end
end
# We've left the loop, the daemon is about to exit.
File.open(LOG_FILE, 'a'){ |f| f.puts "STATE: #{state}" }
msg = 'service_main left at: ' + Time.now.to_s
File.open(LOG_FILE, 'a'){ |f| f.puts msg }
end
# This event triggers when the service receives a signal to stop. I've
# added an explicit "exit!" here to ensure that the Ruby interpreter exits
# properly. I use 'exit!' instead of 'exit' because otherwise Ruby will
# raise a SystemExitError, which I don't want.
#
def service_stop
msg = 'Received stop signal at: ' + Time.now.to_s
File.open(LOG_FILE, 'a'){ |f| f.puts msg }
pid_file = 'tmp/pids/server.pid'
File.open(LOG_FILE, 'a'){ |f| f.puts "Stopping server thread #{Time.now.to_s} with pid #{@server_pid}" }
system "taskkill /PID #{@server_pid} /T /F"
Process.waitall
File.open(LOG_FILE, 'a'){ |f| f.puts "Service stopped #{Time.now.to_s}" }
File.file?(pid_file) && File.delete(pid_file)
# exit! - what is this exit for? there was a reason, this seems to cause a bad exit with redmine but might be needed for other scripts
end
# This event triggers when the service receives a signal to pause.
#
def service_pause
msg = 'Received pause signal at: ' + Time.now.to_s
File.open(LOG_FILE, 'a'){ |f| f.puts msg }
end
# This event triggers when the service receives a signal to resume
# from a paused state.
#
def service_resume
msg = 'Received resume signal at: ' + Time.now.to_s
File.open(LOG_FILE, 'a'){ |f| f.puts msg }
end
end
# Create an instance of the Daemon and put it into a loop. I borrowed the
# method name 'mainloop' from Tk, btw.
#
RedmineDaemon.mainloop
#---------------------------------------------------------------------------
# Service Failure Logging
#---------------------------------------------------------------------------
rescue Exception => err
File.open(LOG_FILE, 'a'){ |fh| fh.puts 'Daemon failure: ' + err + '\n'} # this one line is from the 1 page script based on demo
File.open(LOG_FILE,'a+'){ |f| f.puts " ***Daemon failure #{Time.now.to_s} exception=#{err.inspect}\n#{err.backtrace.join($/)}" }
raise
end
Notes
script/rails no longer exists, please use bin/rails instead.
To fix this you basically need to make the change as told in this error. You will see in the redmine-service.rb i have added Redmine 3.x versions, the lines you need to change from Redmine 2.x to 3.x are line 30 - line 36, the rest should be obvious.
If you are using xampp as the donour for the MySQL service you must make sure that this is running when the Redmine service is started otherwise it will fail and not start. To fix this you can make the xampp MySQL (and Apache if required) service as a dependency which means that when you start your redmine service it will start these dependant services first to make sur ethey are running.
Currently the scripts above are not enabled to call Xampp Apache and MySQL services as dependants, the code is there though. There are a couple of steps required to get this working if you want, otherwise you must manually start at least the MySQL service or already have it runnign before you start the redmine service
This feature requires 2 things to be done
NB:
If you want to run more than 1 Xampp installation, or even if you dont, i recommend that you should change the default service name for the Xampp Apache and MySQL services on you Developer Xampp instance. The reason for this is that if like me you use Xampp for developing websites on your Windows PC, the Xampp installationscheck by service name, to see if the Apache and MySQL services are running. This means that if you setup your Developer site with the default service names, when you then open up another instance of Xampp it will think that it is running as a service even if you have not installed that instance as a service.
So by giving different names to these services we will be using for the redmine development xampp it can function independantly to any other xampp instances. This how most people would expect this to work. I also want this seperate installation of xampp because when i am poking around with code or messing databases for my regular web development i do not risk my development enviroment.
Changing the service names is optionals for those budding coders but i definately still recommend it for the reasons outlined above)
Instructions
To change the service names of Apache and MySQL is very easy and requires you to use the xampp control panel.
Apache Service
MySQL Service
This stage is also an easy one and involves editing the redmine_service_ctl.rb from 'My Complex Script' .
:dependencies => nil, #:dependencies => ['Developer-Apache2.4','Developer-MySQL'],
You can see that there is a declaration of no dependencies. The line below it defines some depnedecies but is remmed out. Change the lines around so the service has dependencies. The new code should look like the code below, basically you have just changed the poistion of the Hash '#'
#:dependencies => nil, :dependencies => ['Developer-Apache2.4','Developer-MySQL'],
As you can see the service names match those i set earler but can be anything as long as they match the appropriate service.
Now start the redmine service and you will find it will start the Xampp apache and MySQL Services automatically.
This is a robust way of having redmine running on your Windows PC and once configured you can practically forget about it and just use Redmine for what you wanted to use it for in the first place, software development. There are no more settings to do, you are ready to rock and roll.