]> Sergey Matveev's repositories - uploader.git/commitdiff
daemontools instead of rc.d v1.2.0
authorSergey Matveev <stargrave@stargrave.org>
Thu, 10 Dec 2020 15:06:00 +0000 (18:06 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 10 Dec 2020 19:25:29 +0000 (22:25 +0300)
README
main.go
rc.d/uploader [deleted file]
service/uploader/log/run [new file with mode: 0644]
service/uploader/run [new file with mode: 0755]

diff --git a/README b/README
index 7ab9f86acc11b9fca9923faa91997086acbc51ad..30e9c388c190be3d441bc8034e92bf6367f9093a 100644 (file)
--- 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 23a3accbe2046619267e52bebb7c6d653e8b5934..00b396e4ba9c4450ed3ba3d7518c495e9b363c12 100644 (file)
--- a/main.go
+++ b/main.go
@@ -54,11 +54,10 @@ const (
 var (
        Index = template.Must(template.New("index").Parse(`<html>
 <head><title>Upload</title></head><body>
-<pre>
 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
+<pre>
+$ curl -F file=@somedata.tar.gpg [-F comment="optional comment"] http://.../upload/
+$ b2sum -a blake2b somedata.tar.gpg # to verify checksum
 </pre>
 <form enctype="multipart/form-data" action="/upload/" method="post">
 <label for="file">File to upload:</label><br/>
@@ -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 (executable)
index f30fba6..0000000
+++ /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 (file)
index 0000000..1a9f444
--- /dev/null
@@ -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 (executable)
index 0000000..087fe57
--- /dev/null
@@ -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