| 1 | #!/sbin/openrc-run |
| 2 | |
| 3 | name="opencloud" |
| 4 | description="OpenCloud - file-sync and share server (single-binary runtime)" |
| 5 | |
| 6 | : "${opencloud_user:=opencloud}" |
| 7 | : "${opencloud_group:=opencloud}" |
| 8 | : "${opencloud_config_dir:=/etc/opencloud}" |
| 9 | : "${opencloud_data_dir:=/var/lib/opencloud}" |
| 10 | : "${opencloud_logfile:=/var/log/opencloud/opencloud.log}" |
| 11 | : "${opencloud_insecure:=true}" |
| 12 | |
| 13 | command="/usr/bin/opencloud" |
| 14 | command_args="server" |
| 15 | command_user="${opencloud_user}:${opencloud_group}" |
| 16 | pidfile="/run/${RC_SVCNAME}.pid" |
| 17 | |
| 18 | supervisor="supervise-daemon" |
| 19 | output_log="${opencloud_logfile}" |
| 20 | error_log="${opencloud_logfile}" |
| 21 | |
| 22 | export OC_CONFIG_DIR="${opencloud_config_dir}" |
| 23 | export OC_BASE_DATA_PATH="${opencloud_data_dir}" |
| 24 | [ -n "${opencloud_url}" ] && export OC_URL="${opencloud_url}" |
| 25 | [ -n "${opencloud_log_level}" ] && export OC_LOG_LEVEL="${opencloud_log_level}" |
| 26 | [ -n "${opencloud_http_addr}" ] && export PROXY_HTTP_ADDR="${opencloud_http_addr}" |
| 27 | [ -n "${opencloud_tls}" ] && export PROXY_TLS="${opencloud_tls}" |
| 28 | |
| 29 | depend() { |
| 30 | need net |
| 31 | use dns logger |
| 32 | after firewall |
| 33 | } |
| 34 | |
| 35 | start_pre() { |
| 36 | checkpath -d -m 0700 -o "${opencloud_user}:${opencloud_group}" "${opencloud_config_dir}" |
| 37 | checkpath -d -m 0700 -o "${opencloud_user}:${opencloud_group}" "${opencloud_data_dir}" |
| 38 | checkpath -d -m 0755 -o "${opencloud_user}:${opencloud_group}" "${opencloud_logfile%/*}" |
| 39 | |
| 40 | if [ ! -f "${opencloud_config_dir}/opencloud.yaml" ]; then |
| 41 | einfo "No configuration found - initialising OpenCloud in ${opencloud_config_dir}" |
| 42 | su -s /bin/sh "${opencloud_user}" -c " |
| 43 | export OC_CONFIG_DIR='${opencloud_config_dir}' |
| 44 | export OC_BASE_DATA_PATH='${opencloud_data_dir}' |
| 45 | ${opencloud_admin_password:+export IDM_ADMIN_PASSWORD='${opencloud_admin_password}'} |
| 46 | exec '${command}' init --insecure '${opencloud_insecure}' |
| 47 | " || return 1 |
| 48 | if [ -z "${opencloud_admin_password}" ]; then |
| 49 | ewarn "A random admin password was generated." |
| 50 | ewarn "Find it in ${opencloud_config_dir}/opencloud.yaml (idm.service_user_passwords.admin_password)." |
| 51 | fi |
| 52 | fi |
| 53 | } |