Can't get service to start on chef - ruby

I have a service resource but I can't get chef to start it, instead chef just spits out an error message:
SystemCallError: The specified service does not exist as an installed service. - OpenService: The specified service does not exist as an installed service.
I'm not sure what to do to fix this and I can't find anything on this error (could be I'm not looking in the right place).
The service is distributed as a gem that's installed.
The service itself is a Sinatra app that uses the win32-service gem to start it as a service
The platform is windows server (I know but I have no choice, I have to use windows server)
The code in the chef recipe for this service is:
service service_name do
init_command ("#{%x(gem env gemdir).strip.gsub('/','\\')}\\gems\\#{service_name}-#{installing_version}")
start_command "rake service:start"
stop_command "rake service:stop"
reload_command "rake service:reload"
restart_command "rake service:restart"
supports start: true, restart: true, reload: true
action [:enable,:start]
end

The issue is not with Chef, but with your service itself. Typically when I'm in this situation, I will login manually and attempt to start the service. Sometimes that will give you additional information. Also, take a look at the log files for your app and see if you can figure out why it's not starting.
Ultimately, Chef just calls your init and start commands, but it can't do much if those commands fail.

Related

Error executing action `create` on resource 'directory[C:/topdir/subdir]'

I'm getting permissions errors with the create action on windows servers.
Initially I was doing this in one recipe:
directory "C:/topdir" do
rights :full_control, 'Users'
action :create
end
directory "C:/topdir/subdir" do
action :create
recursive true
end
If I run this in test kitchen or even login to a bootstrapped server and run chef-client it completes with no errors.
But I see these errors on Chef server when it runs automatically:
Description: Error executing action `create` on resource 'directory[C:/topdir/subdir]'
Chef::Exceptions::InsufficientPermissions
Cannot create directory[C:/topdir/subdir] at C:/topdir/subdir due to insufficient permissions
It seems I "fixed" this by replacing rights :fullcontrol, 'Users' with rights :fullcontrol, 'Everyone' but I don't want that and it doesn't make sense to me why that would be necessary.
Why is this happening?
Also, how can I test this if the errors only happen during automated chef runs- I can only see errors in chef server reporting. How can I see what user this is even running in? I assumed local system but I guess not? It works running chef-client locally from an elevated prompt so why would it not work when running on schedule?
My knowledge of Windows is limited, but in general I think services get run as a dedicated SYSTEM user, which is not part of the Users group.

How can i run my ruby service with chef recipe

I have a web service in ruby, and i want to run my ruby service via chef recipe.
I have used execute command as :
execute 'start-ruby' do
command 'ruby /opt/certificate.rb start'
action :run
end
I can see my ruby service running in background on my Amazon instance, but somehow Instance setup is stuck in running setup.
Is there any other alternative from which i can run my ruby service via chef recipe.
The execute resource runs its command synchronously, meaning it waits for it to finish before continuing with the recipe. I'm guessing your start command there starts a foreground-mode daemon (which is how it should work) so it never returns and Chef just waits forever.
Check out https://github.com/poise/application_examples/blob/master/recipes/todo_rails.rb or https://github.com/poise/poise-service for examples of Ruby application deployment and generic service management respectively.

node.js http server as a Windows service

I created a simple http server in Node.js.
I wanted to make it run permanently on my Windows 2008 machine, so that, if the computer reboots, it automatically restarts.
So I made it a service with this command:
C:\Users\Administrator>sc create translate binPath= "node D:\Apps\translate\machine-learning-server\servertranslate.js" DisplayName= "Translation Server"
Then started it with:
C:\Users\Administrator>sc start translate
and got the following error message:
[SC] StartService FAILED 1053:
The service did not respond to the start or control request in a timely fashion.
The program works OK when I start it from the command line (not as a service).
What is the easiest way to have a node.js web server that restarts automatically when the computer reboots?
In the past, I've used NSSM for running Node.js applications as services on Windows. It works quite well, and can be configured to automatically restart your application in the event of a crash.
http://nssm.cc/usage
nssm install YourService "C:\Program Files\Node.js\node.exe" "C:\something\something.js"
As I recall, the Service runtime environment isn't the same as running something under the command shell. In particular, Services are required to respond to messages from the system to indicate their running status, as you've seen :-)
This must be a solved problem, though...
Sure enough:
https://npmjs.org/package/windows-service
windows-service
Run Node.JS programs as native Windows Services.
npm install windows-service
Use this one, really simple
https://github.com/coreybutler/node-windows
Create two js file on your project. And run those as
node your_service.js
node your_service_remove.js
For install:
/**
* Created by sabbir on 08/18/2015.
*/
//ref: https://github.com/coreybutler/node-windows
var Service = require('node-windows').Service;
// Create a new service object
var svc = new Service({
name:'nodeDemoApp',
description: 'The nodejs.org example web server.',
script: 'D:\\NodeJS\\demoWeb\\bin\\www'
});
// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
svc.start();
});
svc.install();
For uninstall:
var Service = require('node-windows').Service;
// Create a new service object
var svc = new Service({
name:'nodeDemoApp',
script: require('path').join(__dirname,'bin\\www')
});
// Listen for the "uninstall" event so we know when it's done.
svc.on('uninstall',function(){
console.log('Uninstall complete.');
console.log('The service exists: ',svc.exists);
});
// Uninstall the service.
svc.uninstall();
At a guess, I'd say that the service doesn't know where to find the node binary. You've probably updated your profile's PATH variable. My recommendation is to ALWAYS hard code the full path in service scripts.
As mentioned in others questions about it, I'd like to share here (because it wasn't referred yet) a node.js module called WinSer that wraps NSSM and its usage is very simple, maybe it helps someone someday.
: )
You could try the package qckwinsvc. First install it globally:
npm install -g qckwinsvc
And then from the cmd:
qckwinsvc
prompt: Service name: [...]
prompt: Service description: [...]
prompt: Node script path: [/path/to/.js file]
To uninstall:
qckwinsvc --uninstall
Always a good idea to look at the number of downloads something is getting.
PM2 seems to be winning and is very easy.
https://medium.com/#harshamw/deploying-a-node-js-application-in-iis-using-a-reverse-proxy-process-management-using-pm2-3d59b83d7f76
You'll need to then use https://www.npmjs.com/package/pm2-windows-service to start it as a windows service on reboot.

