From: Sergey Matveev Date: Thu, 10 Dec 2020 15:06:00 +0000 (+0300) Subject: daemontools instead of rc.d X-Git-Tag: v1.2.0^0 X-Git-Url: http://www.git.stargrave.org/?p=uploader.git;a=commitdiff_plain;h=051552265345ad165bd015fabc8b7c947809e708 daemontools instead of rc.d --- diff --git a/README b/README index 7ab9f86..30e9c38 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ -Simplest form file uploader. +Simplest HTTP form file uploader. It just saves uploaded file from HTML form to the new file on the disk. -Also it calculates BLAKE2b checksum, replying with it in the answer. +Also it calculates BLAKE2b-512 checksum, replying with it in the answer. You can upload files with curl: @@ -9,10 +9,12 @@ You can upload files with curl: [ -F comment="optional comment" ] \ http://localhost:8086/upload/ -You can verify integrity locally: +and verify integrity locally: b2sum -a blake2b somedata.tar.gpg You can enable mail notification with -notify-to and -notify-from options. +It is advisable to run it under daemontools-like supervisor +(http://cr.yp.to/daemontools.html). Example service/uploader provided. uploader is free software: see the file COPYING for copying conditions. diff --git a/main.go b/main.go index 23a3acc..00b396e 100644 --- a/main.go +++ b/main.go @@ -54,11 +54,10 @@ const ( var ( Index = template.Must(template.New("index").Parse(` Upload -
 Example command line usage:
-
-    $ curl -F file=@somedata.tar.gpg [-F comment="optional comment"] http://.../upload/
-    $ b2sum -a blake2b somedata.tar.gpg # to verify checksum
+
+$ curl -F file=@somedata.tar.gpg [-F comment="optional comment"] http://.../upload/
+$ b2sum -a blake2b somedata.tar.gpg # to verify checksum
 

@@ -199,9 +198,11 @@ func upload(w http.ResponseWriter, r *http.Request) { func main() { bind := flag.String("bind", "[::]:8086", "Address to bind to") conns := flag.Int("conns", 2, "Maximal number of connections") - NotifyFromAddr = flag.String("notify-from", "uploader@example.com", "Address notifications are send to") - NotifyToAddr = flag.String("notify-to", "", "Address notifications are send from") + NotifyFromAddr = flag.String("notify-from", "uploader@example.com", "Address notifications are sent to") + NotifyToAddr = flag.String("notify-to", "", "Address notifications are sent from") flag.Parse() + log.SetFlags(log.Lshortfile) + log.SetOutput(os.Stdout) if len(*NotifyFromAddr) == 0 && len(*NotifyToAddr) > 0 { log.Fatalln("notify-from address can not be empty, if notify-to is set") } diff --git a/rc.d/uploader b/rc.d/uploader deleted file mode 100755 index f30fba6..0000000 --- a/rc.d/uploader +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -# -# $FreeBSD$ -# -# PROVIDE: uploader -# REQUIRE: DAEMON NETWORKING FILESYSTEMS -# KEYWORD: shutdown -# -# Add these lines to /etc/rc.conf.local or /etc/rc.conf -# to enable this service: -# -# uploader_enable (bool): Set to NO by default. -# Set it to YES to enable uploader. -# uploader_chdir (path): Set to /storage/gw/incoming by default. -# uploader_bind (string): Address:port to bind to -# Default is "[::]:8086". - -. /etc/rc.subr - -name=uploader -rcvar=uploader_enable - -load_rc_config $name - -: ${uploader_enable:="NO"} -: ${uploader_chdir="/storage/gw/incoming"} -: ${uploader_bind="[::]:8086"} - -command=/home/stargrave/uploader -command_args="-bind '$uploader_bind' >> log 2>&1 &" -command_chdir=$uploader_chdir -uploader_user=stargrave - -run_rc_command "$1" diff --git a/service/uploader/log/run b/service/uploader/log/run new file mode 100644 index 0000000..1a9f444 --- /dev/null +++ b/service/uploader/log/run @@ -0,0 +1,2 @@ +#!/bin/sh -e +exec setuidgid uploader multilog t ./main diff --git a/service/uploader/run b/service/uploader/run new file mode 100755 index 0000000..087fe57 --- /dev/null +++ b/service/uploader/run @@ -0,0 +1,4 @@ +#!/bin/sh -e +cd /path/to/incoming +exec setuidgid uploader /path/to/uploader -bind "[::]:8086" \ + -notify-from uploader@example.com -notify-to admin@example.com