summaryrefslogtreecommitdiff
path: root/firestart
blob: d88ae520d2e7015775daa0ee3f3dc5dff4624a0d (plain)
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
#!/bin/sh

CMD=firefox
UNIT=$CMD
DIR=~/.mozilla
MEMORY_MAX=50%
READ_OPS=1G
WRITE_OPS=$READ_OPS

cfg=$HOME/.config/firestart/conf
if [ -e "$cfg" ]
then
    . "$cfg"
fi

if systemctl --user is-active "$UNIT" >/dev/null
then
    exec "$CMD" "$@" # Asks existing firefox to open a new window.
    exit
fi

DEV=$(echo $(findmnt --target "$DIR" -o MAJ:MIN -n))
[ "$DEV" ] || exit

systemctl --user reset-failed "$UNIT" 2>/dev/null
systemd-run --user \
            --unit "$UNIT" \
            --setenv DISPLAY="$DISPLAY" \
            --setenv XAUTHORITY="$XAUTHORITY" \
            --property MemoryMax="$MEMORY_MAX" \
            --property IOReadIOPSMax="$DEV $READ_OPS" \
            --property IOWriteIOPSMax="$DEV $WRITE_OPS" \
            --property Restart="on-failure" \
            -- \
            "$CMD" "$@"