Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何将rails应用程序(redmine)配置为在windows上作为服务运行?_Ruby On Rails_Windows_Service_Redmine - Fatal编程技术网

Ruby on rails 如何将rails应用程序(redmine)配置为在windows上作为服务运行?

Ruby on rails 如何将rails应用程序(redmine)配置为在windows上作为服务运行?,ruby-on-rails,windows,service,redmine,Ruby On Rails,Windows,Service,Redmine,我使用redmine作为票证管理器,我想将其配置为在windows启动时自动运行 如何将其配置为作为服务运行 -- 我只是问了一个问题来记录它,我希望有人会觉得它有用…1。使用webrick: 参考: 从下载并安装Windows NT资源工具包 通过运行以下命令创建服务: path\INSTSRV.EXE your_service_name path\SRVANY.EXE 在我的例子中,路径是: "C:\Program Files\Windows NT Resource Kit\INSTS

我使用redmine作为票证管理器,我想将其配置为在windows启动时自动运行

如何将其配置为作为服务运行

--


我只是问了一个问题来记录它,我希望有人会觉得它有用…

1。使用webrick:

参考:

  • 从下载并安装Windows NT资源工具包

  • 通过运行以下命令创建服务:

    path\INSTSRV.EXE your_service_name path\SRVANY.EXE
    
    在我的例子中,路径是:

    "C:\Program Files\Windows NT Resource Kit\INSTSRV.EXE" redmine_webrick "C:\Program Files\Windows NT Resource Kit\SRVANY.EXE"
    
    也可以是
    C:\Program Files\Windows Resource Kits\Tools\

  • 运行注册表编辑(开始->运行->注册表编辑)

    • 如果尚未添加以下注册表项,请添加该注册表项:

      HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Services\your\u service\u name

    • 右键单击此注册表项并选择新建->项。将其命名为
      参数

    • 参数
      键添加两个值。右键单击参数键,新建->字符串值。将其命名为
      应用程序
      。现在创建另一个名为
      AppParameters
      。给他们以下值:

      • 应用程序:
        PathToRuby.exe
        ,例如
        C:\ruby\bin\ruby.exe
      • AppParameters:
        C:\RUBYAPP\script\server-e production
        ,其中
        RUBYAPP
        是包含redmine网站的目录
      示例:
      C:\redmine\script\server-p2000-e生产
      (-p表示webrick将侦听的端口,而-e表示使用的环境)

现在您可以转到管理工具->服务。在那里,您可以启动您的服务(名为
您的\u service\u name
)并测试它是否正常工作。应该注意的是,在WEBrick完成其引导过程之前,服务将被标记为已启动。您应该给它一分钟左右,然后再尝试点击服务,以验证它是否正常工作

2。使用mongrel:

参考: 参考:

首先安装mongrel和mongrel_服务gem

gem install mongrel

gem install mongrel_service
然后创建服务

mongrel_rails service::install -N redmine_mongrel -c c:\redmine -p 3000 -e production
3。使用精简版:

参考资料:

