~hadware/magicicada-server/trusty-support

« back to all changes in this revision

Viewing changes to dev-scripts/set_rlimits.sh

  • Committer: Facundo Batista
  • Date: 2015-08-05 13:10:02 UTC
  • Revision ID: facundo@taniquetil.com.ar-20150805131002-he7b7k704d8o7js6
First released version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
# Copyright 2008-2015 Canonical
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify
 
6
# it under the terms of the GNU Affero General Public License as
 
7
# published by the Free Software Foundation, either version 3 of the
 
8
# License, or (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU Affero General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU Affero General Public License
 
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
17
#
 
18
# For further info, check  http://launchpad.net/filesync-server
 
19
 
 
20
# Argument = -d data_seg_size, -m max_memory_size, -v virtual_memory, -n open_files
 
21
 
 
22
usage()
 
23
{
 
24
cat << EOF
 
25
 
 
26
usage: $0 [options] <command>
 
27
 
 
28
This script will change the ulimit and execute the given command.
 
29
 
 
30
OPTIONS:
 
31
   -h      Show this message
 
32
   -d      Data seg size
 
33
   -m      max memory size
 
34
   -v      virtual memory
 
35
   -n      open files
 
36
EOF
 
37
}
 
38
 
 
39
DATA_SEG_SIZE=
 
40
MAX_MEM_SIZE=
 
41
VIRT_MEM_SIZE=
 
42
OPEN_FD=
 
43
COMMAND=
 
44
 
 
45
 
 
46
while getopts “hd:m:v:n:” OPTION
 
47
do
 
48
     case $OPTION in
 
49
         h)
 
50
             usage
 
51
             exit 1
 
52
             ;;
 
53
         d)
 
54
             DATA_SEG_SIZE="-d $OPTARG"
 
55
             ;;
 
56
         m)
 
57
             MAX_MEM_SIZE="-m $OPTARG"
 
58
             ;;
 
59
         v)
 
60
             VIRT_MEM_SIZE="-v $OPTARG"
 
61
             ;;
 
62
         n)
 
63
             OPEN_FD="-n $OPTARG"
 
64
             ;;
 
65
     esac
 
66
done
 
67
 
 
68
shift "$((OPTIND-1))" # shift all the already parsed args
 
69
COMMAND=$@
 
70
 
 
71
if [[ -z $COMMAND ]]
 
72
then
 
73
    echo "no command"
 
74
     usage
 
75
     exit 1
 
76
fi
 
77
 
 
78
ulimit $OPEN_FD $VIRT_MEM_SIZE $MAX_MEM_SIZE $DATA_SEG_SIZE;
 
79
exec $COMMAND