Smartfoxserver 2X linux 64 running on EC2 via dotcloud - how to install?

I am currently trying to deploy smartfoxserver 2X on EC2 using dotcloud. I have been able to detect the private ip of the amazon web instance, and using the dotcloud tools I have been able to determine the correct port. However, I have difficulty installing the server proper via the command line so that I can log into it using the AdminTool.
My postinstall is fairly straightforward:
./SFS2X/sfs2x-service start-launchd
I find that on 'dotcloud push' there is a fair amount of promising output in my cygwin terminal, but the push hangs after saying that the sfs2x-service has been launched correctly, until timeout.
Consequently, my question is, has anyone found a way to install SFS2X on EC2 via dotcloud successfully? I managed to have partial success with SFS Pro, with a complete push to dotcloud, by calling ./jre/bin/java -jar installer.jar in my postinstall. Do I need to do extra legwork and build an installer jar for SFS2X? Is there a way that would be best to do this?
I do understand that there is a standard approach to deployment with SFS2X using RightScale on EC2, however I am interested in deployment using the dotcloud platform.
Thanks in advance.
The reason why it is hanging is because you are trying to start your process in the postinstall, and this is not the correct place to do that. The postinstall script is suppose to finish, if it doesn't the deployment will time out, and then get cancelled.
Once the postinstall script is finished, it will then finish the rest of your deployment.
See this page for more information about dotCloud postinstall script:
http://docs.dotcloud.com/0.9/guides/hooks/#post-install
Pay attention to this warning at the end.
Warning:
If your post-install script returns an error (non-zero exit code), or if it runs for more than 10 minutes, the platform will consider that your build has failed, and the new version of your code will not be deployed.
Instead of putting this in the postinstall script, you should add it as a background process, so that it starts up once the deployment process is complete.
See this page for more information on adding background processes to dotCloud services:
http://docs.dotcloud.com/0.9/guides/daemons/
TL;DR: You need to create a supervisord.conf file, and add it to the root of your project, and add your service to that.
Example (you will need to change to fit your situation):
[program:smartfoxserver]
command = /home/dotcloud/current/SFS2X/sfs2x-service start-launchd
Also, make sure you have the correct dotCloud service specified in your dotcloud.yml in order to have the correct binary and libraries installed for what your smartfoxserver application.

Hudson Running as a Service not Starting

I downloaded Hudson, and am trying to install it as a service. I followed the steps from this page, but when I try to start the service, it always fails. I'm not really getting any defined error codes either. If I try to run the service from the command line (using net start) I get the following (unhelpful) message:
The hudson service could not be started.
The service did not report an error.
The install process seemed to work fine, as the hudson service is installed, and all the files are in the new directory, but the service won't start. Has anyone else run into this problem?
As documented on that page, they have a note of...
If a restart fails for some reason, check the output from Hudson, which is stored in the installation directory that you specified.
Is there anything to denote further errors?

Resources