Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a VM running under Fedora OS. That VM has four users lets say(A, B, C, D). That VM has one process running under each user. So when that VM is rebooted, what should I do so that those process auto starts under respective user.

Provided that

a is the custom command to start a process under A user

b is the custom command to start a process under B user

c is the custom command to start a process under C user

d is the custom command to start a process under D user

a,b,c,d are the commands that are not available to root user. They are only available to respective users.

Thanks

share|improve this question
add comment

2 Answers 2

Create a separate Systemd init script for the processes. For process A create the file /etc/systemd/system/A.service and add something like this to it:

[Unit]
Description=Process A
After=network.target

[Service]
User=userA
Type=forking
ExecStart=/some/command/to/run --arg1 --arg2
Restart=on-failure
StartLimitInterval=5min
StartLimitBurst=4

[Install]
WantedBy=multi-user.target

Customize this as you like (Restart, StartLimitInterval, StartLimitBurst, etc...)

Then enable it with

systemctl enable A.service

and start

systemctl start A.service
share|improve this answer
    
I must spin up a fedora vm and start learning systemd, it's heading my way in a future EL release. –  Iain Jul 31 '13 at 7:47
    
Systemd is a great thing, I use it everywhere since Arch switched to it. –  Stone Jul 31 '13 at 7:50
    
@stone: Do I need to make separate service file for four users? –  Gagan Jul 31 '13 at 7:54
    
Yes, this is the cleanest way to do this. –  Stone Jul 31 '13 at 8:06
    
@stone: Fedora 18 says systemctl: command not found. Have I forgot something to install so that systemctl command can be found. –  Gagan Jul 31 '13 at 8:11
show 1 more comment

Can you use the /etc/crontab and the @reboot time. The format of the /etc/crontab takes a username after the time specification and the process is run as that user.

@reboot A /path/to/a
@reboot B /path/tob

and so on.

share|improve this answer
    
All I want is that the process must be started whenever the server boots. Will it be possible with your answer? –  Gagan Jul 31 '13 at 7:45
    
@Gagan: Why not test it and see ? –  Iain Jul 31 '13 at 7:45
    
@lain: What should I replace reboot with? Is reboot some kind of special variable that crontab recognize? –  Gagan Jul 31 '13 at 7:53
    
@lain: I have added reboot <username> <command> to crontab file but after reboot it didn't start the process. reboot has at sign infront of it. –  Gagan Jul 31 '13 at 8:07
    
Its a special variable, you don't need to replace it. –  Stone Jul 31 '13 at 8:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.