2

I have a virtual server running Ubuntu 14.04 LTS x64 and I want to create a persistent process that restarts with the system and when it crashes.

To do that, I've added the following lines to the "inittab" in the etc-directory:

test:5:respawn:echo "HELLO TEST" > /test.log
sometestname:234:/var/path/to/process/myprocess

After running "init q" or "telinit q", nothing happens. The test.log file isn't created, the process isn't started (It's not listed when using pstree) and there's nothing in the syslog either. Restarting the server also doesn't help.

I've also tried to use systemd to create a new service, by creating a new "myprocess.service" in "/etc/systemd/system/" with these commands:

[Unit]
Description=Process Name

[Service]
ExecStart=/var/path/to/process/myprocess
Restart=restart-always

[Install]
WantedBy=multi-user.target

Again, after a server restart the process isn't there.

Are there any other ways to create a persistent process in Ubuntu?

Also, the process acts as a server, but can also accept user inputs. Since it'll run as a background process most of the time, is it possible to "attach" it to the main console at whim to run some commands, and detach it later on? I'm using putty for remote access to the server.

  • Have you tried using the echo command in /etc/rc.local? – YoMismo Aug 11 '15 at 15:22
0

You can use crontab. Crontab can start a process every minute, the process should check if it is already running and exit if it is. http://linux.die.net/man/1/crontab

0

inittab will know that the process is exiting too quickly and stop. Try a small shell script that waits 60 seconds before exiting. Your echo command will not work properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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