diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2013-07-18 20:04:48 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2013-07-18 20:04:48 +0400 |
commit | 34e97b1d41b4dd82e16dd2e8917d1f2c5ea038a4 (patch) | |
tree | 2ff9d444cde27c43f2d0ba7b72c465d3d85cf340 | |
parent | 33464750454b650d1bf53e8ddf66928df453a61b (diff) | |
download | dh-smf-34e97b1d41b4dd82e16dd2e8917d1f2c5ea038a4.tar.gz |
Can handle services on install/upgrade/remove
-rw-r--r-- | autoscripts/postinst-smf-refresh | 10 | ||||
-rw-r--r-- | autoscripts/postinst-smf-start | 12 | ||||
-rw-r--r-- | autoscripts/postrm-smf-delete | 5 | ||||
-rw-r--r-- | autoscripts/prerm-smf-stop | 12 | ||||
-rw-r--r-- | autoscripts/prerm-smf-stop-before-remove | 10 | ||||
-rwxr-xr-x | dh_smf | 27 |
6 files changed, 69 insertions, 7 deletions
diff --git a/autoscripts/postinst-smf-refresh b/autoscripts/postinst-smf-refresh new file mode 100644 index 0000000..f025687 --- /dev/null +++ b/autoscripts/postinst-smf-refresh @@ -0,0 +1,10 @@ +if [ -n "$2" ]; then # only on upgrade +if [ -x /usr/bin/smf_present ] && /usr/bin/smf_present; then + for s in #SERVICES#; do + case `svcstatus $s` in + disabled|temporary-disabled);; + *) /usr/sbin/svcadm -v refresh $s || true;; + esac + done +fi +fi diff --git a/autoscripts/postinst-smf-start b/autoscripts/postinst-smf-start new file mode 100644 index 0000000..2383c76 --- /dev/null +++ b/autoscripts/postinst-smf-start @@ -0,0 +1,12 @@ +if [ -n "$2" ]; then # only on upgrade +if [ -x /usr/bin/smf_present ] && /usr/bin/smf_present; then + for s in #SERVICES#; do + case `svcstatus $s` in + maintenance) /usr/sbin/svcadm -v clear $s || true;; + offline) /usr/sbin/svcadm -v refresh $s || true;; + online) /usr/sbin/svcadm -v restart $s || true;; + temporary-disabled) /usr/sbin/svcadm -v enable $s || true;; + esac + done +fi +fi diff --git a/autoscripts/postrm-smf-delete b/autoscripts/postrm-smf-delete new file mode 100644 index 0000000..4d33798 --- /dev/null +++ b/autoscripts/postrm-smf-delete @@ -0,0 +1,5 @@ +if [ "$1" = remove ]; then +if [ -x /usr/bin/smf_present ] && /usr/bin/smf_present; then + /usr/sbin/svccfg delete -f #SERVICES# || true; +fi +fi diff --git a/autoscripts/prerm-smf-stop b/autoscripts/prerm-smf-stop new file mode 100644 index 0000000..bdbeb0c --- /dev/null +++ b/autoscripts/prerm-smf-stop @@ -0,0 +1,12 @@ +if [ -x /usr/bin/smf_present ] && /usr/bin/smf_present; then + if [ "$1" = "remove" ]; then + temp="" + else + temp="-t" + fi + for s in #SERVICES#; do + case `svcstatus $s` in + online|offline) /usr/sbin/svcadm -v disable $temp -s $s;; + esac + done +fi diff --git a/autoscripts/prerm-smf-stop-before-remove b/autoscripts/prerm-smf-stop-before-remove new file mode 100644 index 0000000..5b4324a --- /dev/null +++ b/autoscripts/prerm-smf-stop-before-remove @@ -0,0 +1,10 @@ +if [ "$1" = remove ]; then +if [ -x /usr/bin/smf_present ] && /usr/bin/smf_present; then + for s in #SERVICES#; do + case `svcstatus $s` in + disabled);; + *) /usr/sbin/svcadm -v disable -s $s;; + esac + done +fi +fi @@ -151,7 +151,7 @@ foreach my $package ( @{ $dh{DOPACKAGES} } ) { if ( exists $xml->{'service'}->{'create_default_instance'} ) { push @services, { - 'name' => "$service_base:default", + 'name' => "svc:/$service_base:default", 'enabled' => $xml->{'service'}->{'create_default_instance'}->{'enabled'}, 'exec_method' => $xml->{'service'}->{'exec_method'}, @@ -168,7 +168,7 @@ foreach my $package ( @{ $dh{DOPACKAGES} } ) { { push @services, { - 'name' => "$service_base:$k", + 'name' => "svc:/$service_base:$k", 'enabled' => $v->{'enabled'}, 'exec_method' => $v->{'exec_method'} // $xml->{'service'}->{'exec_method'}, @@ -193,10 +193,9 @@ foreach my $package ( @{ $dh{DOPACKAGES} } ) { error("No SMF services found in @manifests") unless @services; - print Dumper(@services); # debug - if ( !$dh{NOSCRIPTS} ) { my @pkg_manifests = map { s!\Q$tmp\E/*!/!; $_ } @manifests; + my @svcs = (); autoscript( $package, 'postinst', 'postinst-smf-import', "s|#MANIFESTS#|@pkg_manifests|" ); @@ -205,22 +204,36 @@ foreach my $package ( @{ $dh{DOPACKAGES} } ) { my @daemons_restart = grep { $_->{'upgrade'} eq 'restart' } @daemons; my @daemons_refresh = grep { $_->{'upgrade'} eq 'refresh' } @daemons; if (@daemons_stop) { - my @svcs = map { $_->{'name'} } @daemons_stop; + @svcs = map { $_->{'name'} } @daemons_stop; autoscript( $package, 'prerm', 'prerm-smf-stop', "s|#SERVICES#|@svcs|" ); autoscript( $package, 'postinst', 'postinst-smf-start', "s|#SERVICES#|@svcs|" ); } if (@daemons_restart) { - my @svcs = map { $_->{'name'} } @daemons_restart; + @svcs = map { $_->{'name'} } @daemons_restart; autoscript( $package, 'postinst', 'postinst-smf-start', "s|#SERVICES#|@svcs|" ); } if (@daemons_refresh) { - my @svcs = map { $_->{'name'} } @daemons_refresh; + @svcs = map { $_->{'name'} } @daemons_refresh; autoscript( $package, 'postinst', 'postinst-smf-refresh', "s|#SERVICES#|@svcs|" ); } + + # Disable and delete services on removal. + # Other services (upgrade=stop) are already disabled. + my @services_nonstop = grep { $_->{'upgrade'} ne 'stop' } @services; + if (@services_nonstop) { + @svcs = map { $_->{'name'} } @services_nonstop; + autoscript( $package, 'prerm', 'prerm-smf-stop-before-remove', + "s|#SERVICES#|@svcs|" ); + } + + # Remove all services. + @svcs = map { $_->{'name'} } @services; + autoscript( $package, 'postrm', 'postrm-smf-delete', + "s|#SERVICES#|@svcs|" ); } } |