L
L
lxfr2019-09-26 11:06:09
linux
lxfr, 2019-09-26 11:06:09

How is the correct autoload in Ubuntu done on behalf of the user?

Greetings!
Tell me, let's say there is a fresh Ubuntu system and a certain user with the rights of a regular user.
How to autoload some bash scripts on his behalf at system startup?
So that if, for example, the server reboots, it all starts up, even if the user himself has not logged into the system yet.
There, in the scripts, some software is launched in Java in daemon mode and listens to some ports, the software itself is located in the [~] user-a directory, but this is not important.
Please do not offer Docker as a solution to this issue.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ronald McDonald, 2019-09-26
@lxfr

How to autoload some bash scripts on his behalf at system startup?

This is how you can run the script on behalf of another user:
Just add a line to the /etc/sudoers file, otherwise it will ask for a password:
username - the desired user.
To run a script on boot, add it to cron:
sudo crontab -eu root
@reboot /bin/sudo -u username /path/to/your/script.sh

P
pfg21, 2019-09-26
@pfg21

Ubuntu has systemd for system process management.
you write a unit for the control system to run your program on behalf of the desired user. for example
/etc/systemd/system/3proxy.proxy.service

[Unit]
Description=Simple proxy (3proxy) service
After=network.target

[Service]
User=nobody
Group=nogroup
ExecStart=/usr/bin/proxy -l/var/log/1pfg/3proxy.log -4 -p10021

[Install]
WantedBy=multi-user.target

then re-read the units
sudo systemctl daemon-reload
include the unit in autoload
sudo systemctl enable 3proxy.proxy.service
and run if needed right now
sudo systemctl start 3proxy.proxy.service

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question