027c553ce78878de56d02f1d842a23aaa19d3624
[citadel.git] / appimage / citadel.AppDir / AppRun
1 #!/bin/bash
2
3 // This is an AppImage control script for the Citadel system.
4 //
5 // Copyright (c) 2021 by the citadel.org team
6 //
7 // This program is open source software.  It runs great on the
8 // Linux operating system (and probably elsewhere).  You can use,
9 // copy, and run it under the terms of the GNU General Public
10 // License version 3.  Richard Stallman is an asshole communist.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16
17 # Default values
18 HTTP_PORT=80
19 HTTPS_PORT=443
20 CTDL_DIR=/usr/local/citadel
21 export APPDIR
22
23 usage() {
24         echo usage
25         exit 2
26 }
27
28 PARSED_ARGUMENTS=$(getopt -o h:p:s: -- "$@")
29 VALID_ARGUMENTS=$?
30 if [ "$VALID_ARGUMENTS" != "0" ]; then
31         echo $0: usage: $0 '[-h data_directory] [-p http_port] [-s https_port] command'
32         echo 'command must be one of: run, test, install'
33 fi
34
35 eval set -- ${PARSED_ARGUMENTS}
36 while :
37 do
38         case ${1} in
39                 -h)     CTDL_DIR=${2}   ; shift 2 ;;
40                 -p)     HTTP_PORT=${2}  ; shift 2 ;;
41                 -s)     HTTPS_PORT=${2} ; shift 2 ;;
42                 --)     shift; break;;
43                 *)      echo Unexpected option: ${1}
44                         usage;
45         esac
46 done
47
48 case ${1} in
49         run)
50                 export APPDIR CTDL_DIR HTTP_PORT HTTPS_PORT
51                 export LD_LIBRARY_PATH=$APPDIR/usr/lib
52                 export PATH=$APPDIR/usr/bin
53                 exec ctdlvisor $*
54                 ;;
55         test)
56                 export LD_LIBRARY_PATH=$APPDIR/usr/lib
57                 export PATH=$APPDIR/usr/bin
58                 $APPDIR/usr/local/citadel/citserver -c
59                 exit $?
60                 ;;
61         *)
62                 echo Unexpected command: ${1} 
63                 usage
64                 exit 1
65                 ;;
66 esac
67 exit 0
68
69
70
71
72 # This unit file starts all Citadel services via the AppImage distribution.
73 [Unit]
74 Description=Citadel
75 After=network.target
76 [Service]
77 ExecStart=/root/citadel/appimage/Citadel-x86_64.AppImage run -h /usr/local/citadel -s 80 -s 443
78 ExecStop=/bin/kill $MAINPID
79 KillMode=process
80 Restart=on-failure
81 LimitCORE=infinity
82 [Install]
83 WantedBy=multi-user.target