summaryrefslogtreecommitdiff
path: root/devel/gogs/files/gogs-service.in
blob: d09100f0d0eee59f414f7f0ac93c6dbdda094131 (plain) (blame)
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
#!/bin/sh

# Copyright (C) 2015 by Yuri Victorovich. All rights reserved.

# PROVIDE: %%PORTNAME%%
# REQUIRE: LOGIN
# KEYWORD: shutdown

#
# Add the following line to /etc/rc.conf to enable %%PORTNAME%%:
#
#%%PORTNAME%%_enable="YES"

. /etc/rc.subr

name="%%PORTNAME%%"
rcvar=%%PORTNAME%%_enable
start_cmd="%%PORTNAME%%_start"
stop_cmd="%%PORTNAME%%_stop"

load_rc_config ${name}

: ${%%PORTNAME%%_enable="NO"}
: ${%%PORTNAME%%_config="%%ETCDIR%%/conf/app.ini"}

logfile=/var/log/%%PORTNAME%%.log
pidfile=/var/run/%%PORTNAME%%.pid
command="/usr/bin/true"
procname="/usr/sbin/daemon"

is_process_running() {
  [ -f $pidfile ] && procstat $(cat $pidfile) >/dev/null 2>&1
}

%%PORTNAME%%_start() {
  if is_process_running; then
    echo "%%PORTNAME%% is already running (pid=$(cat $pidfile))"
    return 1
  fi
  export USER=%%GOGS_USER%%
  export HOME=$(echo ~%%GOGS_USER%%)
  touch $logfile
  chmod 640 $logfile
  cd %%PREFIX%%/libexec/%%PORTNAME%%
  /usr/sbin/daemon -P $pidfile -u %%GOGS_USER%% %%PREFIX%%/libexec/%%PORTNAME%%/%%PORTNAME%% web --config ${%%PORTNAME%%_config} >>$logfile 2>&1
  if is_process_running; then
    echo "started %%PORTNAME%% (pid=$(cat $pidfile))"
  else
    echo "failed to start %%PORTNAME%%"
  fi
}

%%PORTNAME%%_stop() {
  if is_process_running; then
    local pid=$(cat $pidfile)
    echo "stopping %%PORTNAME%% (pid=$pid)"
    kill -- -$pid
  else
    echo "%%PORTNAME%% isn't running"
  fi
}

run_rc_command "$1"