Hello Everyone,

I want to create a systemd service for which the resources allocated should be same as when the process is launched from command line.

Here is my systemd service file
Code:
[Unit]
Description=Image Server
After=Volumes-localStorage2.mount autofs.service

[Service]
Type=simple
ExecStartPre=/bin/sleep 60
ExecStart=/root/ccs/ias/jetty/startjetty.sh
ExecStop=/root/ccs/ias/jetty/endjetty.sh
Restart=always

[Install]
WantedBy=default.target
Below is the comparison between the cgroup and status file under /proc/{PROCESS_ID}/
I see the difference in FDSize and VM sizes.

File Process started with command line Process started using systemd service
cgroup 11: perf_event:/
10:devices:/user.slice
9:hugetlb:/
8:freezer:/
7:cpu,cpuacct:/
6:memory:/
5:blkio:/
4: pids:/user.slice/user-0.slice/session-111.scope
3:cpuset:/
2:net_cls,net_prio:/
1:name=systemd:/user.slice/user-0.slice/session-111.scope
11: perf_event:/
10:devices:/system.slice/ccs-is.service
9:hugetlb:/
8:freezer:/
7:cpu,cpuacct:/
6:memory:/
5:blkio:/
4: pids:/system.slice/ccs-is.service
3:cpuset:/
2:net_cls,net_prio:/
1:name=systemd:/system.slice/ccs-is.service
status Name: java

FDSize: 2048
Groups: 0

VmPeak: 48315864 kB
VmSize: 48080772 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 6442880 kB
VmRSS: 3996968 kB
RssAnon: 3977792 kB
RssFile: 19144 kB
RssShmem: 32 kB
VmData: 48014352 kB
VmStk: 132 kB
VmExe: 4 kB
VmLib: 17784 kB
VmPTE: 13028 kB
VmPMD: 108 kB
VmSwap: 0 kB
HugetlbPages: 0 kB
Threads: 1366
Name: java

FDSize: 512
Groups:

VmPeak: 47170508 kB
VmSize: 47119108 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 1570056 kB
VmRSS: 1560688 kB
RssAnon: 1542096 kB
RssFile: 18560 kB
RssShmem: 32 kB
VmData: 47057508 kB
VmStk: 132 kB
VmExe: 4 kB
VmLib: 17108 kB
VmPTE: 5584 kB
VmPMD: 84 kB
VmSwap: 0 kB
HugetlbPages: 0 kB
Threads: 378

Then I modified the Systemd unit file to change cgroup from system.slice to user.slice (since the process started from command line has cgroup with user.slice)
Code:
[Unit]
Description=Image Server
After=Volumes-localStorage2.mount autofs.service

[Service]
Type=simple
ExecStartPre=/bin/sleep 60
ExecStart=/root/ccs/ias/jetty/startjetty.sh
ExecStop=/root/ccs/ias/jetty/endjetty.sh
Restart=always
Slice=user.slice

[Install]
WantedBy=default.target
File Process started with command line Process started using systemd service
cgroup 11: perf_event:/
10:devices:/user.slice
9:hugetlb:/
8:freezer:/
7:cpu,cpuacct:/
6:memory:/
5:blkio:/
4: pids:/user.slice/user-0.slice/session-111.scope
3:cpuset:/
2:net_cls,net_prio:/
1:name=systemd:/user.slice/user-0.slice/session-111.scope
11: perf_event:/
10:devices:/user.slice
9:hugetlb:/
8:freezer:/
7:cpu,cpuacct:/
6:memory:/
5:blkio:/
4: pids:/user.slice/ccs-is.service
3:cpuset:/
2:net_cls,net_prio:/
1:name=systemd:/user.slice/ccs-is.service
status Name: java

FDSize: 2048
Groups: 0

VmPeak: 48315864 kB
VmSize: 48080772 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 6442880 kB
VmRSS: 3996968 kB
RssAnon: 3977792 kB
RssFile: 19144 kB
RssShmem: 32 kB
VmData: 48014352 kB
VmStk: 132 kB
VmExe: 4 kB
VmLib: 17784 kB
VmPTE: 13028 kB
VmPMD: 108 kB
VmSwap: 0 kB
HugetlbPages: 0 kB
Threads: 1366
Name: java

FDSize: 1024


VmPeak: 47180788 kB
VmSize: 47107864 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 3609828 kB
VmRSS: 3609424 kB
RssAnon: 3590372 kB
RssFile: 19020 kB
RssShmem: 32 kB
VmData: 47041444 kB
VmStk: 132 kB
VmExe: 4 kB
VmLib: 17784 kB
VmPTE: 9776 kB
VmPMD: 96 kB
VmSwap: 0 kB
HugetlbPages: 0 kB
Threads: 422

I also tried by adding the following in systemd service file
Code:
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Still it didn't solve the problem.

Please help!!, Thanks in advance.