summarylogtreecommitdiffstats
path: root/libresonic.sh
blob: e264e3f5e7cf62b1235b4b8221e76050d8aee90b (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/sh

LIBRESONIC_HOME=/var/lib/libresonic
LIBRESONIC_HOST=0.0.0.0
LIBRESONIC_PORT=8080
LIBRESONIC_HTTPS_PORT=0
LIBRESONIC_CONTEXT_PATH=/
LIBRESONIC_MAX_MEMORY=256
LIBRESONIC_PIDFILE=libresonic.pid
LIBRESONIC_DEFAULT_MUSIC_FOLDER=/var/lib/libresonic/music
LIBRESONIC_DEFAULT_PODCAST_FOLDER=/var/lib/libresonic/podcast
LIBRESONIC_DEFAULT_PLAYLIST_FOLDER=/var/lib/libresonic/playlists

quiet=0

usage() {
    echo "Usage: libresonic.sh [options]"
    echo "  --help               This small usage guide."
    echo "  --home=DIR           The directory where Libresonic will create files."
    echo "                       Make sure it is writable. Default: /var/lib/libresonic"
    echo "  --host=HOST          The host name or IP address on which to bind Libresonic."
    echo "                       Only relevant if you have multiple network interfaces and want"
    echo "                       to make Libresonic available on only one of them. The default value"
    echo "                       will bind Libresonic to all available network interfaces. Default: 0.0.0.0"
    echo "  --port=PORT          The port on which Libresonic will listen for"
    echo "                       incoming HTTP traffic. Default: 8080"
    echo "  --https-port=PORT    The port on which Libresonic will listen for"
    echo "                       incoming HTTPS traffic. Default: 0 (disabled)"
    echo "  --context-path=PATH  The context path, i.e., the last part of the Libresonic"
    echo "                       URL. Typically '/' or '/libresonic'. Default '/'"
    echo "  --max-memory=MB      The memory limit (max Java heap size) in megabytes."
    echo "                       Default: 100"
    echo "  --pidfile=PIDFILE    Write PID to this file. Default not created."
    echo "  --quiet              Don't print anything to standard out. Default false."
    echo "  --default-music-folder=DIR    Configure Libresonic to use this folder for music.  This option "
    echo "                                only has effect the first time Libresonic is started. Default '/var/lib/libresonic/music'"
    echo "  --default-podcast-folder=DIR  Configure Libresonic to use this folder for Podcasts.  This option "
    echo "                                only has effect the first time Libresonic is started. Default '/var/lib/libresonic/podcast'"
    echo "  --default-playlist-folder=DIR Configure Libresonic to use this folder for playlists.  This option "
    echo "                                only has effect the first time Libresonic is started. Default '/var/lib/libresonic/playlists'"
    exit 1
}

# Parse arguments.
while [ $# -ge 1 ]; do
    case $1 in
        --help)
            usage
            ;;
        --home=?*)
            LIBRESONIC_HOME=${1#--home=}
            ;;
        --host=?*)
            LIBRESONIC_HOST=${1#--host=}
            ;;
        --port=?*)
            LIBRESONIC_PORT=${1#--port=}
            ;;
        --https-port=?*)
            LIBRESONIC_HTTPS_PORT=${1#--https-port=}
            ;;
        --context-path=?*)
            LIBRESONIC_CONTEXT_PATH=${1#--context-path=}
            ;;
        --max-memory=?*)
            LIBRESONIC_MAX_MEMORY=${1#--max-memory=}
            ;;
        --pidfile=?*)
            LIBRESONIC_PIDFILE=${1#--pidfile=}
            ;;
        --quiet)
            quiet=1
            ;;
        --default-music-folder=?*)
            LIBRESONIC_DEFAULT_MUSIC_FOLDER=${1#--default-music-folder=}
            ;;
        --default-podcast-folder=?*)
            LIBRESONIC_DEFAULT_PODCAST_FOLDER=${1#--default-podcast-folder=}
            ;;
        --default-playlist-folder=?*)
            LIBRESONIC_DEFAULT_PLAYLIST_FOLDER=${1#--default-playlist-folder=}
            ;;
        *)
            usage
            ;;
    esac
    shift
done

# Use JAVA_HOME if set, otherwise assume java is in the path.
JAVA=java
if [ -e "${JAVA_HOME}" ]
    then
    JAVA=${JAVA_HOME}/bin/java
fi

# Create Libresonic home directory.
mkdir -p ${LIBRESONIC_HOME}
LOG=${LIBRESONIC_HOME}/libresonic_sh.log
rm -f ${LOG}

cd $(dirname $0)
if [ -L $0 ] && ([ -e /bin/readlink ] || [ -e /usr/bin/readlink ]); then
    cd $(dirname $(readlink $0))
fi

${JAVA} -Xmx${LIBRESONIC_MAX_MEMORY}m \
  -Dserver.address=${LIBRESONIC_HOST} \
  -Dserver.port=${LIBRESONIC_PORT} \
  -Dserver.httpsPort=${LIBRESONIC_HTTPS_PORT} \
  -Dserver.contextPath=${LIBRESONIC_CONTEXT_PATH} \
  -Dlibresonic.home=${LIBRESONIC_HOME} \
  -Dlibresonic.defaultMusicFolder=${LIBRESONIC_DEFAULT_MUSIC_FOLDER} \
  -Dlibresonic.defaultPodcastFolder=${LIBRESONIC_DEFAULT_PODCAST_FOLDER} \
  -Dlibresonic.defaultPlaylistFolder=${LIBRESONIC_DEFAULT_PLAYLIST_FOLDER} \
  -Djava.awt.headless=true \
  -jar libresonic.war > ${LOG} 2>&1 &

# Write pid to pidfile if it is defined.
if [ $LIBRESONIC_PIDFILE ]; then
    echo $! > ${LIBRESONIC_PIDFILE}
fi

if [ $quiet = 0 ]; then
    echo Started Libresonic [PID $!, ${LOG}]
fi