File: cyphesis.init

package info (click to toggle)
cyphesis-cpp 0.5.21-1.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,880 kB
  • ctags: 4,113
  • sloc: cpp: 35,916; python: 5,277; xml: 4,930; sh: 4,165; makefile: 1,456; ansic: 572
file content (144 lines) | stat: -rw-r--r-- 3,695 bytes parent folder | download | duplicates (3)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/sh
#
# cyphesis          This shell script takes care of starting and stopping
#                   the cyphesis service.
#
# chkconfig: - 90 10
# description: Cyphesis is a server for WorldForge online games.
# processname: cyphesis

if [ -f /etc/rc.d/init.d/functions ] ; then
        . /etc/rc.d/init.d/functions
fi

# Source cyphesis service configuration
if [ -f /etc/sysconfig/cyphesis ] ; then
        . /etc/sysconfig/cyphesis
else
        CYPHESISUSER=cyphesis
fi

POSTGRESUSER=postgres

start() {
        # Start the daemon.

        # Make sure postgres superuser exists
        if ! su $POSTGRESUSER -c true >/dev/null 2>&1; then
            echo
            echo $"Could not check for running PostgreSQL database."
            return 1
        fi

        # Make sure postgres is running
        if ! su $POSTGRESUSER -c "psql -c \"\" template1" >/dev/null 2>&1; then
            echo $"PostgreSQL server is not running."
            return 1
        fi

        # Make sure the user we are going to run as exists
        if ! su $CYPHESISUSER -c true >/dev/null 2>&1; then
            echo $"Cannot find user $CYPHESISUSER to run cyphesis service."
            return 1
        fi

        # Make sure the user has a postgres account
        if ! su $CYPHESISUSER -c "psql -c \"\" template1" >/dev/null 2>&1; then
            echo -n $"Creating PostgreSQL account: "
            su $POSTGRESUSER -c "createuser -A -d -q -R $CYPHESISUSER" >/dev/null 2>&1
            RETVAL=$?
            if [ $RETVAL -eq 0 ]; then
                echo_success
            else
                echo_failure
                echo
                return 1
            fi
            echo
        fi

        # Make sure the database exists
        if ! su $CYPHESISUSER -c "psql -c \"\" cyphesis" >/dev/null 2>&1; then
            # Create the database
            echo -n $"Creating PostgreSQL database: "
            su $CYPHESISUSER -c "createdb -q cyphesis" >/dev/null 2>&1
            RETVAL=$?
            if [ $RETVAL -eq 0 ]; then
                echo_success
            else
                echo_failure
                echo
                return 1
            fi
            echo
            # Populate it with rules
            echo -n $"Loading database with rules: "
            su $CYPHESISUSER -c "cyloadrules" >/dev/null 2>&1
            RETVAL=$?
            if [ $RETVAL -eq 0 ]; then
                echo_success
            else
                echo_failure
                echo
                return 1
            fi
            echo
        fi

        echo -n $"Starting cyphesis: "

        # Run the server, in self daemonising mode
        su $CYPHESISUSER -c "/usr/bin/cyphesis --cyphesis:daemon=true" >/dev/null 2>&1
        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
            echo_success
            touch /var/lock/subsys/cyphesis
        else
            echo_failure
            echo
        fi
        echo
        return $RETVAL
}

stop() {
        # Stop server
        echo -n $"Shutting down cyphesis: "
        killproc cyphesis
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/cyphesis
        return $RETVAL
}

case "$1" in
  start)
        start
        RETVAL=$?
        ;;
  stop)
        stop
        RETVAL=$?
        ;;
  restart|reload)
        stop
        start
        RETVAL=$?
        ;;
  condrestart)
        if [ -f /var/lock/subsys/cyphesis ]; then
            stop
            start
            RETVAL=$?
        fi
        ;;
  status)
        status cyphesis
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 (start|stop|restart|condrestart|status)"
        exit 1
esac

exit $RETVAL