Photoprocess : Convert from container to systemd service.
This commit is contained in:
parent
cdaa3abe70
commit
b8c27de2a1
|
@ -1,100 +0,0 @@
|
|||
# Takes pictures from first photo dir, processes and stores to the second one.
|
||||
{ container, util, pkgs, ... } @args: let
|
||||
cfg = container.config.photoprocess;
|
||||
in {
|
||||
systemd.tmpfiles.rules = container.mkContainerDir cfg [
|
||||
"data"
|
||||
];
|
||||
|
||||
containers.photoprocess = container.mkContainer cfg {
|
||||
bindMounts = {
|
||||
"/data" = {
|
||||
hostPath = "${cfg.storage}/data";
|
||||
isReadOnly = false;
|
||||
};
|
||||
"/in" = {
|
||||
# hostPath = "${container.config.cloud.storage}/data/data/"
|
||||
hostPath = builtins.elemAt cfg.photo 0;
|
||||
isReadOnly = false;
|
||||
};
|
||||
"/out" = {
|
||||
hostPath = builtins.elemAt cfg.photo 1;
|
||||
isReadOnly = false;
|
||||
};
|
||||
};
|
||||
|
||||
config = { lib, ... }: container.mkContainerConfig cfg {
|
||||
systemd.services.photosprocess = let
|
||||
script = pkgs.writeText "PhotoprocessScript" (util.trimTabs ''
|
||||
source /data/Notify.sh
|
||||
|
||||
cd /in
|
||||
|
||||
# Convert png to jpg.
|
||||
for img in $(ls *.png) $(ls *.PNG); do
|
||||
filename=''${img%.*}
|
||||
convert "$filename.png" "$filename.jpg"
|
||||
done
|
||||
rm *.png *.PNG
|
||||
|
||||
# Rename bad extensions.
|
||||
for img in $(ls *.jpeg) $(ls *.JPG) $(ls *.JPEG); do
|
||||
filename=''${img%.*}
|
||||
mv "$img" "$filename.jpg"
|
||||
done
|
||||
|
||||
# Compress jpg.
|
||||
mogrify -resize 2073600@ *.jpg
|
||||
jpegoptim --size=1000k *.jpg
|
||||
|
||||
# Rename to hash.
|
||||
for file in *; do
|
||||
if [[ -f "$file" ]]; then
|
||||
extension="''${file##*.}"
|
||||
if [ -f "$file" ] && [ "$extension" != "$file" ]; then
|
||||
new_name="''${file%$extension}"
|
||||
else
|
||||
new_name="$file"
|
||||
extension=""
|
||||
fi
|
||||
new_name=$(sha1sum "$file" | cut -d\ -f1)
|
||||
if [[ "$extension" != "" ]]; then
|
||||
new_name="''${new_name,,}.$extension"
|
||||
else
|
||||
new_name="''${new_name,,}"
|
||||
fi
|
||||
mv "$file" "$new_name"
|
||||
fi
|
||||
done
|
||||
|
||||
# Move to images.
|
||||
total_photos=$(ls | wc -l)
|
||||
mv *.jpg /out
|
||||
notify_silent "Photos processed: $total_photos"
|
||||
'');
|
||||
in util.mkStaticSystemdService {
|
||||
enable = true;
|
||||
description = "Process uploaded photos.";
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "-${lib.getExe pkgs.bashInteractive} ${script}";
|
||||
Restart = "on-failure";
|
||||
};
|
||||
path = with pkgs; [
|
||||
curl
|
||||
imagemagick
|
||||
jpegoptim
|
||||
];
|
||||
};
|
||||
|
||||
systemd.timers.photosprocess = {
|
||||
timerConfig = {
|
||||
OnCalendar = "daily";
|
||||
Persistent = true;
|
||||
Unit = "photosprocess.service";
|
||||
};
|
||||
wantedBy = [ "timers.target" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
|
@ -141,11 +141,6 @@
|
|||
port = 80;
|
||||
storage = "${storage}/paste";
|
||||
};
|
||||
photoprocess = {
|
||||
inherit (media) photo;
|
||||
address = "10.1.0.4";
|
||||
storage = "${storage}/photoprocess";
|
||||
};
|
||||
print = {
|
||||
domain = "print.${domain}";
|
||||
address = "10.1.0.46";
|
||||
|
|
|
@ -52,7 +52,6 @@ in {
|
|||
(import ../../container/Paper.nix args)
|
||||
(import ../../container/Pass.nix args)
|
||||
(import ../../container/Paste.nix args)
|
||||
(import ../../container/Photoprocess.nix args)
|
||||
(import ../../container/Postgres.nix args)
|
||||
(import ../../container/Print.nix args)
|
||||
(import ../../container/Proxy.nix args)
|
||||
|
|
79
host/home/Photoprocess.nix
Normal file
79
host/home/Photoprocess.nix
Normal file
|
@ -0,0 +1,79 @@
|
|||
# Takes pictures from first photo dir, processes and stores to the second one.
|
||||
{ util, pkgs, lib, ... } @args: let
|
||||
imgInput = "/storage/hot/container/cloud/data/data/cakee/files/media/photo";
|
||||
imgOutput = "/storage/cold_1/backup/tmp/photo";
|
||||
in {
|
||||
systemd.services.photosprocess = let
|
||||
script = pkgs.writeText "PhotoprocessScript" (util.trimTabs ''
|
||||
function notify_silent() {
|
||||
curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\",\"disable_notification\":\"true\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null
|
||||
}
|
||||
|
||||
cd ${imgInput}
|
||||
|
||||
# Convert png to jpg.
|
||||
for img in $(ls *.png) $(ls *.PNG); do
|
||||
filename=''${img%.*}
|
||||
convert "$filename.png" "$filename.jpg"
|
||||
done
|
||||
rm *.png *.PNG
|
||||
|
||||
# Rename bad extensions.
|
||||
for img in $(ls *.jpeg) $(ls *.JPG) $(ls *.JPEG); do
|
||||
filename=''${img%.*}
|
||||
mv "$img" "$filename.jpg"
|
||||
done
|
||||
|
||||
# Compress jpg.
|
||||
mogrify -resize 2073600@ *.jpg
|
||||
jpegoptim --size=1000k *.jpg
|
||||
|
||||
# Rename to hash.
|
||||
for file in *; do
|
||||
if [[ -f "$file" ]]; then
|
||||
extension="''${file##*.}"
|
||||
if [ -f "$file" ] && [ "$extension" != "$file" ]; then
|
||||
new_name="''${file%$extension}"
|
||||
else
|
||||
new_name="$file"
|
||||
extension=""
|
||||
fi
|
||||
new_name=$(sha1sum "$file" | cut -d\ -f1)
|
||||
if [[ "$extension" != "" ]]; then
|
||||
new_name="''${new_name,,}.$extension"
|
||||
else
|
||||
new_name="''${new_name,,}"
|
||||
fi
|
||||
mv "$file" "$new_name"
|
||||
fi
|
||||
done
|
||||
|
||||
# Move to images.
|
||||
total_photos=$(ls | wc -l)
|
||||
mv *.jpg ${imgOutput}
|
||||
notify_silent "Photos processed: $total_photos"
|
||||
'');
|
||||
in util.mkStaticSystemdService {
|
||||
enable = true;
|
||||
description = "Process uploaded photos.";
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "-${lib.getExe pkgs.bashInteractive} ${script}";
|
||||
Restart = "on-failure";
|
||||
};
|
||||
path = with pkgs; [
|
||||
curl
|
||||
imagemagick
|
||||
jpegoptim
|
||||
];
|
||||
};
|
||||
|
||||
systemd.timers.photosprocess = {
|
||||
timerConfig = {
|
||||
OnCalendar = "daily";
|
||||
Persistent = true;
|
||||
Unit = "photosprocess.service";
|
||||
};
|
||||
wantedBy = [ "timers.target" ];
|
||||
};
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
./Container.nix
|
||||
./Filesystem.nix
|
||||
./Network.nix
|
||||
./Photoprocess.nix
|
||||
];
|
||||
|
||||
# Disable auto-switch.
|
||||
|
|
Loading…
Reference in a new issue