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
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