How to check that service is stopped, and if not - stop it?

How to check that service is stopped, and if not - stop it ?

For example in this code block:

See if needed


bash "bundle_redmine_mylyn" do
cwd
"#{node['redmine']['datafs']}/redmine/plugins/redmine_mylyn_connector"
user node['apache']['user']
code <<-EOH
# We doing source because of interactive shell don't read
our .profile
source #{node['redmine']['home']}/.rvm/scripts/rvm
bundle install
EOH
end

And Can write some not_if's only_if's for example

do
not_if
not_if
only_if
only_if
end

?

--
Best regards,

CVision Lab System Administrator
Vladmir Skubriev

I'm not sure where in your code sample you are trying to stop a service,
but you can easily do this with the service resource:

Example:
service "nginx" do
action :stop
end

On Mon, Oct 14, 2013 at 11:22 PM, Vladimir Skubriev <skubriev@cvisionlab.com

wrote:

How to check that service is stopped, and if not - stop it ?

For example in this code block:

See if needed http://stackoverflow.com/**questions/14809840/**

installation-of-redmine-with-**bundler-requires-root-passwordhttp://stackoverflow.com/questions/14809840/installation-of-redmine-with-bundler-requires-root-password
bash "bundle_redmine_mylyn" do
cwd "#{node['redmine']['datafs']}/redmine/plugins/redmine_mylyn_
connector"
user node['apache']['user']
code <<-EOH
# We doing source because of interactive shell don't read
our .profile
source #{node['redmine']['home']}/.**rvm/scripts/rvm
bundle install
EOH
end

And Can write some not_if's only_if's for example

do
not_if
not_if
only_if
only_if
end

?

--
Best regards,

CVision Lab System Administrator
Vladmir Skubriev

On 10/15/2013 10:25 AM, Christopher Armstrong wrote:

I'm not sure where in your code sample you are trying to stop a
service, but you can easily do this with the service resource:
http://docs.opscode.com/resource_service.html

Example:
service "nginx" do
action :stop
end

On Mon, Oct 14, 2013 at 11:22 PM, Vladimir Skubriev
<skubriev@cvisionlab.com mailto:skubriev@cvisionlab.com> wrote:

How to check that service is stopped, and if not - stop it ?

For example in this code block:


# See if needed
http://stackoverflow.com/questions/14809840/installation-of-redmine-with-bundler-requires-root-password
bash "bundle_redmine_mylyn" do
  cwd
"#{node['redmine']['datafs']}/redmine/plugins/redmine_mylyn_connector"
  user node['apache']['user']
  code <<-EOH
              # We doing source because of interactive shell don't
read our .profile
              source #{node['redmine']['home']}/.rvm/scripts/rvm
              bundle install
  EOH
end


And Can write some not_if's only_if's for example

do
    not_if
    not_if
    only_if
    only_if
end

?

-- 
Best regards,

CVision Lab System Administrator
Vladmir Skubriev

Okey.

May be i ask answer some incorrectly
I need a check if a service stopped
Before migration of db in this code block

bash "bundle_redmine_mylyn" do
cwd
"#{node['redmine']['datafs']}/redmine/plugins/redmine_mylyn_connector"
user node['apache']['user']
code <<-EOH
# We doing source because of interactive shell don't read
our .profile
source #{node['redmine']['home']}/.rvm/scripts/rvm
bundle install
EOH
not_if SERVICE_IS_STARTED
end

i.e. SERVICE_IS_STARTED in ruby ?

--
Best regards,

CVision Lab System Administrator
Vladmir Skubriev

skubriev@cvisionlab.com writes:

May be i ask answer some incorrectly
I need a check if a service stopped
Before migration of db in this code block

bash "bundle_redmine_mylyn" do
cwd
"#{node['redmine']['datafs']}/redmine/plugins/redmine_mylyn_connector"
user node['apache']['user']
code <<-EOH
# We doing source because of interactive shell don't read
our .profile
source #{node['redmine']['home']}/.rvm/scripts/rvm
bundle install
EOH
not_if SERVICE_IS_STARTED
end

You can guard your bash resource with either a string which will be
executed as a shell command or a block of Ruby code. So:

bash "bundle_redmine_mylyn" do
   cwd 
"#{node['redmine']['datafs']}/redmine/plugins/redmine_mylyn_connector"
   user node['apache']['user']
   code <<-EOH
               # We doing source because of interactive shell don't read 
our .profile
               source #{node['redmine']['home']}/.rvm/scripts/rvm
               bundle install
   EOH
   not_if { File.exist?(some_file) }
end

Does that help?

--
Seth Falcon | Development Lead | Opscode | @sfalcon

On 10/15/2013 06:42 PM, Seth Falcon wrote:

skubriev@cvisionlab.com writes:

May be i ask answer some incorrectly
I need a check if a service stopped
Before migration of db in this code block