说明:

  • 首先安装thin(如果尚未安装,则需要安装rack gem) (已安装)

  • 按照为webrick指定的相同步骤操作,但添加另一个名为“AppDirectory”的值。这是为了避免使用c:\ruby\bin\thin.bat而需要的。如果我只是指向bat文件,我就无法停止服务

    HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Services\redmine\u thin\Parameters
    中添加以下键:

    应用程序:c:\ruby\bin\ruby.exe

    AppDirectory:c:\redmine

    AppParameters:c:\ruby\bin\thin start-p 4000-e production

  • ------------------------------------------------------------------------------------------ 您可以使用以下命令控制任何服务:

    净启动redmine\u xxx

    净停止红矿

    sc config redmine_xxx start=自动

    sc config redmine_xxx start=auto dependency=MySql

    sc删除redmine_xxx


    用于Rails 3.0.x应用程序(在3.0.10和Windows 7上测试)

    demo_daemon_ctl.rb

    ############################################################################
    # demo_daemon_ctl.rb
    #
    # This is a command line script for installing and/or running a small
    # Ruby program as a service.  The service will simply write a small bit
    # of text to a file every 20 seconds. It will also write some text to the
    # 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 file in question is C:\test.log.  Feel free to delete it when finished.
    #
    # To run the service, you must install it first.
    #
    # Usage: ruby demo_daemon_ctl.rb <option>
    #
    # Note that you *must* pass this program an option
    #
    # Options:
    #    install    - Installs the service.  The service name is "DemoSvc"
    #                 and the display name is "Demo".
    #    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
    ############################################################################
    require 'win32/service'
    require 'rbconfig'
    include Win32
    include Config
    
    # Make sure you're using the version you think you're using.
    puts 'VERSION: ' + Service::VERSION
    
    SERVICE_NAME = 'DemoSvc'
    SERVICE_DISPLAYNAME = 'Demo'
    
    # Quote the full path to deal with possible spaces in the path name.
    ruby = File.join(CONFIG['bindir'], 'ruby').tr('/', '\\')
    path = ' "' + File.dirname(File.expand_path($0)).tr('/', '\\')
    path += '\demo_daemon.rb"'
    cmd = ruby + path
    
    # You must provide at least one argument.
    raise ArgumentError, 'No argument provided' unless ARGV[0]
    
    case ARGV[0].downcase
         when 'install'
                Service.new(
                     :service_name     => SERVICE_NAME,
                     :display_name     => SERVICE_DISPLAYNAME,
                     :description      => 'Sample Ruby service',
                     :binary_path_name => cmd
                )
                puts 'Service ' + SERVICE_NAME + ' installed'      
         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
    

    不久前,我还试图在Windows上安装Redmine。但我可能没能让它工作


    然后我发现。他们有一个Windows安装程序,可以安装Redmine和所有需要的依赖项,,它只适用于Bohdan建议的Rails 4.0.x应用程序, 我们必须更换

    使用RbConfig::CONFIG['bindir']配置['bindir']

    记住: gem安装win32服务

    • gem安装win32服务
    • 在service.rb文件中的Ruby代码下方,更新REDMINE_DIR path以适合您的REDMINE安装
    • 创建服务,例如使用
      sc create redmine binPath=“C:\Ruby23-x64\bin\rubyw-C E:\www\redmine-3.3.2\service.rb”
      其中
      E:\www\redmine-3.3.2\
      是service.rb文件所在目录的路径,而
      C:\Ruby23-x64\bin\rubyw
      是您的Ruby安装路径
    开始 需要“win32/daemon” 包括Win32

      class RedmineService < Daemon
    
        def service_init
          File.open(LOG_FILE, 'a'){ |f| f.puts "Initializing service #{Time.now}" } 
    
          #@server_pid = Process.spawn 'ruby script/rails s -e production', :chdir => REDMINE_DIR, :err => [LOG_FILE, 'a']
          # use full path
          @server_pid = Process.spawn 'C:\Ruby23-x64\bin\ruby E:\www\redmine-3.3.2\bin\rails s -e production -p 3000', :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}" }
          system "taskkill /PID #{@server_pid} /T /F" 
          Process.waitall
          File.open(LOG_FILE, 'a'){ |f| f.puts "Service stopped #{Time.now}" }
          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
    
    class RedmineServiceREDMINE\u DIR,:err=>[LOG\u FILE,'a']
    #使用完整路径
    @server\u pid=Process.spawn'C:\Ruby23-x64\bin\ruby E:\www\redmine-3.3.2\bin\rails s-E production-p3000',:chdir=>redmine\u DIR,:err=>[LOG\u FILE,'a']
    结束
    def维修总泵
    open(LOG_File,'a'){f|f.puts“服务正在运行{Time.now}和pid{@server_-pid}”
    跑步的时候?
    睡眠10
    结束
    结束
    def服务站
    打开(LOG_文件,'a'){f|f.puts“停止服务器线程{Time.now}”
    系统“taskkill/PID{@server\u PID}/T/F”
    Process.waitall
    打开(LOG_File,'a'){| f | f.puts“服务停止{Time.now}”
    出口
    结束
    结束
    RedmineService.mainloop
    救援异常=>e
    File.open(LOG_文件,'a+'){| f | f.puts“***守护程序失败{Time.now}异常={e.inspect}\n{e.backtrace.join($/)}”
    提升
    结束
    
    • 请注意,service.rb中的Process.spawn使用完整路径

      • 希望这对任何人都有帮助。我定义了用精简服务器启动redmine的windows服务

        用于创建windows服务。将路径设置为ruby.exe(redmine的工作目录),并定义启动参数:

        Path: C:\RailsInstaller\Ruby2.3.3\bin\ruby.exe
        Startup directory: C:\Program Files\redmine-3.4.6
        Arguments: C:\RailsInstaller\Ruby2.3.3\bin\thin start -e production -p 3000
        

        谢谢工作得很有魅力。但是我使用rubyw.exe是基于我在另一个线程上读到的一些东西
        ruby demo_daemon_ctl.rb install
        
          class RedmineService < Daemon
        
            def service_init
              File.open(LOG_FILE, 'a'){ |f| f.puts "Initializing service #{Time.now}" } 
        
              #@server_pid = Process.spawn 'ruby script/rails s -e production', :chdir => REDMINE_DIR, :err => [LOG_FILE, 'a']
              # use full path
              @server_pid = Process.spawn 'C:\Ruby23-x64\bin\ruby E:\www\redmine-3.3.2\bin\rails s -e production -p 3000', :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}" }
              system "taskkill /PID #{@server_pid} /T /F" 
              Process.waitall
              File.open(LOG_FILE, 'a'){ |f| f.puts "Service stopped #{Time.now}" }
              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
        
        Path: C:\RailsInstaller\Ruby2.3.3\bin\ruby.exe
        Startup directory: C:\Program Files\redmine-3.4.6
        Arguments: C:\RailsInstaller\Ruby2.3.3\bin\thin start -e production -p 3000