But if you still want to do it, you have to source /opt/ros/melodic/setup.bash in your root shell (like for any other user). Then rosbag and everything should work fine. Although I would suggest trying creating a specific user for the task. (see https://askubuntu.com/questions/676007/how-do-i-make-my-systemd-service-run-via-specific-user-and-start-on-boot)