Your SlideShare is downloading. ×
Ubic
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Ubic

1,890
views

Published on

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,890
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide



















  • Transcript

    • 1. UBIC http://github.com/berekuk/ubic
    • 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