File: quickml.in

package info (click to toggle)
quickml 0.8-2
  • links: PTS
  • area: main
  • in suites: sid
  • size: 492 kB
  • sloc: ruby: 1,822; sh: 272; makefile: 174
file content (81 lines) | stat: -rw-r--r-- 1,912 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! %RUBY%
# coding: euc-jp
# -*- mode: ruby -*-
#
# quickml - an easy-to-use mailing list server
#
# Copyright (C) 2002-2004 Satoru Takabayashi <satoru@namazu.org> 
#     All rights reserved.
#     This is free software with ABSOLUTELY NO WARRANTY.
#
# You can redistribute it and/or modify it under the terms of 
# the GNU General Public License version 2.
#

require 'quickml'

def error (msg)
  STDERR.puts "#{$0}: #{msg}"
  exit(1)
end

def show_usage
  puts "Usage: quickml <data directory> <smtp server> <domain name>"
end

def check_directory (dir)
  error("#{dir}: No such directory") unless File.directory?(dir) 
  error("#{dir}: is not writable")   unless File.writable?(dir) 
end

def be_daemon
  exit!(0) if fork
  Process::setsid
  exit!(0) if fork
  Dir::chdir("/")
  File::umask(022)
  STDIN.reopen("/dev/null",  "r+")
  STDOUT.reopen("/dev/null", "r+")
  STDERR.reopen("/dev/null", "r+")
end

def touch (filename)
  File.safe_open(filename, "a").close
end

def be_secure (config)
  return unless Process.uid == 0
  uid = Etc::getpwnam(config.user).uid 
  gid = Etc::getgrnam(config.group).gid
  touch(config.pid_file)
  touch(config.log_file)
  File.chown(uid, gid, config.data_dir)
  File.chown(uid, gid, config.pid_file)
  File.chown(uid, gid, config.log_file)
  Process.uid  = uid
  Process.gid  = gid
  Process.euid = uid
end

def main (argv)
  config_file = if argv.length == 1 then 
		  argv.first 
		else 
		  File.join("%SYSCONFDIR%", "quickmlrc")
		end
  config = QuickML::Config::load(config_file)
  check_directory(config.data_dir)

  be_daemon
  server  = QuickML::Server.new(config)
  be_secure(config)

  sweeper = QuickML::Sweeper.new(config)
  trap(:TERM) { server.shutdown; sweeper.shutdown }
  trap(:INT)  { server.shutdown; sweeper.shutdown }
  trap(:HUP)  { config.logger.reopen }
  t = Thread.new { sweeper.start }
  t.abort_on_exception = true
  server.start
end
main(ARGV)