SlideShare ist ein Scribd-Unternehmen logo
1 von 19
UBIC
http://github.com/berekuk/ubic
UBIC
Toolkit for writing daemons, init scripts
          and services in perl.

          Batteries included.
case "$1" in
                                        Usual way
start)
 check_for_no_start
 check_privsep_dir
    echo -n "Starting OpenBSD Secure Shell server: sshd"
 start-stop-daemon --start --quiet --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS
    echo "."
 ;;
stop)
    echo -n "Stopping OpenBSD Secure Shell server: sshd"
 start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/sshd.pid
    echo "."
 ;;

reload|force-reload)
 check_for_no_start
 check_config
    echo -n "Reloading OpenBSD Secure Shell server's configuration"
 start-stop-daemon --stop --signal 1 --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd
 echo "."
 ;;

restart)
 check_privsep_dir
 check_config
    echo -n "Restarting OpenBSD Secure Shell server: sshd"
 start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile /var/run/sshd.pid
 check_for_no_start
 start-stop-daemon --start --quiet --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS
 echo "."
 ;;

*)
 echo "Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart}"
Usual way
   They are ugly.
 They are verbose.
They are full of hacks.
Usual way
                  ...and they don’t work consistently:
root@v5114:/etc/init.d# /etc/init.d/nscd start
Starting Name Service Cache Daemon: nscd (already running).

root@v5114:~# /etc/init.d/cron start
Starting periodic command scheduler: crond failed!

root@v5114:~# /etc/init.d/ssh start
root@v5114:~# SD Secure Shell server: sshdroot@v5114:~#

root@v5114:/etc/init.d# /etc/init.d/nscd status
Status of Name Service Cache Daemon service: not running.

root@v5114:/etc/init.d# /etc/init.d/cron status
Usage: /etc/init.d/cron {start|stop|restart|reload|force-reload}.

root@v5114:/etc/init.d# /etc/init.d/ssh status
Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart}
Better way
root # cat /etc/ubic/service/sleeping-daemon
use Ubic::Service::SimpleDaemon;

Ubic::Service::SimpleDaemon->new({
     bin => '/bin/sleep 1000',
});
Better way
root # ubic start sleeping-daemon
Starting sleeping-daemon... started

root # ubic start sleeping-daemon
Starting sleeping-daemon... already running

root # ubic status
sleeping-daemon
   running
ubic-ping
 running
LSB 4.0 conformance
 http://refspecs.freestandards.org/LSB_4.0.0/LSB-Core-
        generic/LSB-Core-generic/iniscrptact.html
start
start the service
stop
stop the service
restart
stop and restart the service if the service is already running, otherwise start the service
try-restart
restart the service if the service is already running
reload
cause the configuration of the service to be reloaded without actually stopping and
restarting the service
force-reload
cause the configuration to be reloaded if the service supports this, otherwise restart the
service if it is running
status
print the current status of the service
Hierarchical services
mmcleric $ ubic status
Not a root, printing cached statuses
ubic-ping
 running
yandex
  yandex.swift-blogs-a
 running
  yandex.swift-blogs-b
 running
  yandex.swift-blogs-c
 running
  yandex.swift-blogs-d
 running
  yandex.swift-blogs-e
 running
yandex-ppb-bulca-ds
  yandex-ppb-bulca-ds.bulca_items
 running
  yandex-ppb-bulca-ds.bulca_items_retry
    off
  yandex-ppb-bulca-ds.index_blogs
 running
  yandex-ppb-bulca-ds.merge_swift
 running
yandex-ppb-cache
  yandex-ppb-cache.swift-blogs
     yandex-ppb-cache.swift-blogs.lighttpd
 running
     yandex-ppb-cache.swift-blogs.fastcgi
 running
Hierarchical services
root # ubic restart -f yandex-ppb-cache
yandex
  Restarting yandex.swift-blogs-a... restarted
  Restarting yandex.swift-blogs-b... restarted
  Restarting yandex.swift-blogs-c... restarted
  Restarting yandex.swift-blogs-d... restarted
  Restarting yandex.swift-blogs-e... restarted
