8a32e7e1dbaa88e3c2bbd88ae5096c024fb7909f
[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 ulimit -c unlimited
23
24 usage() {
25         echo ${APPIMAGE}: usage: ${APPIMAGE} '[-h data_directory] [-p http_port] [-s https_port] command'
26         echo 'command must be one of: run, test, install'
27         exit 2
28 }
29
30
31 # Permanently install the Citadel AppImage to this system
32 installation() {
33
34         # First ... check to make sure Citadel isn't runnings
35         if ps ax | grep citserver | grep -v grep ; then
36                 echo Installation cannot proceed while Citadel is running.
37                 echo Stop your services and try again.
38                 exit 1
39         fi
40
41         echo Hi
42         exit
43 }
44
45
46 PARSED_ARGUMENTS=$(getopt -o h:p:s: -- "$@")
47 VALID_ARGUMENTS=$?
48 if [ "$VALID_ARGUMENTS" != "0" ]; then
49         usage
50 fi
51
52 eval set -- ${PARSED_ARGUMENTS}
53 while :
54 do
55         case ${1} in
56                 -h)     CTDL_DIR=${2}   ; shift 2 ;;
57                 -p)     HTTP_PORT=${2}  ; shift 2 ;;
58                 -s)     HTTPS_PORT=${2} ; shift 2 ;;
59                 --)     shift; break;;
60                 *)      echo Unexpected option: ${1}
61                         usage;
62         esac
63 done
64
65 case ${1} in
66         run)
67                 export APPDIR CTDL_DIR HTTP_PORT HTTPS_PORT
68                 export LD_LIBRARY_PATH=$APPDIR/usr/lib
69                 export PATH=$APPDIR/usr/bin
70                 exec ctdlvisor $*
71                 ;;
72         test)
73                 export LD_LIBRARY_PATH=$APPDIR/usr/lib
74                 export PATH=$APPDIR/usr/bin
75                 exec $APPDIR/usr/local/citadel/citserver -c
76                 ;;
77         install)
78                 installation
79                 ;;
80         *)
81                 echo Unexpected command: ${1} 
82                 usage
83                 exit 1
84                 ;;
85 esac
86 exit 0
87
88
89
90
91 # This unit file starts all Citadel services via the AppImage distribution.
92 [Unit]
93 Description=Citadel
94 After=network.target
95 [Service]
96 ExecStart=/root/citadel/appimage/Citadel-x86_64.AppImage run -h /usr/local/citadel -s 80 -s 443
97 ExecStop=/bin/kill $MAINPID
98 KillMode=process
99 Restart=on-failure
100 LimitCORE=infinity
101 [Install]
102 WantedBy=multi-user.target