bash "bundle_redmine_mylyn" do
cwd
"#{node['redmine']['datafs']}/redmine/plugins/redmine_mylyn_connector"
user node['apache']['user']
code <<-EOH
# We doing source because of interactive shell don't read
our .profile
source #{node['redmine']['home']}/.rvm/scripts/rvm
bundle install
EOH
not_if SERVICE_IS_STARTED
end
You can guard your bash resource with either a string which will be
executed as a shell command or a block of Ruby code. So:

 bash "bundle_redmine_mylyn" do
    cwd
 "#{node['redmine']['datafs']}/redmine/plugins/redmine_mylyn_connector"
    user node['apache']['user']
    code <<-EOH
                # We doing source because of interactive shell don't read
 our .profile
                source #{node['redmine']['home']}/.rvm/scripts/rvm
                bundle install
    EOH
    not_if { File.exist?(some_file) }
 end

Does that help?

That's help of course.
I know how I can do check in bash. Purely theoretically I can use next
condition

not_if { File.exist?(/run/apache2.pid) }

But I was hope that chef has a built-in syntax to check service status.

Because I don't want to waste a time to create and run script if script
should not run.

Thank you for hint.

--
Best regards,

CVision Lab System Administrator
Vladmir Skubriev

Le 2013-10-15 08:22, Vladimir Skubriev a écrit :

How to check
that service is stopped, and if not - stop it ?

For example in this
code block:

See if needed

[1]

bash "bundle_redmine_mylyn" do
cwd

"#{node['redmine']['datafs']}/redmine/plugins/redmine_mylyn_connector"

user node['apache']['user']

code <<-EOH

We doing source because of

interactive shell don't read

our .profile
source
#{node['redmine']['home']}/.rvm/scripts/rvm
bundle install
EOH

end

And Can write some not_if's only_if's for example

do

not_if

not_if
only_if
only_if
end

?

I would use
notifications for this use case, something like:

service "apache2"

bash "bundle_redmine_mylyn" do
cwd

"#{node['redmine']['datafs']}/redmine/plugins/redmine_mylyn_connector"

user node['apache']['user']
code <<-EOH

We doing source because of

interactive shell don't read
our .profile
source
#{node['redmine']['home']}/.rvm/scripts/rvm
bundle install
EOH
action
:nothing
end

ruby_block "stop apache" do

Links:

[1]

Bis from mail client bug ...

Le 2013-10-15 08:22, Vladimir
Skubriev a écrit :

How to check that service is stopped, and if
not - stop it ?

For example in this code block:

See if

needed

[1]

bash "bundle_redmine_mylyn" do
cwd

"#{node['redmine']['datafs']}/redmine/plugins/redmine_mylyn_connector"

user node['apache']['user']

code <<-EOH

We doing source because

of interactive shell don't read

our .profile
source
#{node['redmine']['home']}/.rvm/scripts/rvm
bundle install
EOH

end

And Can write some not_if's only_if's for example

do

not_if
not_if
only_if
only_if
end

?

I would
use notifications for this use case, something like:

bash
"bundle_redmine_mylyn" do
cwd

"#{node['redmine']['datafs']}/redmine/plugins/redmine_mylyn_connector"

user node['apache']['user']
code <<-EOH

We doing source because of

interactive shell don't read
our .profile
source
#{node['redmine']['home']}/.rvm/scripts/rvm
bundle install
EOH
action
:nothing
notifies :start, "service[apache2]
end

service "apache2" do

action :stop

notifies :run, "bash[bundle_redmine_mylyn]"

end

More or less from memory so there may be syntax mistakes with
notifications but the idea is there, if action :stop is too much it may
be trigerred by another ressource (a dummy ruby_block just notyfing or
anything else)

The major drawback I see from this way is that it is
NOT idempotent and will do the same again and again at each chef-run if
there's not way to test the install has to be done or not.

Regards,

Tensibai

Links:

[1]

On 10/16/2013 04:25 PM, Tensibai wrote:

Bis from mail client bug ...

no problem )

I would use notifications for this use case, something like:

bash "bundle_redmine_mylyn" do
cwd
"#{node['redmine']['datafs']}/redmine/plugins/redmine_mylyn_connector"
user node['apache']['user']
code <<-EOH
# We doing source because of interactive shell don't read
our .profile
source #{node['redmine']['home']}/.rvm/scripts/rvm
bundle install
EOH
action :nothing
notifies :start, "service[apache2]
end

service "apache2" do

action :stop

notifies :run, "bash[bundle_redmine_mylyn]"

end

I has many bundle and rake block in a whole cookbook, which is setting
up redmine entirely

I need a check for security of production server data in during operation.

Because application server runned by apache should be stopeed. Bundle is
not a clear example.

Must clear is rake db:migrate, for example.

Of course now i use in the home of all recipes

service "apache2" do

action :stop

end

And at the end of all code

service "apache2" do

action :start

end

But I think this is not good idea.

More or less from memory so there may be syntax mistakes with
notifications but the idea is there, if action :stop is too much it
may be trigerred by another ressource (a dummy ruby_block just
notyfing or anything else)

The major drawback I see from this way is that it is NOT idempotent
and will do the same again and again at each chef-run if there's not
way to test the install has to be done or not.

Regards,

Tensibai

--
Best regards,

CVision Lab System Administrator
Vladmir Skubriev