SysV init scripts
root # cat /etc/init.d/sleeping-daemon
#!/usr/bin/perl
use Ubic::Run; # that’s all!
Watchdog
root # killall sleep

root # ubic status
sleeping-daemon not running
ubic-ping       running

root # ubic-watchdog
[ Fri Jun 11 03:06:32 2010 ]
sleeping-daemon is broken, restarting
HTTP ping
mmcleric $ wget -q -O - 'http://localhost:12345/status/service/sleeping-
daemon'
ok

mmcleric $ wget -O - 'http://localhost:12345/status/service/abc'
--03:31:21-- http://localhost:12345/status/service/abc
       => `-'
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:12345... connected.
HTTP request sent, awaiting response... 404 Not found
03:31:21 ERROR 404: Not found.
Non-root users
root # cat /etc/ubic/service/sleeping-daemon
use Ubic::Service::SimpleDaemon;

Ubic::Service::SimpleDaemon->new({
     bin => '/bin/sleep 1000',
      user => 'nobody',
});
Common classes
mmcleric $ cat /etc/ubic/service/something
...
Ubic::Service::Common->new({
    start => sub {
       start_daemon({
           bin    => '/usr/bin/something’,
           pidfile => '/var/tmp/something.pid',
           stdout => "/var/log/something.log",
           stderr => "/var/log/something.err.log",
           ubic_log => "/var/log/something.ubic.log",
       });
    },
    stop => sub {
       stop_daemon('/var/log/something.pid');
    },
    status => sub {
       check_daemon('/var/log/something.pid') ? 'running' : 'not running';
    },
    user => 'www-data',
});
Common classes
mmcleric $ cat /etc/ubic/service/something
...
Ubic::Service::PSGI->new({
    server => 'Starman',
    app => '/usr/share/something.psgi',
    server_args => { workers => 3,
               port => $port },
    app_name => "something",
    port   => $port,
    ubic_log => "$log_dir/ubic.log",
    stdout => "$log_dir/stdout.log",
    stderr => "$log_dir/stderr.log",
    user    => "www-data",
});
Common classes
    Ubic::Service::Common
     Ubic::Service::Lighttpd
   Ubic::Service::Memcached
   Ubic::Service::ProcManager
       Ubic::Service::PSGI
  Ubic::Service::SimpleDaemon
     Ubic::Service::Skeleton

     (not all of them are on cpan - yet)
Statistics
  Usage in Yandex:
23 different packages
     19 clusters
      457 hosts
Credits
             UBIC:
http://github.com/berekuk/ubic
http://search.cpan.org/dist/Ubic

               Me:
 Vyacheslav Matyukhin, Yandex
http://friendfeed.com/mmcleric
    mailto:me@berekuk.ru
 jabber:mmcleric@gmail.com

Weitere ähnliche Inhalte

Was ist angesagt?

Testing your infrastructure with litmus
Testing your infrastructure with litmusTesting your infrastructure with litmus
Testing your infrastructure with litmusBram Vogelaar
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricksbcoca
 
Instruction: dev environment
Instruction: dev environmentInstruction: dev environment
Instruction: dev environmentSoshi Nemoto
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stackBram Vogelaar
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0bcoca
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteBram Vogelaar
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteBram Vogelaar
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingSteve Rhoades
 
Ansible fest Presentation slides
Ansible fest Presentation slidesAnsible fest Presentation slides
Ansible fest Presentation slidesAaron Carey
 
Docker command
Docker commandDocker command
Docker commandEric Ahn
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesBram Vogelaar
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestrationbcoca
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Tom Croucher
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansiblebcoca
 
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero ClicksHow to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero ClicksCarlos Sanchez
 
Observability with Consul Connect
Observability with Consul ConnectObservability with Consul Connect
Observability with Consul ConnectBram Vogelaar
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Brian Schott
 

Was ist angesagt? (20)

Testing your infrastructure with litmus
Testing your infrastructure with litmusTesting your infrastructure with litmus
Testing your infrastructure with litmus
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
Instruction: dev environment
Instruction: dev environmentInstruction: dev environment
Instruction: dev environment
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stack
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suite
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suite
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
 
Ansible fest Presentation slides
Ansible fest Presentation slidesAnsible fest Presentation slides
Ansible fest Presentation slides
 
Docker command
Docker commandDocker command
Docker command
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet Profiles
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
Top Node.js Metrics to Watch
Top Node.js Metrics to WatchTop Node.js Metrics to Watch
Top Node.js Metrics to Watch
 
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero ClicksHow to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
 
Observability with Consul Connect
Observability with Consul ConnectObservability with Consul Connect
Observability with Consul Connect
 
Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2Using Ansible Dynamic Inventory with Amazon EC2
Using Ansible Dynamic Inventory with Amazon EC2
 
Configuration Management in Ansible
Configuration Management in Ansible Configuration Management in Ansible
Configuration Management in Ansible
 

Andere mochten auch

A Unique Business Blogging Strategy
A Unique Business Blogging StrategyA Unique Business Blogging Strategy
A Unique Business Blogging StrategyChristine Rochelle
 
A 3-869e531bc383bc2db2d9e22b083ea95f5f0fa454-141125232253-conversion-gate02
A 3-869e531bc383bc2db2d9e22b083ea95f5f0fa454-141125232253-conversion-gate02A 3-869e531bc383bc2db2d9e22b083ea95f5f0fa454-141125232253-conversion-gate02
A 3-869e531bc383bc2db2d9e22b083ea95f5f0fa454-141125232253-conversion-gate02Chris Humphreys
 
Build Your Business Blog - Christine Rochelle
Build Your Business Blog - Christine RochelleBuild Your Business Blog - Christine Rochelle
Build Your Business Blog - Christine RochelleChristine Rochelle
 
DMSC - Automotive SEO Content Follow Up Webinar
DMSC - Automotive SEO Content Follow Up WebinarDMSC - Automotive SEO Content Follow Up Webinar
DMSC - Automotive SEO Content Follow Up WebinarChristine Rochelle
 
The Hutchinson’S Landscape 2010’
The  Hutchinson’S  Landscape 2010’The  Hutchinson’S  Landscape 2010’
The Hutchinson’S Landscape 2010’biznurse
 
How to-add-clickable-links-to-slideshare
How to-add-clickable-links-to-slideshareHow to-add-clickable-links-to-slideshare
How to-add-clickable-links-to-slideshareChris Humphreys
 
MK Valenti Before And After
MK Valenti Before And AfterMK Valenti Before And After
MK Valenti Before And Aftermkvalenti
 
Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)Vyacheslav Matyukhin
 
Business Entrepreneurs
Business EntrepreneursBusiness Entrepreneurs
Business EntrepreneursCarly Taylor
 
Writing is My Therapy Because I Have No Money For Drugs
Writing is My Therapy Because I Have No Money For DrugsWriting is My Therapy Because I Have No Money For Drugs
Writing is My Therapy Because I Have No Money For DrugsChristine Rochelle
 
A Cohesive Social Media Strategy
A Cohesive Social Media StrategyA Cohesive Social Media Strategy
A Cohesive Social Media StrategyChristine Rochelle
 
Manufacturing Pasts - 16th June 2012
Manufacturing Pasts - 16th June 2012Manufacturing Pasts - 16th June 2012
Manufacturing Pasts - 16th June 2012taniarowlett
 
3 Social Strategies Your Brand is Missing
3 Social Strategies Your Brand is Missing3 Social Strategies Your Brand is Missing
3 Social Strategies Your Brand is MissingChristine Rochelle
 
Ubic slides (Moscow.pm meeting, Nov 2010)
Ubic slides (Moscow.pm meeting, Nov 2010)Ubic slides (Moscow.pm meeting, Nov 2010)
Ubic slides (Moscow.pm meeting, Nov 2010)Vyacheslav Matyukhin
 
How to add clickable links to slideshare
How to add clickable links to slideshareHow to add clickable links to slideshare
How to add clickable links to slideshareChris Humphreys
 
Love’em Or Lose’em
Love’em Or Lose’emLove’em Or Lose’em
Love’em Or Lose’emBogdan
 

Andere mochten auch (18)

A Unique Business Blogging Strategy
A Unique Business Blogging StrategyA Unique Business Blogging Strategy
A Unique Business Blogging Strategy
 
A 3-869e531bc383bc2db2d9e22b083ea95f5f0fa454-141125232253-conversion-gate02
A 3-869e531bc383bc2db2d9e22b083ea95f5f0fa454-141125232253-conversion-gate02A 3-869e531bc383bc2db2d9e22b083ea95f5f0fa454-141125232253-conversion-gate02
A 3-869e531bc383bc2db2d9e22b083ea95f5f0fa454-141125232253-conversion-gate02
 
Build Your Business Blog - Christine Rochelle
Build Your Business Blog - Christine RochelleBuild Your Business Blog - Christine Rochelle
Build Your Business Blog - Christine Rochelle
 
DMSC - Automotive SEO Content Follow Up Webinar
DMSC - Automotive SEO Content Follow Up WebinarDMSC - Automotive SEO Content Follow Up Webinar
DMSC - Automotive SEO Content Follow Up Webinar
 
The Hutchinson’S Landscape 2010’
The  Hutchinson’S  Landscape 2010’The  Hutchinson’S  Landscape 2010’
The Hutchinson’S Landscape 2010’
 
How to-add-clickable-links-to-slideshare
How to-add-clickable-links-to-slideshareHow to-add-clickable-links-to-slideshare
How to-add-clickable-links-to-slideshare
 
MK Valenti Before And After
MK Valenti Before And AfterMK Valenti Before And After
MK Valenti Before And After
 
Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)
 
Uitnodiging
UitnodigingUitnodiging
Uitnodiging
 
Business Entrepreneurs
Business EntrepreneursBusiness Entrepreneurs
Business Entrepreneurs
 
Writing is My Therapy Because I Have No Money For Drugs
Writing is My Therapy Because I Have No Money For DrugsWriting is My Therapy Because I Have No Money For Drugs
Writing is My Therapy Because I Have No Money For Drugs
 
A Cohesive Social Media Strategy
A Cohesive Social Media StrategyA Cohesive Social Media Strategy
A Cohesive Social Media Strategy
 
Manufacturing Pasts - 16th June 2012
Manufacturing Pasts - 16th June 2012Manufacturing Pasts - 16th June 2012
Manufacturing Pasts - 16th June 2012
 
3 Social Strategies Your Brand is Missing
3 Social Strategies Your Brand is Missing3 Social Strategies Your Brand is Missing
3 Social Strategies Your Brand is Missing
 
Ubic slides (Moscow.pm meeting, Nov 2010)
Ubic slides (Moscow.pm meeting, Nov 2010)Ubic slides (Moscow.pm meeting, Nov 2010)
Ubic slides (Moscow.pm meeting, Nov 2010)
 
How to add clickable links to slideshare
How to add clickable links to slideshareHow to add clickable links to slideshare
How to add clickable links to slideshare
 
Love’em Or Lose’em
Love’em Or Lose’emLove’em Or Lose’em
Love’em Or Lose’em
 
Twitter 101 For Car Dealers
Twitter 101 For Car DealersTwitter 101 For Car Dealers
Twitter 101 For Car Dealers
 

Ähnlich wie UBIC Toolkit for Writing Daemons and Services in Perl

Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slidesharetomcopeland
 
Pursue container architecture with mincs
Pursue container architecture with mincsPursue container architecture with mincs
Pursue container architecture with mincsYuki Nishiwaki
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newYiwei Ma
 
PFIセミナー資料 H27.10.22
PFIセミナー資料 H27.10.22PFIセミナー資料 H27.10.22
PFIセミナー資料 H27.10.22Yuya Takei
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierCarlos Sanchez
 
Docker in Action
Docker in ActionDocker in Action
Docker in ActionSimon Su
 
ByPat博客出品Lvs+keepalived
ByPat博客出品Lvs+keepalivedByPat博客出品Lvs+keepalived
ByPat博客出品Lvs+keepalivedredhat9
 
Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)Ben Hall
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slidesDocker, Inc.
 
Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year laterChristian Ortner
 
Control your deployments with Capistrano
Control your deployments with CapistranoControl your deployments with Capistrano
Control your deployments with CapistranoRamazan K
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetOmar Reygaert
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOpsОмские ИТ-субботники
 
Harmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetHarmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetAchieve Internet
 
Linux Du Jour
Linux Du JourLinux Du Jour
Linux Du Jourmwedgwood
 

Ähnlich wie UBIC Toolkit for Writing Daemons and Services in Perl (20)

Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 
Cooking with Chef
Cooking with ChefCooking with Chef
Cooking with Chef
 
Puppet @ Seat
Puppet @ SeatPuppet @ Seat
Puppet @ Seat
 
Pursue container architecture with mincs
Pursue container architecture with mincsPursue container architecture with mincs
Pursue container architecture with mincs
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
 
PFIセミナー資料 H27.10.22
PFIセミナー資料 H27.10.22PFIセミナー資料 H27.10.22
PFIセミナー資料 H27.10.22
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
 
Docker in Action
Docker in ActionDocker in Action
Docker in Action
 
FreeBSD: Dev to Prod
FreeBSD: Dev to ProdFreeBSD: Dev to Prod
FreeBSD: Dev to Prod
 
Puppet
PuppetPuppet
Puppet
 
ByPat博客出品Lvs+keepalived
ByPat博客出品Lvs+keepalivedByPat博客出品Lvs+keepalived
ByPat博客出品Lvs+keepalived
 
Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slides
 
Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year later
 
Control your deployments with Capistrano
Control your deployments with CapistranoControl your deployments with Capistrano
Control your deployments with Capistrano
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
 
Harmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetHarmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and Puppet
 
Linux Du Jour
Linux Du JourLinux Du Jour
Linux Du Jour
 

Kürzlich hochgeladen

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Kürzlich hochgeladen (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

UBIC Toolkit for Writing Daemons and Services in Perl

  • 2. UBIC Toolkit for writing daemons, init scripts and services in perl. Batteries included.
  • 3. case "$1" in Usual way start) check_for_no_start check_privsep_dir echo -n "Starting OpenBSD Secure Shell server: sshd" start-stop-daemon --start --quiet --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS echo "." ;; stop) echo -n "Stopping OpenBSD Secure Shell server: sshd" start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/sshd.pid echo "." ;; reload|force-reload) check_for_no_start check_config echo -n "Reloading OpenBSD Secure Shell server's configuration" start-stop-daemon --stop --signal 1 --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd echo "." ;; restart) check_privsep_dir check_config echo -n "Restarting OpenBSD Secure Shell server: sshd" start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile /var/run/sshd.pid check_for_no_start start-stop-daemon --start --quiet --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS echo "." ;; *) echo "Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart}"
  • 4. Usual way They are ugly. They are verbose. They are full of hacks.
  • 5. Usual way ...and they don’t work consistently: root@v5114:/etc/init.d# /etc/init.d/nscd start Starting Name Service Cache Daemon: nscd (already running). root@v5114:~# /etc/init.d/cron start Starting periodic command scheduler: crond failed! root@v5114:~# /etc/init.d/ssh start root@v5114:~# SD Secure Shell server: sshdroot@v5114:~# root@v5114:/etc/init.d# /etc/init.d/nscd status Status of Name Service Cache Daemon service: not running. root@v5114:/etc/init.d# /etc/init.d/cron status Usage: /etc/init.d/cron {start|stop|restart|reload|force-reload}. root@v5114:/etc/init.d# /etc/init.d/ssh status Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart}
  • 6. Better way root # cat /etc/ubic/service/sleeping-daemon use Ubic::Service::SimpleDaemon; Ubic::Service::SimpleDaemon->new({ bin => '/bin/sleep 1000', });
  • 7. Better way root # ubic start sleeping-daemon Starting sleeping-daemon... started root # ubic start sleeping-daemon Starting sleeping-daemon... already running root # ubic status sleeping-daemon running ubic-ping running
  • 8. LSB 4.0 conformance http://refspecs.freestandards.org/LSB_4.0.0/LSB-Core- generic/LSB-Core-generic/iniscrptact.html start start the service stop stop the service restart stop and restart the service if the service is already running, otherwise start the service try-restart restart the service if the service is already running reload cause the configuration of the service to be reloaded without actually stopping and restarting the service force-reload cause the configuration to be reloaded if the service supports this, otherwise restart the service if it is running status print the current status of the service
  • 9. Hierarchical services mmcleric $ ubic status Not a root, printing cached statuses ubic-ping running yandex yandex.swift-blogs-a running yandex.swift-blogs-b running yandex.swift-blogs-c running yandex.swift-blogs-d running yandex.swift-blogs-e running yandex-ppb-bulca-ds yandex-ppb-bulca-ds.bulca_items running yandex-ppb-bulca-ds.bulca_items_retry off yandex-ppb-bulca-ds.index_blogs running yandex-ppb-bulca-ds.merge_swift running yandex-ppb-cache yandex-ppb-cache.swift-blogs yandex-ppb-cache.swift-blogs.lighttpd running yandex-ppb-cache.swift-blogs.fastcgi running
  • 10. Hierarchical services root # ubic restart -f yandex-ppb-cache yandex Restarting yandex.swift-blogs-a... restarted Restarting yandex.swift-blogs-b... restarted Restarting yandex.swift-blogs-c... restarted Restarting yandex.swift-blogs-d... restarted Restarting yandex.swift-blogs-e... restarted
  • 11. SysV init scripts root # cat /etc/init.d/sleeping-daemon #!/usr/bin/perl use Ubic::Run; # that’s all!
  • 12. Watchdog root # killall sleep root # ubic status sleeping-daemon not running ubic-ping running root # ubic-watchdog [ Fri Jun 11 03:06:32 2010 ] sleeping-daemon is broken, restarting
  • 13. HTTP ping mmcleric $ wget -q -O - 'http://localhost:12345/status/service/sleeping- daemon' ok mmcleric $ wget -O - 'http://localhost:12345/status/service/abc' --03:31:21-- http://localhost:12345/status/service/abc => `-' Resolving localhost... 127.0.0.1 Connecting to localhost|127.0.0.1|:12345... connected. HTTP request sent, awaiting response... 404 Not found 03:31:21 ERROR 404: Not found.
  • 14. Non-root users root # cat /etc/ubic/service/sleeping-daemon use Ubic::Service::SimpleDaemon; Ubic::Service::SimpleDaemon->new({ bin => '/bin/sleep 1000', user => 'nobody', });
  • 15. Common classes mmcleric $ cat /etc/ubic/service/something ... Ubic::Service::Common->new({ start => sub { start_daemon({ bin => '/usr/bin/something’, pidfile => '/var/tmp/something.pid', stdout => "/var/log/something.log", stderr => "/var/log/something.err.log", ubic_log => "/var/log/something.ubic.log", }); }, stop => sub { stop_daemon('/var/log/something.pid'); }, status => sub { check_daemon('/var/log/something.pid') ? 'running' : 'not running'; }, user => 'www-data', });
  • 16. Common classes mmcleric $ cat /etc/ubic/service/something ... Ubic::Service::PSGI->new({ server => 'Starman', app => '/usr/share/something.psgi', server_args => { workers => 3, port => $port }, app_name => "something", port => $port, ubic_log => "$log_dir/ubic.log", stdout => "$log_dir/stdout.log", stderr => "$log_dir/stderr.log", user => "www-data", });
  • 17. Common classes Ubic::Service::Common Ubic::Service::Lighttpd Ubic::Service::Memcached Ubic::Service::ProcManager Ubic::Service::PSGI Ubic::Service::SimpleDaemon Ubic::Service::Skeleton (not all of them are on cpan - yet)
  • 18. Statistics Usage in Yandex: 23 different packages 19 clusters 457 hosts
  • 19. Credits UBIC: http://github.com/berekuk/ubic http://search.cpan.org/dist/Ubic Me: Vyacheslav Matyukhin, Yandex http://friendfeed.com/mmcleric mailto:me@berekuk.ru jabber:mmcleric@gmail.com

Hinweis der Redaktion