The server is running Debian 7 Wheezy without systemd.

I have a user in Debian with Perlbrew installed into their home directory. The user is running a Mojolicious app. In order for the app to work, the Perlbrew bashrc file must be loaded. Currently, the user logs in and runs their app with hypnotoad app, which launches the daemon. I am trying to keep the app, and everything related to it isolated to the user's home directory, and I'd really rather not mess with system Perl. However, I'd like for their app to run as a service, started on boot and so on, but I'm not sure how to source in the Perlbrew bashrc when running the service as the user.

So, in short, my question is summed up in the title, but basically I am wondering how to source in a bashrc file for a service.


Have you tried with su <user> -l -c <cmd> ?
The rc scripts are executed as the root user (id=0), so, as root, you can spawn a process with the privileges of any user defined in the system.

For example :

su root -l -c "ls /tmp"

Where :

  • -c : execute command.
  • -l : login as the specified user.
| improve this answer | |

Of course, you should not import a user's .bashrc into a script that runs as root at system startup. Two suggestions:

Write a script to launch the service (let's say mystart.sh) . That script can source the .bashrc, then start the app:

. .bashrc
hypnotoad app

To run that script at startup, I suggest use the user's crontab. Have the user put

@reboot mystart.sh

in their crontab. That way it runs as the user, and it is up to them if they want to disable or replace it in future.

| improve this answer | |
  • I see no reason not so source in Perlbrew's bashrc file and run the script as root. Anyhow, figured it out. I just used Daemon::Control's init_config method to load Perlbrew's bashrc, then created an LSB compatible init script. If anyone reads this, I'd suggest this as a much better suggestion than this answer, using cronttab and imagining it's associated with an actual person. – Franz Kafka Feb 22 '15 at 2:52
  • Regardless of whether an actual person owns the account, sourcing another account's bashrc (or any script owned by another user) from a script running as root is unwise. If the account is compromised by an attacker, they can easily escalate their access to root privileges by adding commands to this bashrc. – Colin Phipps Feb 22 '15 at 10:34

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.