Committed empty backend project, fixed URL

This commit is contained in:
Rick Falkvinge
2013-03-02 13:18:45 +00:00
parent 246593a807
commit f7c7613b49
5 changed files with 79 additions and 2191 deletions
-1
View File
@@ -61,7 +61,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="OneOffs.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
-1880
View File
File diff suppressed because it is too large Load Diff
+78 -149
View File
@@ -26,6 +26,9 @@ namespace Swarmops.Backend
{
internal class Program
{
private const string swarmopsExitFlagFile = "./swarmops-backend-exit.flag";
private const string heartbeatFile = "/var/run/swarmops-backend/heartbeat.txt";
private static void Main (string[] args)
{
testMode = false;
@@ -39,9 +42,9 @@ namespace Swarmops.Backend
if (args.Length > 0)
{
if (args[0].ToLower() == "test")
{
{/*
BotLog.Write(0, "MainCycle", "Running self-tests");
HeartBeater.Instance.Beat("/var/run/piratebot/heartbeat.txt"); // Otherwise Heartbeater.Beat() will fail in various places
HeartBeater.Instance.Beat(heartbeatFile); // Otherwise Heartbeater.Beat() will fail in various places
testMode = true;
Console.WriteLine("Testing All Maintenance Processes (except membership-changing ones).");
@@ -59,7 +62,7 @@ namespace Swarmops.Backend
OnNoon();
Console.WriteLine("\r\nMidnight:");
OnMidnight();
*/
Console.Write("\r\nAll tests run. Waiting for mail queue to flush... ");
while (!MailTransmitter.CanExit)
{
@@ -73,7 +76,7 @@ namespace Swarmops.Backend
if (args[0].ToLower() == "console")
{
Console.WriteLine("\r\nRunning PirateBot-Mono in CONSOLE mode.\r\n");
Console.WriteLine("\r\nRunning Swarmops-Backend in CONSOLE mode.\r\n");
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
@@ -81,34 +84,7 @@ namespace Swarmops.Backend
// ----------------------- INSERT ANY ONE-OFF ACTIONS HERE -------------------------
Console.WriteLine("Calling closure of 2010 books.");
OneOffs.CloseBooksForYear(2010);
/*
PWEvents.CreateEvent(EventSource.PirateBot, EventType.ParleyCancelled, 1, 1, 1, 1, 1, string.Empty);
PWEvents.CreateEvent(EventSource.PirateBot, EventType.ParleyCancelled, 1, 1, 1, 1, 4, string.Empty);
PWEvents.CreateEvent(EventSource.PirateBot, EventType.ParleyCancelled, 1, 1, 1, 1, 5, string.Empty);*/
// PirateWeb.Utility.BotCode.ActivityMailer.Run();
// PirateWeb.Utility.BotCode.RosterHousekeeping.RemindExpiriesMail();
// OneOffs.FixOutboundInvoices();
// OneOffs.SmsMembersOnElectionDay2010();
// OneOffs.RepairFinancials();
// Console.WriteLine("Entering RemindExpiriesMail()");
// PirateWeb.Utility.BotCode.RosterHousekeeping.RemindExpiriesMail();
// OneOffs.CarryOver2010LocalBudgets();
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
Console.Write("\r\nWaiting for mail queue to flush... ");
while (!MailTransmitter.CanExit)
@@ -123,7 +99,7 @@ namespace Swarmops.Backend
if (args[0].ToLower() == "rsm")
{
Console.WriteLine("räksmörgås RÄKSMÖRGÅS");
Console.WriteLine("Testing character encoding: räksmörgås RÄKSMÖRGÅS");
return;
}
}
@@ -141,28 +117,16 @@ namespace Swarmops.Backend
smtpClient.Credentials = null; // mono bug
smtpClient.Send (message);*/
Console.WriteLine(" * PirateBot-Lamp starting");
Console.WriteLine(" * Swarmops Backend starting");
HeartBeater.Instance.Beat("/var/run/piratebot/heartbeat.txt");
HeartBeater.Instance.Beat(heartbeatFile);
if (File.Exists("./piratebotexit.flag"))
if (File.Exists(swarmopsExitFlagFile))
{
File.Delete("./piratebotexit.flag");
File.Delete(swarmopsExitFlagFile);
}
//to debug automatic restart: (Hang here)
if (File.Exists("./lock_the_shit")) { while (true) Thread.Sleep(1000); }
BotLog.Write(0, "MainCycle", "BOT STARTING, sending botstart notices");
MailTransmitter statusMail = new MailTransmitter
("PirateWeb-L", "noreply@pirateweb.net", "PirateBot-L starting", string.Empty, Person.FromIdentity(1));
statusMail.Send();
Person.FromIdentity(1).SendOfficerNotice("PirateBot-L active & operational",
"PirateBot Lamp - all systems are operational", 1);
BotLog.Write(0, "MainCycle", "...done");
BotLog.Write(0, "MainCycle", "Backend STARTING");
DateTime cycleStartTime = DateTime.Now;
@@ -171,7 +135,7 @@ namespace Swarmops.Backend
int lastHour = cycleStartTime.Hour;
while (!File.Exists("./piratebotexit.flag"))
while (!File.Exists(swarmopsExitFlagFile))
{
BotLog.Write(0, "MainCycle", "Cycle Start");
@@ -215,9 +179,11 @@ namespace Swarmops.Backend
catch (Exception e)
{
//Note each "OnEvery..." catches its own errors and sends Exception mail now.
//so that failure in one should not stop the others from running.
ExceptionMail.Send(new Exception("Failed in bot main loop", e), true);
// Note each "OnEvery..." catches its own errors and sends Exception mails,
// so that failure in one should not stop the others from running. This particular
// code should never run.
ExceptionMail.Send(new Exception("Failed in swarmops-backend main loop", e), true);
}
lastSecond = cycleStartTime.Second;
@@ -226,26 +192,22 @@ namespace Swarmops.Backend
// Wait for a maximum of ten seconds
while (DateTime.Now < cycleStartTime.AddSeconds(10) && !File.Exists("./piratebotexit.flag"))
while (DateTime.Now < cycleStartTime.AddSeconds(10) && !File.Exists(swarmopsExitFlagFile))
{
Thread.Sleep(200);
}
}
Console.WriteLine(" * PirateBot-Lamp stopping");
BotLog.Write(0, "MainCycle", "BOT EXITING, sending bot-termination notices");
Console.WriteLine(" * Swarmops Backend stopping");
BotLog.Write(0, "MainCycle", "BACKEND EXITING, sending backend-termination notices");
if (HeartBeater.Instance.WasKilled)
{
File.Delete("./piratebotexit.flag");
// removed unconditional delete, cron jobb that restarts bot uses it to know that it is intentionally down.
ExceptionMail.Send(new Exception("HeartBeater triggered restart of MonoBot. Will commence after 800 seconds."), false);
File.Delete(swarmopsExitFlagFile);
// removed unconditional delete, cron job that restarts bot uses it to know that it is intentionally down.
ExceptionMail.Send(new Exception("HeartBeater triggered restart of Swarmops Backend. Will commence after 800 seconds."), false);
}
statusMail = new MailTransmitter
("PirateWeb-L", "noreply@pirateweb.net", "PirateBot-L exiting", string.Empty, Person.FromIdentity(1));
statusMail.Send();
BotLog.Write(0, "MainCycle", "...done");
while (!MailTransmitter.CanExit)
@@ -264,9 +226,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running EventProcessor.Run()...");
/*TestTrace("Running EventProcessor.Run()...");
EventProcessor.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -275,9 +237,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running MailResolver.Run()...");
/*TestTrace("Running MailResolver.Run()...");
MailResolver.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -286,9 +248,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running MailProcessor.Run()...");
/*TestTrace("Running MailProcessor.Run()...");
MailProcessor.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -326,10 +288,10 @@ namespace Swarmops.Backend
try
{
BotLog.Write(1, "FiveMinute", "Starting press release checker");
/*BotLog.Write(1, "FiveMinute", "Starting press release checker");
TestTrace("Running PressReleaseChecker.Run()...");
PressReleaseChecker.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -338,10 +300,10 @@ namespace Swarmops.Backend
try
{
BotLog.Write(1, "FiveMinute", "Starting newsletter checker");
/*BotLog.Write(1, "FiveMinute", "Starting newsletter checker");
TestTrace("Running NewsletterChecker.Run()...");
NewsletterChecker.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -350,10 +312,10 @@ namespace Swarmops.Backend
try
{
BotLog.Write(1, "FiveMinute", "Starting turnaround tracker");
/*BotLog.Write(1, "FiveMinute", "Starting turnaround tracker");
TestTrace("Running TurnaroundTracker.Run()...");
TurnaroundTracker.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -378,10 +340,10 @@ namespace Swarmops.Backend
try
{
BotLog.Write(1, "FiveMinute", "Closing delay warnings");
/*BotLog.Write(1, "FiveMinute", "Closing delay warnings");
TestTrace("Running SupportDatabase.CloseDelayWarnings()...");
SupportDatabase.CloseDelayWarnings();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -390,10 +352,10 @@ namespace Swarmops.Backend
try
{
TestTrace("Running SupportDatabase.NotifyBouncingEmails()...");
/*TestTrace("Running SupportDatabase.NotifyBouncingEmails()...");
BotLog.Write(1, "FiveMinute", "Notifying bouncing emails");
SupportDatabase.NotifyBouncingEmails();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -402,10 +364,10 @@ namespace Swarmops.Backend
try
{
TestTrace("Running SupportMailReview.Run()...");
/*TestTrace("Running SupportMailReview.Run()...");
BotLog.Write(1, "FiveMinute", "Running support mail review");
SupportMailReview.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -432,9 +394,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running BlogWatcher.Run()...");
/*TestTrace("Running BlogWatcher.Run()...");
BlogWatcher.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -443,9 +405,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running MediaWatcher.Run()...");
/*TestTrace("Running MediaWatcher.Run()...");
MediaWatcher.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -454,9 +416,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running PaymentGroupMapper.Run()...");
/*TestTrace("Running PaymentGroupMapper.Run()...");
PaymentGroupMapper.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -465,9 +427,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running BlogTop50Scraper.Run()...");
/*TestTrace("Running BlogTop50Scraper.Run()...");
BlogTop50Scraper.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -476,9 +438,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running Mappery.CreatePiratpartietOrganizationStrengthCircuitMap()...");
/*TestTrace("Running Mappery.CreatePiratpartietOrganizationStrengthCircuitMap()...");
Mappery.CreatePiratpartietOrganizationStrengthCircuitMap();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -487,24 +449,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running Mappery.CreatePiratpartietOrganizationStrengthCityMap()...");
/*TestTrace("Running Mappery.CreatePiratpartietOrganizationStrengthCityMap()...");
Mappery.CreatePiratpartietOrganizationStrengthCityMap();
TestTrace(" done.\r\n");
}
catch (Exception e)
{
TraceAndReport(e);
}
try
{
//run once a month at the 25:th at 5 o'clock in the morning
if (startTime.Day == 25 && startTime.Hour == 5 && startTime.Minute < 50)
{
TestTrace("Running RosterHousekeeping.RemindChangeOrg()...");
RosterHousekeeping.RemindChangeOrg();
TestTrace(" done.\r\n");
}
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -529,9 +476,9 @@ namespace Swarmops.Backend
{
if (!testMode)
{
TestTrace("Running RosterHousekeeping.ChurnExpiredMembers()...");
/*TestTrace("Running RosterHousekeeping.ChurnExpiredMembers()...");
RosterHousekeeping.ChurnExpiredMembers();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
}
catch (Exception e)
@@ -541,9 +488,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running InternalPollMaintenance.Run()...");
/*TestTrace("Running InternalPollMaintenance.Run()...");
InternalPollMaintenance.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -552,9 +499,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running SwedishForumMemberCheck.Run()...");
/*TestTrace("Running SwedishForumMemberCheck.Run()...");
SwedishForumMemberCheck.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -563,9 +510,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running SalaryProcessor.Run()...");
/*TestTrace("Running SalaryProcessor.Run()...");
SalaryProcessor.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -574,9 +521,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running TurnaroundTracker.Housekeeping()...");
/*TestTrace("Running TurnaroundTracker.Housekeeping()...");
TurnaroundTracker.Housekeeping();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -585,9 +532,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running Mappery.CreateUngPiratUptakeMap()...");
/*TestTrace("Running Mappery.CreateUngPiratUptakeMap()...");
Mappery.CreateUngPiratUptakeMap();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -596,9 +543,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running RosterHousekeeping.TimeoutVolunteers()...");
/*TestTrace("Running RosterHousekeeping.TimeoutVolunteers()...");
RosterHousekeeping.TimeoutVolunteers();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -622,9 +569,9 @@ namespace Swarmops.Backend
{
if (!testMode)
{
TestTrace("Running RosterHousekeeping.RemindAllExpiries()...");
/*TestTrace("Running RosterHousekeeping.RemindAllExpiries()...");
RosterHousekeeping.RemindAllExpiries();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
}
catch (Exception e)
@@ -636,9 +583,9 @@ namespace Swarmops.Backend
{
if (!testMode)
{
TestTrace("Running SupportDatabase.NotifyBouncingEmails()...");
/*TestTrace("Running SupportDatabase.NotifyBouncingEmails()...");
SupportDatabase.NotifyBouncingEmails();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
}
@@ -649,9 +596,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running SupportDatabase.CloseDelayWarnings()...");
/*TestTrace("Running SupportDatabase.CloseDelayWarnings()...");
SupportDatabase.CloseDelayWarnings();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -660,9 +607,9 @@ namespace Swarmops.Backend
try
{
TestTrace("Running SupportMailReview.Run()...");
/*TestTrace("Running SupportMailReview.Run()...");
SupportMailReview.Run();
TestTrace(" done.\r\n");
TestTrace(" done.\r\n");*/
}
catch (Exception e)
{
@@ -707,24 +654,6 @@ namespace Swarmops.Backend
}
private static void TranslateUrls ()
{
string[] untranslatedUrls = UrlTranslations.GetUntranslated(20);
foreach (string url in untranslatedUrls)
{
try
{
string newUrl = UrlTranslator.Translate(url);
UrlTranslations.Set(url, newUrl);
}
catch (Exception e)
{
ExceptionMail.Send(new Exception("Tried to translate URL " + url, e));
}
}
}
private static bool testMode;
}
}
-160
View File
@@ -1,160 +0,0 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: swarmops-backend
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Swarmops backend
# Description: This file starts and stops the Swarmsops backend. It is installed as part of
# the swarmops-backend package and placed in /etc/init.d for compatibility with
# Debian and Ubuntu servers.
### END INIT INFO
# Author: Rick Falkvinge <rick.falkvinge@pirateacademy.eu>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Swarmops Backend"
NAME=swarmops-backend
DAEMON=/usr/sbin/$NAME
DAEMON_ARGS="--options args"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:
+1 -1
View File
@@ -8,7 +8,7 @@
<p>This system, <em>Swarmops,</em> is under heavy (re)construction. It has been the admin mainstay of the Swedish Pirate Party for six years, and is being generalized to encompass any organization.</p>
<p>What you see here is the new interface being rewritten on top of the already-running engine. It runs on Debian/Ubuntu servers for frontend and backend.</p>
<p>This notice will be replaced with a proper Dashboard when all the basic functions are in place. You can see functions appear as they are implemented in the menu.</p>
<p>A rough roadmap says that basic financials are implemented first, then member registry functions, then communications, then responsibilities, then governance. For more on the specific roadmap, go to the <a href="http://scrum.pirateadacemy.eu/">SCRUM planning</a> for Swarmops.</p>
<p>A rough roadmap says that basic financials are implemented first, then member registry functions, then communications, then responsibilities, then governance. For more on the specific roadmap, go to the <a href="http://scrum.pirateacademy.eu/">SCRUM planning</a> for Swarmops.</p>
</asp:Content>