/[vz-tools]/trunk/vz-remove.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/vz-remove.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 37 - (show annotations)
Fri Feb 8 21:43:29 2008 UTC (16 years, 2 months ago) by dpavlin
File MIME type: text/plain
File size: 983 byte(s)
stop VE before removal
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Shell qw/rm vzlist vzctl/;
5
6 my $vz = '/vz';
7 my $conf = '/etc/vz/conf';
8
9 my $VEID = shift @ARGV;
10
11 sub vzlist_config {
12 my @c;
13 open( my $cfgs, 'find /etc/vz/conf -maxdepth 1 -name "*.conf" |' ) || die "can't run find: $!";
14 while(<$cfgs>) {
15 chomp;
16 if ( m#^.+/(\d+)\.conf$# ) {
17 if ( -d "$vz/private/$1" ) {
18 push @c, $1;
19 } else {
20 warn "WARNING: have config for $1 but no private directory\n";
21 }
22 } else {
23 warn "SKIPPED: $_\n";
24 }
25 }
26 return @c;
27 }
28
29 die "Usage: $0 VEID\n\n", join("\n",vzlist_config()),"\n" unless $VEID;
30
31 my $c = "$conf/$VEID.conf";
32 if ( -e $c ) {
33 vzctl('stop', $VEID);
34 unlink $c || die "can't remove $c: $!";
35 } else {
36 warn "WARNING: configuration file $c doesn't exist\n";
37 }
38
39 foreach my $p ( qw/root private/ ) {
40 my $c = "$vz/$p/$VEID";
41 if ( -e $c ) {
42 rm('-Rf', $c);
43 die "can't remove $c: $!" if -e $c;
44 } else {
45 warn "WARNING: directory $c doesn't exist\n";
46 }
47 }
48
49 print "OK: $VEID removed\n";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26