[Box Backup] Boxbackup as a service on Windows...

Per Thomsen boxbackup at fluffy.co.uk
Thu Oct 21 01:32:56 BST 2004


This is a multi-part message in MIME format.
--------------050600060602050908040005
Content-Type: multipart/alternative;
 boundary="------------040003000409040502020707"


--------------040003000409040502020707
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Here are the things that I have put together as the documentation for 
installing boxbackup on Windows... Let me know if you find anything that 
isn't correct, or could be improved.

I have attached 2 files:

    * install-cygwin-service.pl, which is run after bbackupd is ready to
      run (all certs are done, etc.), to create the Windows Service and
      start it.
    * remove-cygwin-service.sh. This simply removes the service, if you
      are stopping backups on the machine in question.

For the purposes of this email, I'm assuming that you have a cygwin 
parcel already built and installed. I submitted a more lengthy 
description of the entire build/install process on Windows to Ben for 
inclusion on the web site. If you want that in email, please let me 
know, and I'll send it out.

Here is the documentation I came up with for the scripts.


      Making boxbackup run as a Windows Service

For most installations (with the default locations for config files, 
etc.) running the install-cygwin-service.pl script will complete the 
installation painlessly, and you will have a running bbackupd after 
completing the installation, and whenever you reboot.

Simply run the script:

perl install-cygwin-service.pl

The service can be monitored in the Windows Service Manager. It is named 
boxbackup.

For non-standard configurations, there are command-line options to point 
the script to the bbackupd.conf config file, and the bbackupd.exe 
executable:

perl install-cygwin-service.pl [-c <path-to-bbackupd-config-file>] [-e 
<path-to-bbackupd-executable-file>]


      Removing the Service

If you decide not to run backups on a machine anymore, simply remove the 
service by running:

sh remove-cygwin-service.sh


-- 
Per Reedtz Thomsen | The Reedtz Corporation | F: 209 883 4119
V: 209 883 4102    |   pthomsen at reedtz.com  | C: 415 425 4025
GPG ID: 1209784F   |  Yahoo! Chat: pthomsen | AIM: pthomsen


--------------040003000409040502020707
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Here are the things that I have put together as the documentation for
installing boxbackup on Windows... Let me know if you find anything
that isn't correct, or could be improved.<br>
<br>
I have attached 2 files: <br>
<ul>
  <li>install-cygwin-service.pl, which is run after bbackupd is ready
to run (all certs are done, etc.), to create the Windows Service and
start it.</li>
  <li>remove-cygwin-service.sh. This simply removes the service, if you
are stopping backups on the machine in question.</li>
</ul>
For the purposes of this email, I'm assuming that you have a cygwin
parcel already built and installed. I submitted a more lengthy
description of the entire build/install process on Windows to Ben for
inclusion on the web site. If you want that in email, please let me
know, and I'll send it out.<br>
<br>
Here is the documentation I came up with for the scripts.<br>
<h3>Making boxbackup run as a Windows Service</h3>
For most installations (with the default locations for config files,
etc.) running the install-cygwin-service.pl script will complete the
installation painlessly, and you will have a running bbackupd after
completing the installation, and whenever you reboot.<br>
<br>
Simply run the script:<br>
<br>
perl install-cygwin-service.pl<br>
<br>
The service can be monitored in the Windows Service Manager. It is
named boxbackup.<br>
<br>
For non-standard configurations, there are command-line options to
point the script to the bbackupd.conf config file, and the bbackupd.exe
executable:<br>
<br>
perl install-cygwin-service.pl [-c
<path-to-bbackupd-config-file>] [-e
<path-to-bbackupd-executable-file>]<br>
<h3>Removing the Service</h3>
If you decide not to run backups on a machine anymore, simply remove
the service by running:<br>
<br>
sh remove-cygwin-service.sh<br>
<br>
<br>
<pre class="moz-signature" cols="72">-- 
Per Reedtz Thomsen | The Reedtz Corporation | F: 209 883 4119
V: 209 883 4102    |   <a class="moz-txt-link-abbreviated"
 href="mailto:pthomsen at reedtz.com">pthomsen at reedtz.com</a>  | C: 415 425 4025
GPG ID: 1209784F   |  Yahoo! Chat: pthomsen | AIM: pthomsen
</pre>
</body>
</html>

--------------040003000409040502020707--

--------------050600060602050908040005
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
 name="remove-cygwin-service.sh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="remove-cygwin-service.sh"

#!/bin/bash

# Contributed to the boxbackup project by Per Reedtz Thomsen. pthomsen at reedtz.com

# This script removes the 'boxbackup' service from the Windows service manager
# using the cygrunsrv utility. 

# Date      Who                      Comments
# 20041005  pthomsen at reedtz.com      Created 

cygrunsrv -R boxbackup

echo "Service \"boxbackup\" removed."



--------------050600060602050908040005
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
 name="install-cygwin-service.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="install-cygwin-service.pl"

#!/usr/bin/perl -w


# Contributed to the boxbackup project by Per Reedtz Thomsen. pthomsen at reedtz.com

# This script reads the config file for boxbackup, and changes the mode
# of the directory named by 'DataDirectory' and any files there. Also,
# the files pointed to by the 'CommandSocket' and 'PidFile' configuration
# parameters will be chmod'ed to be read-write by all.
# The Windows services are created and started using the 'cygrunsrv' utility.

# Date      Who                      Comments
# 20041005  pthomsen at reedtz.com      Created 
# 20041020  pthomsen at reedtz.com	     Switched to using Getopt::Std for cmd-line things.

use strict;

use Getopt::Std;
getopt('ce');
our ($opt_c, $opt_e);
# Figure out the config file to use. Default is /etc/box/bbackupd.conf
my $confFile = (defined($opt_c) ? $opt_c :  "/etc/box/bbackupd.conf");
# Figure out the bbaackupd executable to use. Default is /usr/local/bin/bbackupd.exe
my $exeFile = (defined($opt_e) ? $opt_e :  "/usr/local/bin/bbackupd.exe");

die "File $confFile does not exist. Please provide the full path to the bbackupd configuration file.\n" if !(-f $confFile);
die "Can't read $confFile. Permission denied. Please chmod the file so I can read it.\n" if !(-r $confFile);
die "File $exeFile does not exist. Please provide the full path to the bbackupd.exe file.\n" if !(-f $exeFile);
die "File $exeFile is not executable. Please provide the full path to the correct bbackupd.exe file.\n" if !(-x $exeFile);

# print "Config: $confFile\n";

my $dataDir;
my $cmdSocket;
my $pidFile;

open (CONFIG, "<$confFile") or die "Can't open $confFile: $!\n";

# Read the confgiguration file, and pull the DataDirectory, CommandSocket, and PidFile parameters.
while (<CONFIG>)
{
    
    if (/^\s*DataDirectory\s*=\s*([^\n\s]+)\s*\n/)
    {
	$dataDir = $1;
	next;
    }

    if (/^\s*CommandSocket\s*=\s*([^\n\s]+)\s*\n/)
    {
	$cmdSocket = $1;
	next;
    }
    if (/^\s*PidFile\s*=\s*([^\n\s]+)\s*\n/)
    {
	$pidFile = $1;
	next;
    }
}

# check that we got all the parameters from the file. If not, die.
if ((!defined($dataDir)) || (!defined($cmdSocket)) || (!defined($pidFile)))
{
    die "Could not read config parameters from $confFile. Values retrieved:\n\tDataDirectory = $dataDir\n\tCommandSocket = $cmdSocket\n\tPidFile = $pidFile\n";
}


print  "Parameters retrieved from $confFile. Values:\n\tDataDirectory = $dataDir\n\tCommandSocket = $cmdSocket\n\tPidFile = $pidFile\n";
print "chmod...";
# change the mode of the files/dirs retrieved.
chmod(0777, $dataDir) or die "Can't chmod $dataDir: $!\n";
chmod(0666, "$dataDir/*") or die "Can't chmod $dataDir/*: $!\n";
chmod(0666, $pidFile) or die "Can't chmod $pidFile: $!\n";
chmod(0755, $cmdSocket) or die "Can't chmod $cmdSocket: $!\n";
print " Done.\n";

# Now install the service using cygrunsrv.
# Details: 
#   -I <svc_name>      Install a service. svc_name is the name under which the
#                      service will appear in the Windows Service Manager
#   -p <path_to_exe>   Path to the executable.
#   -a <options>       Command line options to the executable.
#   -f <description>   Description of the service.
#   -o                 Attempt clean exit of service during system shutdown

print "Installing boxbackup service...";
my $sysCmd = "cygrunsrv.exe -I boxbackup -p " . $exeFile;
$sysCmd .= " -a \"" . $confFile . " SINGLEPROCESS\"";
$sysCmd .= " -o -f \"Online Backup System by Ben Summer\"";
print "$sysCmd\n";
my $output = qx($sysCmd);
die "cygrunsrv failed to install service. Error Message: $output\n" if($output ne "");
print " Done.\n";


# Start the service
# Details:
#   -S <svc_name>     Start a service. svc_name is the name of the (installed)
#                     service to start.

print "Starting boxbackup service...";
$sysCmd = "cygrunsrv.exe -S boxbackup";
print "$sysCmd\n";
$output = qx($sysCmd);
die "cygrunsrv failed to start service. Error Message: $output\n" if($output ne "");
print " Done.\n";

print "\n\nService Installation complete. To test, reboot your machine, and make sure that\n";
print "the boxbackup service is running. A good way to make sure, is to check that the account number\n";
print "from this machine is connecting to the bbstored server. Check the bbstored logs for more info.\n\n";



--------------050600060602050908040005--



More information about the Boxbackup mailing list